all files / lib/ OverflowHashCode.js

91.49% Statements 43/47
75% Branches 12/16
100% Functions 9/9
97.73% Lines 43/44
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                                              26×       98× 98× 120×   98× 120× 120× 14×   116× 16× 80×   100×       100×     98×    
"use strict";
var OverflowLong_1 = require("./OverflowLong");
var OverflowTyped_1 = require("./OverflowTyped");
var OverflowHashCode = (function () {
    function OverflowHashCode(_seed, _PRIME, _byteLength) {
        Iif (_seed === void 0) { _seed = 1; }
        Iif (_PRIME === void 0) { _PRIME = 31; }
        Iif (_byteLength === void 0) { _byteLength = 32; }
        this._seed = _seed;
        this._PRIME = _PRIME;
        this._byteLength = _byteLength;
        this.overflow = _byteLength === 32 ? new OverflowTyped_1.OverflowTyped(_seed) : new OverflowLong_1.OverflowLong(_seed);
    }
    Object.defineProperty(OverflowHashCode.prototype, "seed", {
        get: function () {
            return this._seed;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(OverflowHashCode.prototype, "prime", {
        get: function () {
            return this._PRIME;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(OverflowHashCode.prototype, "byteLength", {
        get: function () {
            return this._byteLength;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(OverflowHashCode.prototype, "value", {
        get: function () {
            return this.overflow.value;
        },
        enumerable: true,
        configurable: true
    });
    OverflowHashCode.prototype.valueOf = function () {
        return this.overflow.value;
    };
    OverflowHashCode.prototype.of = function () {
        var args = [];
        for (var _i = 0; _i < arguments.length; _i++) {
            args[_i] = arguments[_i];
        }
        return new OverflowHashCode(hash.apply(void 0, [this.overflow, this.prime].concat(args)).value, this.prime, this.byteLength);
    };
    return OverflowHashCode;
}());
exports.OverflowHashCode = OverflowHashCode;
function hash(overflow, prime) {
    var args = [];
    for (var _i = 2; _i < arguments.length; _i++) {
        args[_i - 2] = arguments[_i];
    }
    for (var j = 0; j < args.length; j++) {
        var a = args[j];
        if (Array.isArray(a)) {
            for (var i = 0; i < a.length; i++)
                overflow = hash(overflow, prime, a[i]);
        }
        else if (typeof a === "string") {
            for (var i = 0; i < a.length; i++)
                overflow = hash(overflow, prime, a.charCodeAt(i));
        }
        else Iif (typeof a === "object" || typeof a === "function") {
            overflow = hash(overflow, prime, String(a));
        }
        else {
            overflow = overflow.times(prime).plus(a);
        }
    }
    return overflow;
}
//# sourceMappingURL=OverflowHashCode.js.map