Class: LRUCache
- Inherits:
-
Object
- Object
- LRUCache
- Defined in:
- lib/simms_structures/lru_cache.rb
Instance Attribute Summary collapse
-
#count ⇒ Object
readonly
Returns the value of attribute count.
Instance Method Summary collapse
- #get(key) ⇒ Object
-
#initialize(max, prc) ⇒ LRUCache
constructor
A new instance of LRUCache.
- #to_s ⇒ Object
Constructor Details
#initialize(max, prc) ⇒ LRUCache
Returns a new instance of LRUCache.
8 9 10 11 12 13 |
# File 'lib/simms_structures/lru_cache.rb', line 8 def initialize(max, prc) @map = HashMap.new @store = LinkedList.new @max = max @prc = prc end |
Instance Attribute Details
#count ⇒ Object (readonly)
Returns the value of attribute count.
6 7 8 |
# File 'lib/simms_structures/lru_cache.rb', line 6 def count @count end |
Instance Method Details
#get(key) ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/simms_structures/lru_cache.rb', line 19 def get(key) link = @map[key] if link update_link!(link) link.val else eject! if @map.count == @max calc!(key).val end end |
#to_s ⇒ Object
30 31 32 |
# File 'lib/simms_structures/lru_cache.rb', line 30 def to_s "Map: " + @map.to_s + "\n" + "Store: " + @store.to_s end |