class Rambling::Trie::Nodes::Raw

A representation of a node in an uncompressed trie data structure.

Public Instance Methods

add(chars) click to toggle source

Adds a word to the current raw (uncompressed) trie node. @param [Array<Symbol>] chars the char array to add to the trie. @return [Raw] the added/modified node based on the word added. @note This method clears the contents of the chars variable.

# File lib/rambling/trie/nodes/raw.rb, line 12
def add chars
  if chars.empty?
    terminal!
  else
    add_to_children_tree chars
  end
end
compressed?() click to toggle source

Always return `false` for a raw (uncompressed) node. @return [Boolean] always `false` for a raw (uncompressed) node.

# File lib/rambling/trie/nodes/raw.rb, line 22
def compressed?
  false
end

Private Instance Methods

add_to_children_tree(chars) click to toggle source
# File lib/rambling/trie/nodes/raw.rb, line 28
def add_to_children_tree chars
  letter = chars.pop
  child = children_tree[letter] || new_node(letter)
  child.add chars
  child
end
children_match_prefix(chars) { |word| ... } click to toggle source
# File lib/rambling/trie/nodes/raw.rb, line 65
def children_match_prefix chars
  return enum_for :children_match_prefix, chars unless block_given?

  return if chars.empty?

  letter = chars.shift.to_sym
  child = children_tree[letter]

  return unless child

  child.match_prefix chars do |word|
    yield word
  end
end
closest_node(chars) click to toggle source
# File lib/rambling/trie/nodes/raw.rb, line 57
def closest_node chars
  letter = chars.shift.to_sym
  child = children_tree[letter]
  return missing unless child

  child.scan chars
end
new_node(letter) click to toggle source
# File lib/rambling/trie/nodes/raw.rb, line 35
def new_node letter
  node = Rambling::Trie::Nodes::Raw.new letter, self
  children_tree[letter] = node
  node
end
partial_word_chars?(chars = []) click to toggle source
# File lib/rambling/trie/nodes/raw.rb, line 41
def partial_word_chars? chars = []
  letter = chars.shift.to_sym
  child = children_tree[letter]
  return false unless child

  child.partial_word? chars
end
word_chars?(chars = []) click to toggle source
# File lib/rambling/trie/nodes/raw.rb, line 49
def word_chars? chars = []
  letter = chars.shift.to_sym
  child = children_tree[letter]
  return false unless child

  child.word? chars
end