/**
 * Bi-directional map
 * @template K,V
 */
export class BiMap {

    /**
     *
     * @type {Map<K, V>}
     */
    forward = new Map();
    /**
     *
     * @type {Map<V, K>}
     */
    backward = new Map();


    /**
     *
     * @param {K} key
     * @param {V} value
     */
    add(key, value) {
        this.forward.set(value, key);
        this.backward.set(key, value);
    }

    /**
     *
     * @param {V} value
     * @returns {K|undefined}
     */
    getKeyByValue(value) {
        return this.backward.get(value);
    }

    /**
     *
     * @param {K} address
     * @returns {V|undefined}
     */
    getValueByKey(address) {
        return this.forward.get(address);
    }
}

BiMap.prototype.get = BiMap.prototype.getValueByKey;
BiMap.prototype.set = BiMap.prototype.add;