Class: Algorithmable::Cache::Imp
- Inherits:
-
Object
- Object
- Algorithmable::Cache::Imp
- Extended by:
- Forwardable
- Defined in:
- lib/algorithmable/cache/imp.rb
Instance Method Summary collapse
- #[]=(key, value) ⇒ Object
-
#initialize(max_size, heap) ⇒ Imp
constructor
A new instance of Imp.
Constructor Details
#initialize(max_size, heap) ⇒ Imp
Returns a new instance of Imp.
8 9 10 11 |
# File 'lib/algorithmable/cache/imp.rb', line 8 def initialize(max_size, heap) @max_size = max_size @heap = heap end |
Instance Method Details
#[]=(key, value) ⇒ Object
13 14 15 16 |
# File 'lib/algorithmable/cache/imp.rb', line 13 def []=(key, value) @heap.pop if @heap.size >= @max_size @heap[key] = value end |