Class: Komainu::TrieNode

Inherits:
Object
  • Object
show all
Defined in:
lib/komainu/trie_node.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTrieNode

Returns a new instance of TrieNode.



5
6
7
# File 'lib/komainu/trie_node.rb', line 5

def initialize
  @children = {}
end

Instance Attribute Details

#childrenObject

Returns the value of attribute children.



3
4
5
# File 'lib/komainu/trie_node.rb', line 3

def children
  @children
end

#wordObject

Returns the value of attribute word.



3
4
5
# File 'lib/komainu/trie_node.rb', line 3

def word
  @word
end

Instance Method Details

#insert(word) ⇒ Object



9
10
11
12
13
14
15
16
17
18
# File 'lib/komainu/trie_node.rb', line 9

def insert word
  node = self
  word.each_char do |letter|
    unless node.children[letter]
      node.children[letter] = TrieNode.new
    end
    node = node.children[letter]
  end
  node.word = word
end