UNPKG

1.59 kBTypeScriptView Raw
1export declare namespace Touch {
2 const None: 0;
3 const First: 1;
4 const AsOld: 1;
5 const Last: 2;
6 const AsNew: 2;
7}
8export type Touch = 0 | 1 | 2;
9export declare class LinkedMap<K, V> implements Map<K, V> {
10 readonly [Symbol.toStringTag] = "LinkedMap";
11 private _map;
12 private _head;
13 private _tail;
14 private _size;
15 private _state;
16 constructor();
17 clear(): void;
18 isEmpty(): boolean;
19 get size(): number;
20 get first(): V | undefined;
21 get last(): V | undefined;
22 has(key: K): boolean;
23 get(key: K, touch?: Touch): V | undefined;
24 set(key: K, value: V, touch?: Touch): this;
25 delete(key: K): boolean;
26 remove(key: K): V | undefined;
27 shift(): V | undefined;
28 forEach(callbackfn: (value: V, key: K, map: LinkedMap<K, V>) => void, thisArg?: any): void;
29 keys(): IterableIterator<K>;
30 values(): IterableIterator<V>;
31 entries(): IterableIterator<[K, V]>;
32 [Symbol.iterator](): IterableIterator<[K, V]>;
33 protected trimOld(newSize: number): void;
34 private addItemFirst;
35 private addItemLast;
36 private removeItem;
37 private touch;
38 toJSON(): [K, V][];
39 fromJSON(data: [K, V][]): void;
40}
41export declare class LRUCache<K, V> extends LinkedMap<K, V> {
42 private _limit;
43 private _ratio;
44 constructor(limit: number, ratio?: number);
45 get limit(): number;
46 set limit(limit: number);
47 get ratio(): number;
48 set ratio(ratio: number);
49 get(key: K, touch?: Touch): V | undefined;
50 peek(key: K): V | undefined;
51 set(key: K, value: V): this;
52 private checkTrim;
53}