class Algorithmable::Cache::PrimitiveMaxHeap
Public Class Methods
new(index = [])
click to toggle source
# File lib/algorithmable/cache/primitive_max_heap.rb, line 10 def initialize(index = []) @storage = {} @index = index end
Public Instance Methods
[](key)
click to toggle source
# File lib/algorithmable/cache/primitive_max_heap.rb, line 20 def [](key) @storage[key].tap do |value| swim key if value end end
[]=(key, value)
click to toggle source
# File lib/algorithmable/cache/primitive_max_heap.rb, line 15 def []=(key, value) swim key @storage[key] = value end
Private Instance Methods
swim(key)
click to toggle source
# File lib/algorithmable/cache/primitive_max_heap.rb, line 28 def swim(key) @index.delete(key) @index.unshift(key) end