入门客AI创业平台(我带你入门,你带我飞行)
博文笔记

nodejs实现队列

创建时间:2017-11-13 投稿人: 浏览次数:179
"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();
声明:该文观点仅代表作者本人,入门客AI创业平台信息发布平台仅提供信息存储空间服务,如有疑问请联系rumenke@qq.com。
  • 上一篇:没有了
  • 下一篇:没有了
未上传头像