import { OrderedSet } from "./set.js";
/**
 * An implementation of Map that support getting first/last key and value.
 */
export class OrderedMap {
    _set;
    map;
    constructor() {
        this._set = new OrderedSet();
        this.map = new Map();
    }
    get(key) {
        return this.map.get(key);
    }
    set(key, value) {
        this._set.add(key);
        this.map.set(key, value);
        return this;
    }
    delete(key, searchFromHead) {
        if (this.map.has(key)) {
            this._set.delete(key, searchFromHead);
            return this.map.delete(key);
        }
        return false;
    }
    keys() {
        return this._set.values();
    }
    lastKey() {
        return this._set.last();
    }
    firstKey() {
        return this._set.first();
    }
    values() {
        const _self = this;
        return (function* generateValues() {
            for (const key of _self.keys()) {
                yield _self.get(key);
            }
        })();
    }
    lastValue() {
        const lastKey = this._set.last();
        if (lastKey === null) {
            return null;
        }
        return this.get(lastKey);
    }
    firstValue() {
        const firstKey = this._set.first();
        if (firstKey === null) {
            return null;
        }
        return this.get(firstKey);
    }
    size() {
        return this._set.size;
    }
    has(key) {
        return this.map.has(key);
    }
}
//# sourceMappingURL=map.js.map