Class: Rambling::Trie::Nodes::Raw

Inherits:
Node
  • Object
show all
Defined in:
lib/rambling/trie/nodes/raw.rb

Overview

A representation of a node in an uncompressed trie data structure. :reek:RepeatedConditional { max_ifs: 4 }

Instance Attribute Summary

Attributes inherited from Node

#children_tree, #letter, #parent, #value

Instance Method Summary collapse

Methods inherited from Node

#[], #[]=, #children, #delete, #first_child, #initialize, #key?, #match_prefix, #partial_word?, #root?, #scan, #terminal!, #terminal?, #word?

Methods included from Inspectable

#inspect

Methods included from Stringifyable

#as_word, #to_s

Methods included from Comparable

#==

Methods included from Enumerable

#each, #empty_enum

Methods included from Compressible

#compressible?

Constructor Details

This class inherits a constructor from Rambling::Trie::Nodes::Node

Instance Method Details

#add(reversed_chars, value = nil) ⇒ Node

Note:

This method consumes the array by popping each element during recursion, leaving it empty on return.

Adds a word to the current raw (uncompressed) trie node.

Parameters:

  • reversed_chars (Array<Symbol>)

    the char array to add to the trie, in reverse order.

Returns:

  • (Node)

    the added/modified node based on the word added.



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/rambling/trie/nodes/raw.rb', line 13

def add reversed_chars, value = nil
  if reversed_chars.empty?
    unless root?
      self.value = value
      terminal!
    end
    self
  else
    add_to_children_tree reversed_chars, value
  end
end

#compressed?Boolean

Always return ‘false` for a raw (uncompressed) node.

Returns:

  • (Boolean)

    always ‘false` for a raw (uncompressed) node.



27
28
29
# File 'lib/rambling/trie/nodes/raw.rb', line 27

def compressed?
  false
end