Class: TrieFile::Node
- Inherits:
-
Object
- Object
- TrieFile::Node
- Defined in:
- lib/trie-file/node.rb
Constant Summary collapse
- CHILD_FIELDS_LENGTH =
6
- HEADER_FIELD_LENGTH =
4
Instance Attribute Summary collapse
-
#byte_pos ⇒ Object
Returns the value of attribute byte_pos.
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
- #add_child(char, node) ⇒ Object
- #bytesize ⇒ Object
- #child_at(char) ⇒ Object
- #has_child?(char) ⇒ Boolean
-
#initialize(value = nil) ⇒ Node
constructor
A new instance of Node.
- #value_bytes ⇒ Object
- #value_bytesize ⇒ Object
Constructor Details
#initialize(value = nil) ⇒ Node
Returns a new instance of Node.
11 12 13 14 15 |
# File 'lib/trie-file/node.rb', line 11 def initialize(value = nil) @value = value @children = {} @byte_pos = 0 end |
Instance Attribute Details
#byte_pos ⇒ Object
Returns the value of attribute byte_pos.
9 10 11 |
# File 'lib/trie-file/node.rb', line 9 def byte_pos @byte_pos end |
#children ⇒ Object (readonly)
Returns the value of attribute children.
8 9 10 |
# File 'lib/trie-file/node.rb', line 8 def children @children end |
#value ⇒ Object
Returns the value of attribute value.
9 10 11 |
# File 'lib/trie-file/node.rb', line 9 def value @value end |
Instance Method Details
#add_child(char, node) ⇒ Object
25 26 27 |
# File 'lib/trie-file/node.rb', line 25 def add_child(char, node) @children[char] = node end |
#bytesize ⇒ Object
29 30 31 32 |
# File 'lib/trie-file/node.rb', line 29 def bytesize # add some constants here HEADER_FIELD_LENGTH + (children.size * CHILD_FIELDS_LENGTH) + value_bytesize end |
#child_at(char) ⇒ Object
21 22 23 |
# File 'lib/trie-file/node.rb', line 21 def child_at(char) children[char] end |
#has_child?(char) ⇒ Boolean
17 18 19 |
# File 'lib/trie-file/node.rb', line 17 def has_child?(char) children.include?(char) end |
#value_bytes ⇒ Object
38 39 40 |
# File 'lib/trie-file/node.rb', line 38 def value_bytes value ? value.bytes : [] end |
#value_bytesize ⇒ Object
34 35 36 |
# File 'lib/trie-file/node.rb', line 34 def value_bytesize value ? value.bytesize : 0 end |