Spaces:
Sleeping
Sleeping
File size: 1,330 Bytes
e4bf523 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | 'use strict'
/**
* Copyright (c) 2017~2020, OBCon Inc.
* All rights reserved.
*/
/**
* @file
* @copyright 2017~2020, OBCon Inc.
* @author gye hyun james kim [pnuskgh@gmail.com]
*/
class Queue { //--- FIFO (First In First Out)
constructor(data) {
this._maxSize = 0; //--- 0. 크기 제한 없음
this._data = data || [];
}
get maxSize() {
return this._maxSize;
}
set maxSize(newValue) {
this._maxSize = newValue;
}
getBuffer() { //--- Stack 복사
return this._data.slice();
}
isEmpty() {
return this._data.length == 0;
}
peek() { //--- 첫번째 항목 조회
return (this.isEmpty()) ? null : this._data[0];
}
enqueue(item) { //--- 항목 추가
this._data.push(item);
if ((0 < this._maxSize) && (this._maxSize < this._data.length)) {
this._data.slice();
}
}
dequeue() { //--- 항목 제거
return this._data.shift();
}
}
module.exports = Queue;
|