Class: Rambling::Trie::Nodes::Compressed

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

Overview

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

Constant Summary

Constants included from Enumerable

Enumerable::EMPTY_ENUMERATOR

Instance Attribute Summary

Attributes inherited from Node

#children_tree, #letter, #parent

Instance Method Summary collapse

Methods inherited from Node

#[], #[]=, #children, #delete, #first_child, #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

Methods included from Compressible

#compressible?

Constructor Details

#initialize(letter = nil, parent = nil, children_tree = {}) ⇒ Compressed

Creates a new compressed node.

Parameters:

  • letter (Symbol, nil) (defaults to: nil)

    the Node’s letter value.

  • parent (Node, nil) (defaults to: nil)

    the parent of the current node.

  • children_tree (Hash<Symbol, Node>) (defaults to: {})

    the children tree of the current node.



13
14
15
16
17
18
# File 'lib/rambling/trie/nodes/compressed.rb', line 13

def initialize letter = nil, parent = nil, children_tree = {}
  super

  # Ensure all children have the current compressed node as the parent
  children_tree.each_value { |child| child.parent = self }
end

Instance Method Details

#add(_) ⇒ void

This method returns an undefined value.

Always raises InvalidOperation when trying to add a word to the current compressed trie node

Parameters:

  • _ (String)

    the word to add to the trie.

Raises:



25
26
27
# File 'lib/rambling/trie/nodes/compressed.rb', line 25

def add _
  raise Rambling::Trie::InvalidOperation, 'Cannot add word to compressed trie'
end

#compressed?Boolean

Always return ‘true` for a compressed node.

Returns:

  • (Boolean)

    always ‘true` for a compressed node.



31
32
33
# File 'lib/rambling/trie/nodes/compressed.rb', line 31

def compressed?
  true
end