Sha256: 683aab2037414e069b2a5f48d39fb4ee5e1ab808c97b2b218ec12c2520b10c82

Contents?: true

Size: 1.83 KB

Versions: 47

Compression:

Stored size: 1.83 KB

Contents

"use strict";
function arrayMove(src, srcIndex, dst, dstIndex, len) {
    for (var j = 0; j < len; ++j) {
        dst[j + dstIndex] = src[j + srcIndex];
        src[j + srcIndex] = void 0;
    }
}

function Queue(capacity) {
    this._capacity = capacity;
    this._length = 0;
    this._front = 0;
}

Queue.prototype._willBeOverCapacity = function (size) {
    return this._capacity < size;
};

Queue.prototype._pushOne = function (arg) {
    var length = this.length();
    this._checkCapacity(length + 1);
    var i = (this._front + length) & (this._capacity - 1);
    this[i] = arg;
    this._length = length + 1;
};

Queue.prototype.push = function (fn, receiver, arg) {
    var length = this.length() + 3;
    if (this._willBeOverCapacity(length)) {
        this._pushOne(fn);
        this._pushOne(receiver);
        this._pushOne(arg);
        return;
    }
    var j = this._front + length - 3;
    this._checkCapacity(length);
    var wrapMask = this._capacity - 1;
    this[(j + 0) & wrapMask] = fn;
    this[(j + 1) & wrapMask] = receiver;
    this[(j + 2) & wrapMask] = arg;
    this._length = length;
};

Queue.prototype.shift = function () {
    var front = this._front,
        ret = this[front];

    this[front] = undefined;
    this._front = (front + 1) & (this._capacity - 1);
    this._length--;
    return ret;
};

Queue.prototype.length = function () {
    return this._length;
};

Queue.prototype._checkCapacity = function (size) {
    if (this._capacity < size) {
        this._resizeTo(this._capacity << 1);
    }
};

Queue.prototype._resizeTo = function (capacity) {
    var oldCapacity = this._capacity;
    this._capacity = capacity;
    var front = this._front;
    var length = this._length;
    var moveItemsCount = (front + length) & (oldCapacity - 1);
    arrayMove(this, 0, this, oldCapacity, moveItemsCount);
};

module.exports = Queue;

Version data entries

47 entries across 43 versions & 15 rubygems

Version Path
optimacms-0.1.61 spec/dummy/node_modules/bluebird/js/release/queue.js
disco_app-0.18.0 test/dummy/node_modules/bluebird/js/release/queue.js
disco_app-0.18.2 test/dummy/node_modules/bluebird/js/release/queue.js
disco_app-0.16.1 test/dummy/node_modules/bluebird/js/release/queue.js
disco_app-0.15.2 test/dummy/node_modules/bluebird/js/release/queue.js
disco_app-0.18.4 test/dummy/node_modules/bluebird/js/release/queue.js
disco_app-0.18.1 test/dummy/node_modules/bluebird/js/release/queue.js
disco_app-0.12.7.pre.puma.pre.3 test/dummy/node_modules/bluebird/js/release/queue.js
disco_app-0.14.0 test/dummy/node_modules/bluebird/js/release/queue.js
disco_app-0.13.6.pre.puma.pre.3 test/dummy/node_modules/bluebird/js/release/queue.js
tang-0.2.1 spec/tang_app/node_modules/bluebird/js/release/queue.js
groonga-client-model-6.0.0 test/apps/rails6.0.3.5/node_modules/bluebird/js/release/queue.js
groonga-client-model-6.0.0 test/apps/rails6.1.3/node_modules/bluebird/js/release/queue.js
ruby2js-4.0.4 lib/tasks/testrails/node_modules/bluebird/js/release/queue.js
ruby2js-4.0.3 lib/tasks/testrails/node_modules/bluebird/js/release/queue.js
tang-0.2.0 spec/tang_app/node_modules/bluebird/js/release/queue.js
tang-0.1.0 spec/tang_app/node_modules/bluebird/js/release/queue.js
tang-0.0.9 spec/tang_app/node_modules/bluebird/js/release/queue.js
enju_library-0.3.8 spec/dummy/node_modules/bluebird/js/release/queue.js
ilog-0.4.1 node_modules/consolidate/node_modules/bluebird/js/release/queue.js