Download benchmarks/javascript/lru_cache.js from SevdanurGenc/LLM-Automated-Test-Generation-Agent: direct link, hf CLI and curl.
- Browser
- Download file 1.02 kB
-
https://huggingface.co/SevdanurGenc/LLM-Automated-Test-Generation-Agent/resolve/main/benchmarks/javascript/lru_cache.js
- Command line
-
hf download hf://SevdanurGenc/LLM-Automated-Test-Generation-Agent/benchmarks/javascript/lru_cache.js
-
curl -L -o lru_cache.js https://huggingface.co/SevdanurGenc/LLM-Automated-Test-Generation-Agent/resolve/main/benchmarks/javascript/lru_cache.js
1.02 kB
| /** Kapasite sınırlı, en uzun süre kullanılmayanı (LRU) atan önbellek. */ | |
| export class LRUCache { | |
| constructor(capacity) { | |
| if (!Number.isInteger(capacity) || capacity <= 0) { | |
| throw new RangeError('capacity pozitif tam sayı olmalı'); | |
| } | |
| this.capacity = capacity; | |
| this.map = new Map(); | |
| this.hits = 0; | |
| this.misses = 0; | |
| } | |
| get(key) { | |
| if (!this.map.has(key)) { | |
| this.misses++; | |
| return undefined; | |
| } | |
| const value = this.map.get(key); | |
| this.map.delete(key); | |
| this.map.set(key, value); | |
| this.hits++; | |
| return value; | |
| } | |
| set(key, value) { | |
| if (this.map.has(key)) this.map.delete(key); | |
| this.map.set(key, value); | |
| if (this.map.size > this.capacity) { | |
| const oldest = this.map.keys().next().value; | |
| this.map.delete(oldest); | |
| return oldest; | |
| } | |
| return undefined; | |
| } | |
| get size() { | |
| return this.map.size; | |
| } | |
| hitRate() { | |
| const total = this.hits + this.misses; | |
| return total === 0 ? 0 : this.hits / total; | |
| } | |
| } | |