Class: RubyIndexer::PrefixTree::Node
- Inherits:
-
Object
- Object
- RubyIndexer::PrefixTree::Node
- Defined in:
- lib/ruby_indexer/lib/ruby_indexer/prefix_tree.rb
Overview
: [Value]
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
: Hash[String, Node].
-
#key ⇒ Object
readonly
: String.
-
#leaf ⇒ Object
: bool.
-
#parent ⇒ Object
readonly
: Node?.
-
#value ⇒ Object
: Value.
Instance Method Summary collapse
-
#collect ⇒ Object
: -> Array.
-
#initialize(key, value, parent = nil) ⇒ Node
constructor
: (String key, Value value, ?Node? parent) -> void.
Constructor Details
#initialize(key, value, parent = nil) ⇒ Node
: (String key, Value value, ?Node? parent) -> void
127 128 129 130 131 132 133 |
# File 'lib/ruby_indexer/lib/ruby_indexer/prefix_tree.rb', line 127 def initialize(key, value, parent = nil) @key = key @value = value @parent = parent @children = {} @leaf = false end |
Instance Attribute Details
#children ⇒ Object (readonly)
: Hash[String, Node]
112 113 114 |
# File 'lib/ruby_indexer/lib/ruby_indexer/prefix_tree.rb', line 112 def children @children end |
#key ⇒ Object (readonly)
: String
115 116 117 |
# File 'lib/ruby_indexer/lib/ruby_indexer/prefix_tree.rb', line 115 def key @key end |
#leaf ⇒ Object
: bool
121 122 123 |
# File 'lib/ruby_indexer/lib/ruby_indexer/prefix_tree.rb', line 121 def leaf @leaf end |
#parent ⇒ Object (readonly)
: Node?
124 125 126 |
# File 'lib/ruby_indexer/lib/ruby_indexer/prefix_tree.rb', line 124 def parent @parent end |
#value ⇒ Object
: Value
118 119 120 |
# File 'lib/ruby_indexer/lib/ruby_indexer/prefix_tree.rb', line 118 def value @value end |
Instance Method Details
#collect ⇒ Object
: -> Array
136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/ruby_indexer/lib/ruby_indexer/prefix_tree.rb', line 136 def collect result = [] stack = [self] while (node = stack.pop) result << node.value if node.leaf stack.concat(node.children.values) end result end |