Class: SolidCache::MaglevHash::Preferences

Inherits:
Object
  • Object
show all
Defined in:
lib/solid_cache/maglev_hash.rb

Instance Method Summary collapse

Constructor Details

#initialize(offset, skip) ⇒ Preferences

Returns a new instance of Preferences.



57
58
59
60
# File 'lib/solid_cache/maglev_hash.rb', line 57

def initialize(offset, skip)
  @preferred_slots = TABLE_SIZE.times.map { |i| (offset + i * skip) % TABLE_SIZE }
  @rank = 0
end

Instance Method Details

#preferred_free_slot(lookup) ⇒ Object



62
63
64
65
66
67
# File 'lib/solid_cache/maglev_hash.rb', line 62

def preferred_free_slot(lookup)
  loop do
    slot = next_slot
    return slot if lookup[slot].nil?
  end
end