(key: string)
| 6 | ) {} |
| 7 | |
| 8 | async initKey(key: string) { |
| 9 | // Maintain LRU |
| 10 | const index = this.items.findIndex((item) => item[0] === key); |
| 11 | |
| 12 | if (index < 0) { |
| 13 | // Calculate info for new file |
| 14 | const value: V | null = await this.calculateValue(key); |
| 15 | |
| 16 | if (value === null) { |
| 17 | return; |
| 18 | } |
| 19 | |
| 20 | this.items.push([key, value]); |
| 21 | if (this.items.length > this.N) { |
| 22 | this.items.shift(); |
| 23 | } |
| 24 | } else { |
| 25 | // Move to end of array, since it was recently used |
| 26 | const [item] = this.items.splice(index, 1); |
| 27 | this.items.push(item); |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | get(key: string): V | undefined { |
| 32 | return this.items.find((item) => item[0] === key)?.[1]; |
no test coverage detected