Class: RubyIndexer::PrefixTree::Node

Inherits:
Object
  • Object
show all
Extended by:
T::Generic, T::Sig
Defined in:
lib/ruby_indexer/lib/ruby_indexer/prefix_tree.rb

Constant Summary collapse

Value =
type_member

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, value, parent = nil) ⇒ Node

Returns a new instance of Node.



132
133
134
135
136
137
138
# File 'lib/ruby_indexer/lib/ruby_indexer/prefix_tree.rb', line 132

def initialize(key, value, parent = nil)
  @key = key
  @value = value
  @parent = parent
  @children = T.let({}, T::Hash[String, Node[Value]])
  @leaf = T.let(false, T::Boolean)
end

Instance Attribute Details

#childrenObject (readonly)

Returns the value of attribute children.



117
118
119
# File 'lib/ruby_indexer/lib/ruby_indexer/prefix_tree.rb', line 117

def children
  @children
end

#keyObject (readonly)

Returns the value of attribute key.



120
121
122
# File 'lib/ruby_indexer/lib/ruby_indexer/prefix_tree.rb', line 120

def key
  @key
end

#leafObject

Returns the value of attribute leaf.



126
127
128
# File 'lib/ruby_indexer/lib/ruby_indexer/prefix_tree.rb', line 126

def leaf
  @leaf
end

#parentObject (readonly)

Returns the value of attribute parent.



129
130
131
# File 'lib/ruby_indexer/lib/ruby_indexer/prefix_tree.rb', line 129

def parent
  @parent
end

#valueObject

Returns the value of attribute value.



123
124
125
# File 'lib/ruby_indexer/lib/ruby_indexer/prefix_tree.rb', line 123

def value
  @value
end

Instance Method Details

#collectObject



141
142
143
144
145
146
147
148
149
150
# File 'lib/ruby_indexer/lib/ruby_indexer/prefix_tree.rb', line 141

def collect
  result = T.let([], T::Array[Value])
  result << value if leaf

  children.each_value do |node|
    result.concat(node.collect)
  end

  result
end