class RubyTrie::TrieNode

A TrieNode is a node in the Trie derives from the TreeNode class You should only need this class if you use Tree methods to walk the tree and such-like

Public Instance Methods

add_node(string, value) → TrieContent click to toggle source

adds adds a node at a particular point if the node already exists, then it will overwrite the value

# File lib/ruby_trie.rb, line 52
def add_node(string, value)
   current_node = self.root
   current_string = ''
   chars = string.split('')
   
   chars.each do |c|
      current_string << c
      child = current_node[c]
      unless child 
         child = TrieNode.new(c)
         current_node.add(child)
      end
      current_node = child
   end
   
   current_node.content = TrieContent.new(string, value)   
end
get_node(string) → TrieNode click to toggle source

return the TreeNode corresponding to a given string

# File lib/ruby_trie.rb, line 74
def get_node(string)
   current_node = self.root
   current_string = ''
   chars = string.split('')
   
   chars.each do |c|
      current_string << c
      current_node = current_node[c]
      break unless current_node
   end
   
   current_node
end
get_node_value(string) → Object click to toggle source

gets the value at a node returns nil if the node does not exist

# File lib/ruby_trie.rb, line 92
def get_node_value(string)
   node = get_node(string)
   node&.content&.value
end