nodejs实现队列

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/u010129985/article/details/78516555
"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();
展开阅读全文

没有更多推荐了,返回首页