forked from Tevemadar/WebAlign
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'Tevemadar:master' into master
- Loading branch information
Showing
3 changed files
with
432 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
class LRUCache { | ||
#map = new Map; | ||
#capacity; | ||
constructor(capacity) { | ||
this.#capacity = capacity; | ||
} | ||
get(key) { | ||
if (!this.#map.has(key)) | ||
return null; | ||
const value = this.#map.get(key); | ||
this.#map.delete(key); | ||
this.#map.set(key, value); | ||
return value; | ||
} | ||
put(key, value) { | ||
while (this.#map.size >= this.#capacity) | ||
this.#map.delete(this.#map.keys().next().value); | ||
this.#map.set(key, value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.