Sha256: 78b12889af29725d6df0cf14dda1d4c3c315de1492290a9e00a7d8178d4f61f4
Contents?: true
Size: 919 Bytes
Versions: 5
Compression:
Stored size: 919 Bytes
Contents
module Dcha module MPT class Node < Array # :nodoc: module Findable def find(nbk) case type when :blank then Node::BLANK.first when :branch then find_branch(nbk) when :leaf then find_leaf(nbk) when :extension then find_extension(nbk) end end private def find_branch(nbk) return last if nbk.empty? node = Node.decode(self[nbk[0]]) node.find(nbk[1..-1]) end def find_leaf(nbk) key = NibbleKey.decode(first).terminate(false) nbk == key ? self[1] : Node::BLANK.first end def find_extension(nbk) key = NibbleKey.decode(first).terminate(false) return Node::BLANK.first unless key.prefix?(nbk) node = Node.decode(self[1]) node.find nbk[key.size..-1] end end end end end
Version data entries
5 entries across 5 versions & 1 rubygems