export default class LRUCache {
    constructor(size) {
        this.size = size;
        this.values = new Map();
        if (size <= 0)
            throw new Error('Size must be greater than 0');
    }
    get(key) {
        const hasKey = this.values.has(key);
        let entry;
        if (hasKey) {
            // Pop entry and move to end
            entry = this.values.get(key);
            this.values.delete(key);
            this.values.set(key, entry);
        }
        return entry;
    }
    set(key, value) {
        if (this.values.size >= this.size) {
            // Remove least recently used entry
            const keyToDelete = this.values.keys().next().value;
            this.values.delete(keyToDelete);
        }
        this.values.set(key, value);
    }
}
