Code coverage report for usr/local/google/home/trevj/src/uproxy-lib/build/dev/uproxy-lib/queue/queue.js

Statements: 96.43% (27 / 28)      Branches: 50% (2 / 4)      Functions: 100% (6 / 6)      Lines: 96.43% (27 / 28)      Ignored: none     

All files » usr/local/google/home/trevj/src/uproxy-lib/build/dev/uproxy-lib/queue/ » 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        2 1 2 2   2   2 1 12 12 12 12   12 2 2         2   2 2     12 2   2 2 2 2 2   2     2   2  
// This file defines a basic queue data structure, providing
// the standard Array push(), shift(), and length attributes,
// but with O(1) operation.
// Private helper class.
var Cell = (function () {
    function Cell(item) {
        this.item = item;
        this.next = null;
    }
    return Cell;
})();
var Queue = (function () {
    function Queue() {
        var _this = this;
        this.back_ = null;
        this.front_ = null;
        this.length = 0;
        // Add an item to the back of the queue.
        this.push = function (item) {
            var cell = new Cell(item);
            Iif (_this.length > 0) {
                _this.back_.next = cell;
            }
            else {
                // The queue was empty, so set both pointers.
                _this.front_ = cell;
            }
            _this.back_ = cell;
            _this.length++;
        };
        // Remove and return the front element.
        this.shift = function () {
            var dequeued = _this.front_;
            // If this.front_ is this.back_, then getNext() returns null.
            _this.front_ = dequeued.next;
            dequeued.next = null; // Just to help the garbage collector.
            _this.length--;
            Eif (_this.length === 0) {
                _this.back_ = null;
            }
            return dequeued.item;
        };
    }
    return Queue;
})();
exports.Queue = Queue; // class Queue