Class: MSSMT::LeafNode
- Inherits:
-
Object
- Object
- MSSMT::LeafNode
- Defined in:
- lib/mssmt/leaf_node.rb
Overview
Leaf node within a MS-SMT that commit to a value and some integer value (the sum) associated with the value.
Instance Attribute Summary collapse
-
#sum ⇒ Object
readonly
Returns the value of attribute sum.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Class Method Summary collapse
-
.empty_leaf ⇒ MSSMT::LeafNode
Generate empty leaf node.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#empty? ⇒ Boolean
Check whether value and sum is empty.
-
#initialize(value, sum) ⇒ LeafNode
constructor
Constructor.
-
#node_hash ⇒ String
Calculate node hash.
Constructor Details
#initialize(value, sum) ⇒ LeafNode
Constructor
12 13 14 15 16 17 18 |
# File 'lib/mssmt/leaf_node.rb', line 12 def initialize(value, sum) @value = value if sum > Tree::MAX_SUM_VALUE raise OverflowError, "sum: #{sum} is overflow" end @sum = sum end |
Instance Attribute Details
#sum ⇒ Object (readonly)
Returns the value of attribute sum.
6 7 8 |
# File 'lib/mssmt/leaf_node.rb', line 6 def sum @sum end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
6 7 8 |
# File 'lib/mssmt/leaf_node.rb', line 6 def value @value end |
Class Method Details
.empty_leaf ⇒ MSSMT::LeafNode
Generate empty leaf node.
22 23 24 |
# File 'lib/mssmt/leaf_node.rb', line 22 def self.empty_leaf LeafNode.new(nil, 0) end |
Instance Method Details
#==(other) ⇒ Object
38 39 40 41 |
# File 'lib/mssmt/leaf_node.rb', line 38 def ==(other) return false unless other.is_a?(LeafNode) node_hash == other.node_hash end |
#empty? ⇒ Boolean
Check whether value and sum is empty.
34 35 36 |
# File 'lib/mssmt/leaf_node.rb', line 34 def empty? (value.nil? or value.empty?) && sum.zero? end |
#node_hash ⇒ String
Calculate node hash.
28 29 30 |
# File 'lib/mssmt/leaf_node.rb', line 28 def node_hash Digest::SHA256.digest("#{value}#{[sum].pack("Q>")}") end |