Class: SolidCache::MaglevHash
- Inherits:
-
Object
- Object
- SolidCache::MaglevHash
- Defined in:
- lib/solid_cache/maglev_hash.rb
Defined Under Namespace
Classes: Preferences
Constant Summary collapse
- TABLE_SIZE =
Must be prime
2053
Instance Attribute Summary collapse
-
#nodes ⇒ Object
readonly
Returns the value of attribute nodes.
Instance Method Summary collapse
-
#initialize(nodes) ⇒ MaglevHash
constructor
A new instance of MaglevHash.
- #node(key) ⇒ Object
Constructor Details
#initialize(nodes) ⇒ MaglevHash
Returns a new instance of MaglevHash.
12 13 14 15 16 17 18 |
# File 'lib/solid_cache/maglev_hash.rb', line 12 def initialize(nodes) raise ArgumentError, "No nodes specified" if nodes.count == 0 raise ArgumentError, "Maximum node count is #{TABLE_SIZE}" if nodes.count > TABLE_SIZE @nodes = nodes.uniq.sort @lookup = build_lookup end |
Instance Attribute Details
#nodes ⇒ Object (readonly)
Returns the value of attribute nodes.
7 8 9 |
# File 'lib/solid_cache/maglev_hash.rb', line 7 def nodes @nodes end |
Instance Method Details
#node(key) ⇒ Object
20 21 22 |
# File 'lib/solid_cache/maglev_hash.rb', line 20 def node(key) nodes[lookup[quick_hash(key) % TABLE_SIZE]] end |