/** @internal NOTE: Internal APIs. Subject to change. Use of these APIs in production applications is not supported. */
import '../MapExtensions';
/** Biderctional map. Its a normal map but by using the {@link reverse} property it is possible to perform lookups
 *  in the "reverse" direction.
 */
export class BidirectionalMap {
    _byKey = new Map();
    _byVal = new Map();
    _reverse;
    constructor(parent) {
        if (parent === undefined) {
            this._reverse = new BidirectionalMap(this);
            this._reverse._byKey = this._byVal;
            this._reverse._byVal = this._byKey;
        }
        else {
            this._reverse = parent;
        }
    }
    get reverse() {
        return this._reverse;
    }
    getOrAdd(key, factory) {
        const ret = this.getOrAdd(key, (_key) => {
            const v = factory(_key);
            this._byVal.getOrAdd(v, () => _key);
            return v;
        });
        return ret;
    }
    /** See {@link Map} */
    clear() {
        this._byKey.clear();
        this._byVal.clear();
    }
    /** See {@link Map} */
    delete(key) {
        const v = this._byKey.get(key);
        if (v) {
            this._byKey.delete(key);
            this._byVal.delete(v);
        }
        return v !== undefined;
    }
    /** See {@link Map} */
    // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
    forEach(callbackfn, thisArg) {
        this._byKey.forEach(callbackfn, thisArg);
    }
    /** See {@link Map} */
    get(key) {
        return this._byKey.get(key);
    }
    /** See {@link Map} */
    has(key) {
        return this._byKey.has(key);
    }
    /** See {@link Map} */
    set(key, value) {
        this._byKey.set(key, value);
        this._byVal.set(value, key);
        return this;
    }
    /** See {@link Map} */
    get size() {
        return this._byKey.size;
    }
    /** See {@link Map} */
    [Symbol.iterator]() {
        return this._byKey[Symbol.iterator]();
    }
    /** See {@link Map} */
    entries() {
        return this._byKey.entries();
    }
    /** See {@link Map} */
    keys() {
        return this._byKey.keys();
    }
    /** See {@link Map} */
    values() {
        return this._byKey.values();
    }
    /** See {@link Map} */
    get [Symbol.toStringTag]() {
        return this._byKey[Symbol.toStringTag];
    }
}
//# sourceMappingURL=bidirectional-map.js.map