export default class Dictionary<TKey, TValue>{

    public constructor() {
        this.keys = new Array<TKey>();
        this.values = new Array<TValue>();
    }
    public keys: Array<TKey>;
    public values: Array<TValue>;
    public get count(): number {
        return this.keys.length;
    }
    public add(key: TKey, value: TValue) {
        let index = this.keys.indexOf(key);
        if (index == -1) {
            this.keys.push(key);
            this.values.push(value);
        } else {
            this.values[index] = value;
        }
    }

    public remove(key: TKey) {
        let index = this.keys.indexOf(key);
        if (index != -1) {
            this.keys.splice(index, 1);
            this.values.splice(index, 1);
        }
    }

    public getValue(key: TKey): TValue {
        let index = this.keys.indexOf(key);
        if (index != -1) {
            return this.values[index];
        }
        return null
    }

    public containKey(key: TKey) {
        let index = this.keys.indexOf(key);
        if (index != -1) {
            return true;
        }
        return false;
    }

    public containValue(value: TValue) {
        let index = this.values.indexOf(value);
        if (index != -1) {
            return true;
        }
        return false;
    }

    public clear() {
        this.keys.length = 0;
        this.values.length = 0;
    }

}