nodejs实现队列
"use strict"
const MAXLEN=2000;
class Queue {
constructor() {
this.filelist=[];
this.top=0;
}
Push(path){
this.filelist.push(path);
}
Pop() {
if (this.top < this.filelist.length) {
if (this.top > 32) {
this.filelist=this.filelist.splice(this.top,this.filelist.length-this.top);
this.top=0;
}
this.top+=1;
return this.filelist[this.top-1]
} else {
return null;
}
this.Shuff();
}
Length(){
return (this.filelist.length-this.top);
}
Shuff(){
//队列push频率高,pop频率低
if ((this.filelist.length-this.top) > MAXLEN) {
this.filelist=this.filelist.splice(this.top,MAXLEN-700);
this.top=0;
}
}
}
module.exports=new Queue();
声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。
- 上一篇: 利用数组实现队列操作
- 下一篇: NodeJs forEach循环