class Algorithmable::Cache::PrimitiveMinHeap

Public Class Methods

new(index = []) click to toggle source
# File lib/algorithmable/cache/primitive_min_heap.rb, line 10
def initialize(index = [])
  @storage = {}
  @index = index
end

Public Instance Methods

[](key) click to toggle source
# File lib/algorithmable/cache/primitive_min_heap.rb, line 20
def [](key)
  @storage[key].tap do |value|
    sink key if value
  end
end
[]=(key, value) click to toggle source
# File lib/algorithmable/cache/primitive_min_heap.rb, line 15
def []=(key, value)
  sink key
  @storage[key] = value
end

Private Instance Methods

sink(key) click to toggle source
# File lib/algorithmable/cache/primitive_min_heap.rb, line 28
def sink(key)
  @index.delete(key)
  @index.push(key)
end