algorithms-js icon indicating copy to clipboard operation
algorithms-js copied to clipboard

Implemented LRU Cache Data Structure

Open strobelo opened this issue 6 years ago • 0 comments

Description of new feature, or changes

Introduces a class (LRUCache) which implements a least-recently-used cache data structure. LRU cache is most commonly known for its popularity in operating systems applications for managing system memory caches.

This implementation accepts entries as key-value pairs. If a new entry would exceed the cache's configured maximum size, the least recently retrieved items are removed and destroyed from memory until there is enough room for the new one.

By default, items are considered to have size 1. However, you can specify a custom size function for how big to consider items. For example, if you are storing strings in your cache with a maximum limit of 20, you could specify that the cache should consider the string's length as its size, you would effectively have a cache with a maximum size of 20 bytes.

Checklist

  • [x] Your branch is up-to-date with the base branch
  • [x] You've included at least one test if this is a new feature
  • [x] All tests are passing

Related Issues and Discussions

Implements #17

People to notify

@manrajgrover

strobelo avatar Oct 21 '18 19:10 strobelo