michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: this.EXPORTED_SYMBOLS = ["Queue"]; michael@0: michael@0: this.Queue = function Queue() { michael@0: this._queue = []; michael@0: this._index = 0; michael@0: } michael@0: michael@0: Queue.prototype = { michael@0: getLength: function() { return (this._queue.length - this._index); }, michael@0: michael@0: isEmpty: function() { return (this._queue.length == 0); }, michael@0: michael@0: enqueue: function(item) { this._queue.push(item); }, michael@0: michael@0: dequeue: function() { michael@0: if(this.isEmpty()) michael@0: return undefined; michael@0: michael@0: var item = this._queue[this._index]; michael@0: if (++this._index * 2 >= this._queue.length){ michael@0: this._queue = this._queue.slice(this._index); michael@0: this._index = 0; michael@0: } michael@0: return item; michael@0: } michael@0: }