1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/settings/SettingsQueue.jsm Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,30 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this file, 1.6 + * You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +this.EXPORTED_SYMBOLS = ["Queue"]; 1.9 + 1.10 +this.Queue = function Queue() { 1.11 + this._queue = []; 1.12 + this._index = 0; 1.13 +} 1.14 + 1.15 +Queue.prototype = { 1.16 + getLength: function() { return (this._queue.length - this._index); }, 1.17 + 1.18 + isEmpty: function() { return (this._queue.length == 0); }, 1.19 + 1.20 + enqueue: function(item) { this._queue.push(item); }, 1.21 + 1.22 + dequeue: function() { 1.23 + if(this.isEmpty()) 1.24 + return undefined; 1.25 + 1.26 + var item = this._queue[this._index]; 1.27 + if (++this._index * 2 >= this._queue.length){ 1.28 + this._queue = this._queue.slice(this._index); 1.29 + this._index = 0; 1.30 + } 1.31 + return item; 1.32 + } 1.33 +}