Class: HashTable::StringTraits
- Inherits:
-
Object
- Object
- HashTable::StringTraits
- Defined in:
- lib/hashtable/traits.rb
Instance Attribute Summary collapse
-
#string_index ⇒ Object
readonly
Returns the value of attribute string_index.
-
#string_table ⇒ Object
readonly
Returns the value of attribute string_table.
Instance Method Summary collapse
- #hash_lookup_key(key) ⇒ Object
-
#initialize ⇒ StringTraits
constructor
A new instance of StringTraits.
- #lookup_key_to_storage_key(key) ⇒ Object
- #storage_key_to_lookup_key(offset) ⇒ Object
Constructor Details
#initialize ⇒ StringTraits
Returns a new instance of StringTraits.
22 23 24 25 |
# File 'lib/hashtable/traits.rb', line 22 def initialize @string_table = "\0" @string_index = 1 end |
Instance Attribute Details
#string_index ⇒ Object (readonly)
Returns the value of attribute string_index.
20 21 22 |
# File 'lib/hashtable/traits.rb', line 20 def string_index @string_index end |
#string_table ⇒ Object (readonly)
Returns the value of attribute string_table.
20 21 22 |
# File 'lib/hashtable/traits.rb', line 20 def string_table @string_table end |
Instance Method Details
#hash_lookup_key(key) ⇒ Object
27 28 29 30 31 |
# File 'lib/hashtable/traits.rb', line 27 def hash_lookup_key(key) result = 0 key.each_byte { |byte| result += byte * 13 } result end |
#lookup_key_to_storage_key(key) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/hashtable/traits.rb', line 33 def lookup_key_to_storage_key(key) @string_table += "#{key}\0" old_si = @string_index @string_index += key.length + 1 old_si end |
#storage_key_to_lookup_key(offset) ⇒ Object
40 41 42 |
# File 'lib/hashtable/traits.rb', line 40 def storage_key_to_lookup_key(offset) @string_table[offset..][/[^\0]+/] end |