/*
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 { Base, Type, markType } from "igniteui-angular-core";
import { LruCache_LruCacheNode$2 } from "./LruCache_LruCacheNode$2";
import { ArgumentOutOfRangeException } from "igniteui-angular-core";
import { Dictionary$2 } from "igniteui-angular-core";
import { LinkedList } from "./LinkedList";
import { EqualityComparer$1 } from "igniteui-angular-core";
/**
 * @hidden
 */
export class LruCache$2 extends Base {
    constructor($tKey, $tValue, a, b) {
        super();
        this.$tKey = null;
        this.$tValue = null;
        this.e = 0;
        this.d = null;
        this.a = null;
        this.$tKey = $tKey;
        this.$tValue = $tValue;
        this.$type = this.$type.specialize(this.$tKey, this.$tValue);
        if (b == null) {
            b = EqualityComparer$1.defaultEqualityComparerValue(this.$tKey);
        }
        this.d = new Dictionary$2(this.$tKey, LruCache_LruCacheNode$2.$.specialize(this.$tKey, this.$tValue), 2, b);
        this.a = new LinkedList();
        this.f = a;
    }
    get f() {
        return this.e;
    }
    set f(a) {
        if (a <= 0) {
            throw new ArgumentOutOfRangeException(0);
        }
        this.e = a;
        for (let b = this.d.count - a; b > 0; b--) {
            let c = this.a.d;
            this.d.removeItem(c.n);
            c.m();
        }
    }
    get g() {
        return this.d.count;
    }
    item(a) {
        let b;
        let c;
        if (((() => { let d = this.d.tryGetValue(a, c); c = d.p1; return d.ret; })())) {
            b = c.o;
            c.i();
        }
        else {
            b = Type.getDefaultValue(this.$tValue);
        }
        return b;
    }
    h(a, b) {
        let c;
        if (((() => { let d = this.d.tryGetValue(a, c); c = d.p1; return d.ret; })())) {
            c.o = b;
            c.i();
        }
        else {
            c = new LruCache_LruCacheNode$2(this.$tKey, this.$tValue);
            c.n = a;
            c.o = b;
            c.j(this.a);
            this.d.addItem(a, c);
            if (this.d.count > this.e) {
                this.d.removeItem(this.a.d.n);
                this.a.d.m();
            }
        }
    }
    i() {
        this.d.clear();
        this.a.e();
    }
    c(a) {
        let b;
        let c;
        b = ((() => { let d = this.d.tryGetValue(a, c); c = d.p1; return d.ret; })());
        if (b) {
            c.m();
            this.d.removeItem(a);
        }
        return b;
    }
}
LruCache$2.$t = markType(LruCache$2, 'LruCache$2');
//# sourceMappingURL=LruCache$2.js.map