manrajgrover / algorithms-js

Consumable Data Structures and Algorithms library in JavaScript
MIT License
198 stars 129 forks source link

Add LRUCache, along with test cases #149

Open zhengjynicolas opened 7 months ago

zhengjynicolas commented 7 months ago

Description of new feature, or changes

Least Recently Used (LRU) cache. This LRUCache implemented base on original data structure Map. When trying to add a new key-value pair, if cache.size == cache.capacity, the Least Recently Used key is removed. The size of this LRU is also a property. Property capacity is allowed to be reset, Least Recently Used keys will be removed when capacity is set to smaller one.

Checklist

Related Issues and Discussions

implement https://github.com/manrajgrover/algorithms-js/issues/17

People to notify

@manrajgrover