Class: Key

Inherits:
Object
  • Object
show all
Defined in:
lib/scale/trie.rb

Instance Method Summary collapse

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