/*
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 { List$1 } from "./List$1";
import { Dictionary$2 } from "./Dictionary$2";
import { Base, Number_$type, Boolean_$type, markType } from "./type";
export class FastIterationDictionary$2 extends Base {
    constructor($tKey, $tValue, a, ..._rest) {
        super();
        this.$tKey = null;
        this.$tValue = null;
        this.h = null;
        this.l = null;
        this.n = null;
        this.m = null;
        this.i = null;
        this.c = false;
        this.$tKey = $tKey;
        this.$tValue = $tValue;
        this.$type = this.$type.specialize(this.$tKey, this.$tValue);
        a = (a == void 0) ? 0 : a;
        switch (a) {
            case 0:
                {
                    let c = [null];
                    {
                        let e = c[0];
                        this.h = new Dictionary$2(this.$tKey, this.$tValue, 2, e);
                        this.l = new List$1(this.$tKey, 0);
                        this.n = new List$1(this.$tValue, 0);
                        this.i = new Dictionary$2(this.$tKey, Number_$type, 0);
                        this.m = new List$1(Boolean_$type, 0);
                    }
                }
                break;
            case 1:
                {
                    let c = _rest[0];
                    this.h = new Dictionary$2(this.$tKey, this.$tValue, 2, c);
                    this.l = new List$1(this.$tKey, 0);
                    this.n = new List$1(this.$tValue, 0);
                    this.i = new Dictionary$2(this.$tKey, Number_$type, 0);
                    this.m = new List$1(Boolean_$type, 0);
                }
                break;
        }
    }
    p(a, b) {
        this.h.addItem(a, b);
        this.l.add(a);
        this.n.add(b);
        this.i.addItem(a, this.l.count - 1);
        this.m.add(false);
    }
    r() {
        this.h.clear();
        this.l.clear();
        this.n.clear();
        this.i.clear();
        this.m.clear();
    }
    d(a) {
        return this.h.containsKey(a);
    }
    get o() {
        return this.h.count;
    }
    get j() {
        return this.h.keys;
    }
    get f() {
        return this.c;
    }
    set f(a) {
        this.c = a;
        if (this.m.count > (this.i.count * 3)) {
            this.q();
        }
    }
    e(a) {
        let b = this.h.removeItem(a);
        if (b) {
            let c = this.i.item(a);
            this.m._inner[c] = true;
            this.i.removeItem(a);
            if (this.m.count > (this.i.count * 3)) {
                this.q();
            }
            return b;
        }
        return b;
    }
    q() {
        if (this.f) {
            return;
        }
        let a = this.m.count;
        let b = 0;
        let c = false;
        for (let d = 0; d < a; d++) {
            if (this.m._inner[d]) {
                this.l.removeAt(d);
                this.n.removeAt(d);
                this.m.removeAt(d);
                d--;
                a--;
                c = true;
            }
            else {
                if (c) {
                    this.i.removeItem(this.l._inner[d]);
                    this.i.addItem(this.l._inner[d], b);
                }
                b++;
            }
        }
    }
    g(a, b) {
        return {
            ret: ((() => { let c = this.h.tryGetValue(a, b); b = c.p1; return c.ret; })()),
            p1: b
        };
    }
    b(a) {
        return this.h.f(a);
    }
    get k() {
        return this.h.values;
    }
    item(a, b) {
        if (arguments.length === 2) {
            if (!this.d(a)) {
                this.p(a, b);
            }
            else {
                this.h.item(a, b);
                let c = this.i.item(a);
                this.n._inner[c] = b;
                this.m._inner[c] = false;
            }
            return b;
        }
        else {
            return this.h.item(a);
        }
    }
}
FastIterationDictionary$2.$t = markType(FastIterationDictionary$2, 'FastIterationDictionary$2');
//# sourceMappingURL=FastIterationDictionary$2.js.map