Skip to content

Instantly share code, notes, and snippets.

@PatrickJS
Last active August 19, 2020 22:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PatrickJS/5b2aa83084e38ba1d1cce1e855a35900 to your computer and use it in GitHub Desktop.
Save PatrickJS/5b2aa83084e38ba1d1cce1e855a35900 to your computer and use it in GitHub Desktop.
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