Last active
August 19, 2020 22:11
-
-
Save PatrickJS/5b2aa83084e38ba1d1cce1e855a35900 to your computer and use it in GitHub Desktop.
simple LRU using Map https://repl.it/@PatrickJS1/SpatialLegitimateProcedure#index.ts
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
class LRU extends Map { | |
m = 10; | |
get(k) { | |
let i = super.get(k); | |
if (i) { | |
super.delete(k); | |
super.set(k, i); | |
} | |
return i; | |
} | |
set(k, v) { | |
super.delete(k); | |
if (super.size == this.m) { | |
super.delete(super.keys().next().value); | |
} | |
return super.set(k, v); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment