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.



59
60
61
62
# File 'lib/solid_cache/maglev_hash.rb', line 59

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



64
65
66
67
68
69
# File 'lib/solid_cache/maglev_hash.rb', line 64

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