Code coverage report for debug\queue.js

Statements: 100% (65 / 65)      Branches: 100% (4 / 4)      Functions: 100% (11 / 11)      Lines: 100% (65 / 65)      Ignored: none     

All files » debug\ » queue.js
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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100  8 8 41 190 190       8 16 16 16     8 13941     8 16248 16248 16248 16248 16248     8 9 9 9 9   9 9 9     8 3 3 3     8 13941   13941   13941 13941 41 41 41 41   13900 13900 13900 13900 13900 13900 13900     8 57957   57957     57957 57957 57957 57957     8 134619     8 30157 41       8 41 41 41 41 41 41     8      
(function () { "use strict";
var ASSERT = require("./assert.js");
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._unshiftOne = function(value) {
    var capacity = this._capacity;
    this._checkCapacity(this.length() + 1);
    var front = this._front;
    var i = (((( front - 1 ) &
                    ( capacity - 1) ) ^ capacity ) - capacity );
    this[i] = value;
    this._front = i;
    this._length = this.length() + 1;
};
 
Queue.prototype.unshift = function(fn, receiver, arg) {
    this._unshiftOne(arg);
    this._unshiftOne(receiver);
    this._unshiftOne(fn);
};
 
Queue.prototype.push = function (fn, receiver, arg) {
    ASSERT((arguments.length === 3),
    "arguments.length === 3");
    ASSERT(((typeof fn) === "function"),
    "typeof fn === \u0022function\u0022");
    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 () {
    ASSERT((this.length() > 0),
    "this.length() > 0");
    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;
 
}());