All Downloads are FREE. Search and download functionalities are using the official Maven repository.

package.build.cjs.lru.js.map Maven / Gradle / Ivy

The newest version!
{"version":3,"file":"lru.js","sources":["../../src/lru.ts"],"sourcesContent":["/** A simple Least Recently Used map */\nexport class LRUMap {\n  private readonly _cache: Map;\n\n  public constructor(private readonly _maxSize: number) {\n    this._cache = new Map();\n  }\n\n  /** Get the current size of the cache */\n  public get size(): number {\n    return this._cache.size;\n  }\n\n  /** Get an entry or undefined if it was not in the cache. Re-inserts to update the recently used order */\n  public get(key: K): V | undefined {\n    const value = this._cache.get(key);\n    if (value === undefined) {\n      return undefined;\n    }\n    // Remove and re-insert to update the order\n    this._cache.delete(key);\n    this._cache.set(key, value);\n    return value;\n  }\n\n  /** Insert an entry and evict an older entry if we've reached maxSize */\n  public set(key: K, value: V): void {\n    if (this._cache.size >= this._maxSize) {\n      // keys() returns an iterator in insertion order so keys().next() gives us the oldest key\n      this._cache.delete(this._cache.keys().next().value);\n    }\n    this._cache.set(key, value);\n  }\n\n  /** Remove an entry and return the entry if it was in the cache */\n  public remove(key: K): V | undefined {\n    const value = this._cache.get(key);\n    if (value) {\n      this._cache.delete(key);\n    }\n    return value;\n  }\n\n  /** Clear all entries */\n  public clear(): void {\n    this._cache.clear();\n  }\n\n  /** Get all the keys */\n  public keys(): Array {\n    return Array.from(this._cache.keys());\n  }\n\n  /** Get all the values */\n  public values(): Array {\n    const values: V[] = [];\n    this._cache.forEach(value => values.push(value));\n    return values;\n  }\n}\n"],"names":[],"mappings":";;AAAA;AACO,MAAM,MAAM,CAAO;;AAG1B,GAAS,WAAW,GAAkB,QAAQ,EAAU,CAAA,IAAA,CAAA,QAAA,GAAA,QAAA;AACxD,IAAI,IAAI,CAAC,MAAA,GAAS,IAAI,GAAG,EAAQ;AACjC;;AAEA;AACA,GAAS,IAAI,IAAI,GAAW;AAC5B,IAAI,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI;AAC3B;;AAEA;AACA,GAAS,GAAG,CAAC,GAAG,EAA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