Class: TrieNode
- Inherits:
-
Object
- Object
- TrieNode
- Defined in:
- lib/classbench/trie_node.rb
Instance Attribute Summary collapse
-
#level ⇒ Object
depth of node.
-
#prefixes_count ⇒ Object
number of occurences of the prefix.
-
#subtree ⇒ Object
Hash mapping character -> TrieNode.
-
#subtree_weights ⇒ Object
Returns the value of attribute subtree_weights.
Instance Method Summary collapse
- #compute_weights ⇒ Object
- #increment_prefixes ⇒ Object
-
#initialize(level) ⇒ TrieNode
constructor
A new instance of TrieNode.
- #one_weight ⇒ Object
- #zero_weight ⇒ Object
Constructor Details
#initialize(level) ⇒ TrieNode
Returns a new instance of TrieNode.
8 9 10 11 12 13 14 15 |
# File 'lib/classbench/trie_node.rb', line 8 def initialize(level) self.prefixes_count = 0 self.subtree = {} self.subtree_weights = {} self.level = level end |
Instance Attribute Details
#level ⇒ Object
depth of node
2 3 4 |
# File 'lib/classbench/trie_node.rb', line 2 def level @level end |
#prefixes_count ⇒ Object
number of occurences of the prefix
3 4 5 |
# File 'lib/classbench/trie_node.rb', line 3 def prefixes_count @prefixes_count end |
#subtree ⇒ Object
Hash mapping character -> TrieNode
5 6 7 |
# File 'lib/classbench/trie_node.rb', line 5 def subtree @subtree end |
#subtree_weights ⇒ Object
Returns the value of attribute subtree_weights.
6 7 8 |
# File 'lib/classbench/trie_node.rb', line 6 def subtree_weights @subtree_weights end |
Instance Method Details
#compute_weights ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/classbench/trie_node.rb', line 17 def compute_weights weight = 0 subtree.each do |char, st| self.subtree_weights[char] = st.compute_weights weight += self.subtree_weights[char] end weight += self.prefixes_count end |
#increment_prefixes ⇒ Object
28 29 30 |
# File 'lib/classbench/trie_node.rb', line 28 def increment_prefixes self.prefixes_count += 1 end |
#one_weight ⇒ Object
36 37 38 |
# File 'lib/classbench/trie_node.rb', line 36 def one_weight subtree_weights["1"] end |
#zero_weight ⇒ Object
32 33 34 |
# File 'lib/classbench/trie_node.rb', line 32 def zero_weight subtree_weights["0"] end |