Class: Key
- Inherits:
-
Object
- Object
- Key
- Defined in:
- lib/scale/trie.rb
Instance Method Summary collapse
-
#initialize(value) ⇒ Key
constructor
A new instance of Key.
- #next_nibble(partial, padding) ⇒ Object
Constructor Details
#initialize(value) ⇒ Key
Returns a new instance of Key.
153 154 155 156 |
# File 'lib/scale/trie.rb', line 153 def initialize(value) @value = value[2..] if value.start_with?("0x") @offset = 0 end |
Instance Method Details
#next_nibble(partial, padding) ⇒ Object
158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/scale/trie.rb', line 158 def next_nibble(partial, padding) partial = partial[2..] if partial.start_with?("0x") partial = partial[1..] if padding new_offset = @offset + partial.length if partial == @value[@offset...new_offset] nibble = @value[new_offset] @offset = new_offset + 1 return nibble else raise "Fail" end end |