/*
THIS INFRAGISTICS ULTIMATE SOFTWARE LICENSE  AGREEMENT ("AGREEMENT") LOCATED HERE:
https://www.infragistics.com/legal/license/igultimate-la
https://www.infragistics.com/legal/license/igultimate-eula
GOVERNS THE LICENSING, INSTALLATION AND USE OF INFRAGISTICS SOFTWARE. BY DOWNLOADING AND/OR INSTALLING AND USING INFRAGISTICS SOFTWARE:  you are indicating that you have read and understand this Agreement, and agree to be legally bound by it on behalf of the yourself and your company.
*/
import * as tslib_1 from "tslib";
import { IHashPool$2_$type } from "./IHashPool$2";
import { List$1 } from "./List$1";
import { Dictionary$2 } from "./Dictionary$2";
import { Base, fromEnum, markType } from "./type";
var HashPool$2 = /** @class */ (function (_super) {
    tslib_1.__extends(HashPool$2, _super);
    function HashPool$2($tKey, $tValue) {
        var _this = _super.call(this) || this;
        _this.$tKey = null;
        _this.$tValue = null;
        _this.d = null;
        _this.b = null;
        _this._create = null;
        _this._disactivate = null;
        _this._activate = null;
        _this._destroy = null;
        _this.$tKey = $tKey;
        _this.$tValue = $tValue;
        _this.$type = _this.$type.specialize(_this.$tKey, _this.$tValue);
        _this.d = new List$1(_this.$tValue, 0);
        _this.b = new Dictionary$2(_this.$tKey, _this.$tValue, 0);
        return _this;
    }
    Object.defineProperty(HashPool$2.prototype, "create", {
        get: function () {
            return this._create;
        },
        set: function (a) {
            this._create = a;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(HashPool$2.prototype, "disactivate", {
        get: function () {
            return this._disactivate;
        },
        set: function (a) {
            this._disactivate = a;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(HashPool$2.prototype, "activate", {
        get: function () {
            return this._activate;
        },
        set: function (a) {
            this._activate = a;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(HashPool$2.prototype, "destroy", {
        get: function () {
            return this._destroy;
        },
        set: function (a) {
            this._destroy = a;
        },
        enumerable: true,
        configurable: true
    });
    HashPool$2.prototype.item = function (a) {
        var _this = this;
        var b;
        if (!((function () { var c = _this.b.tryGetValue(a, b); b = c.p1; return c.ret; })())) {
            if (this.d.count > 0) {
                b = this.d._inner[this.d.count - 1];
                this.d.removeAt(this.d.count - 1);
            }
            else {
                b = this.create();
            }
            if (this.activate != null) {
                this.activate(b);
            }
            this.b.item(a, b);
        }
        return b;
    };
    Object.defineProperty(HashPool$2.prototype, "c", {
        get: function () {
            return this.b.keys;
        },
        enumerable: true,
        configurable: true
    });
    HashPool$2.prototype.a = function (a) {
        return this.b.containsKey(a);
    };
    HashPool$2.prototype.g = function (a) {
        var _this = this;
        var b;
        if (((function () { var c = _this.b.tryGetValue(a, b); b = c.p1; return c.ret; })())) {
            this.b.removeItem(a);
            if (this.disactivate != null) {
                this.disactivate(b);
            }
            this.d.add(b);
            var c = this.b.count;
            var d = 2;
            while (c != 0) {
                c >>= 1;
                d <<= 1;
            }
            if (d < this.d.count) {
                for (var e = d; e < this.d.count; ++e) {
                    this.destroy(this.d._inner[e]);
                }
                this.d.v(d, this.d.count - d);
            }
        }
    };
    HashPool$2.prototype.clear = function () {
        var a = new List$1(this.$tKey, 0);
        try {
            for (var _a = tslib_1.__values(fromEnum(this.b.keys)), _b = _a.next(); !_b.done; _b = _a.next()) {
                var b = _b.value;
                a.add(b);
            }
        }
        catch (e_1_1) { e_1 = { error: e_1_1 }; }
        finally {
            try {
                if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
            }
            finally { if (e_1) throw e_1.error; }
        }
        try {
            for (var _d = tslib_1.__values(fromEnum(a)), _e = _d.next(); !_e.done; _e = _d.next()) {
                var c = _e.value;
                this.g(c);
            }
        }
        catch (e_2_1) { e_2 = { error: e_2_1 }; }
        finally {
            try {
                if (_e && !_e.done && (_f = _d.return)) _f.call(_d);
            }
            finally { if (e_2) throw e_2.error; }
        }
        var e_1, _c, e_2, _f;
    };
    Object.defineProperty(HashPool$2.prototype, "e", {
        get: function () {
            return this.b.count;
        },
        enumerable: true,
        configurable: true
    });
    HashPool$2.prototype.f = function (a) {
        for (var b = 0; b < this.d.count; b++) {
            a(this.d._inner[b]);
        }
        try {
            for (var _a = tslib_1.__values(fromEnum(this.b.values)), _b = _a.next(); !_b.done; _b = _a.next()) {
                var c = _b.value;
                a(c);
            }
        }
        catch (e_3_1) { e_3 = { error: e_3_1 }; }
        finally {
            try {
                if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
            }
            finally { if (e_3) throw e_3.error; }
        }
        var e_3, _c;
    };
    HashPool$2.$t = markType(HashPool$2, 'HashPool$2', Base.$, [IHashPool$2_$type.specialize(0, 1)]);
    return HashPool$2;
}(Base));
export { HashPool$2 };
//# sourceMappingURL=HashPool$2.js.map