class TSS::Vertex

Trie vertex class

Attributes

char[RW]

Letter representing this vertex

children[R]

Array of children TSS::Vertex references for nested models(full trie, Aho-Corasick trie) or as list of nested vertexes of root vertex of flat trie

end_indexes[RW]

Array of indexes of word in dictionary Empty if it is intermediate TSS::Vertex in chain

parent[RW]

Reference to the parent TSS::Vertex

root[RW]

Reference to the root vertex of the trie

Public Class Methods

new(parent = nil) { |self| ... } click to toggle source

Initializes new vertex

Example:

>> TSS::Vertex.new(@root_vertex)
>> TSS::Vertex.new(@root_vertex)

Optional arguments:

parent: (TSS::Vertex)
# File lib/tss/vertex.rb, line 35
def initialize(parent = nil)
  @char = nil
  @parent = parent
  @children = []
  @links = []
  @end_indexes = []
  yield(self) if block_given?
end

Public Instance Methods

add_child(char, end_index) click to toggle source

Initializes new TSS::Vertex and adds it to the parent attribute

# File lib/tss/vertex.rb, line 46
def add_child(char, end_index)
  child = get_child(char)
  if child
    child.end_indexes << end_index unless end_index.nil?
    child
  else
    init_subchild(char, end_index)
  end
end
children_chars() click to toggle source

Returns array of characters from array of children TSS::Vertex

# File lib/tss/vertex.rb, line 76
def children_chars
  @children.map(&:char)
end
get_child(char) click to toggle source

Returns child TSS::Vertex by letter, from children attribute

# File lib/tss/vertex.rb, line 58
def get_child(char)
  @children.find { |c| c.char == char }
end
vertex() click to toggle source
# File lib/tss/vertex.rb, line 80
def vertex
  self
end

Private Instance Methods

init_subchild(char, end_index) click to toggle source
# File lib/tss/vertex.rb, line 86
def init_subchild(char, end_index)
  child = self.class.new(self)
  child.char = char
  child.root = @root
  child.end_indexes << end_index unless end_index.nil?
  @children << child
  child
end