class XRBP::SHAMap::InnerNode
A DB entry which may contain references of up to 16-child nodes, facilitating abstract tree-like traversal.
This class simply encapsulates children w/ hashes
Attributes
common[RW]
depth[RW]
hashes[RW]
is_branch[RW]
Public Class Methods
new(args={})
click to toggle source
# File lib/xrbp/nodestore/shamap/inner_node.rb, line 10 def initialize(args={}) @v2 = args[:v2] @depth = args[:depth] || 0 @common = {} @hashes = {} @children = [] @is_branch = 0 end
Public Instance Methods
canonicalize_child(branch, node)
click to toggle source
Canonicalize and store child node at branch
# File lib/xrbp/nodestore/shamap/inner_node.rb, line 66 def canonicalize_child(branch, node) raise ArgumentError unless branch >= 0 && branch < 16 raise unless node raise unless node.hash == hashes[branch] if @children[branch] return @children[branch] else return @children[branch] = node end end
child(branch)
click to toggle source
Returns child containing in given branch
# File lib/xrbp/nodestore/shamap/inner_node.rb, line 59 def child(branch) raise ArgumentError unless branch >= 0 && branch < 16 @children[branch] end
child_hash(branch)
click to toggle source
Returns hash of child on given branch
# File lib/xrbp/nodestore/shamap/inner_node.rb, line 52 def child_hash(branch) raise ArgumentError unless branch >= 0 && branch < 16 hashes[branch] end
common_prefix?(key)
click to toggle source
# File lib/xrbp/nodestore/shamap/inner_node.rb, line 28 def common_prefix?(key) hd = depth/2 0.upto(hd) do |d| return false if common[d] != key[d] end return (common[hd] & 0xF0) && (key[hd] & 0xF0) if depth & 1 return true end
empty?()
click to toggle source
Returns true if node has no children
# File lib/xrbp/nodestore/shamap/inner_node.rb, line 41 def empty? is_branch == 0 end
empty_branch?(branch)
click to toggle source
Return true if specified branch is empty, else false
# File lib/xrbp/nodestore/shamap/inner_node.rb, line 47 def empty_branch?(branch) (is_branch & (1 << branch)) == 0 end
inner?()
click to toggle source
# File lib/xrbp/nodestore/shamap/inner_node.rb, line 24 def inner? true end
update_hash()
click to toggle source
Update this node's hash from child hashes
# File lib/xrbp/nodestore/shamap/inner_node.rb, line 80 def update_hash nh = nil if is_branch != 0 sha512 = OpenSSL::Digest::SHA512.new sha512 << HASH_+PREFIXES[:inner_node] hashes.each { |k,h| sha512 << v } nh = sha512.digest end return false if nh == self.hash self.hash = nh return true end
v2?()
click to toggle source
# File lib/xrbp/nodestore/shamap/inner_node.rb, line 20 def v2? @v2 end