erikras / lru-memoize

A utility to provide LRU memoization for any js function
MIT License
316 stars 20 forks source link

Replace shifts by push. #85

Open gamazeps opened 7 years ago

gamazeps commented 7 years ago

Push are O(1) operations whereas shift are O(n) operations, this removes this complexity.

Also returns a null as the comment says

heydiplo commented 6 years ago

@gamazeps,

With LRU we want most recent entry at the top of a cache (at 0, so it's searched first), that's why unshift.

null might be a valid return value we want to cache, undefined suits better.