Class: Dawg::MemoryNode

Inherits:
Object
  • Object
show all
Defined in:
lib/dawg/node/memory_node.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(io, index, edge_count, final, hash, edges_pos) ⇒ MemoryNode

Returns a new instance of MemoryNode.



4
5
6
7
8
9
10
11
# File 'lib/dawg/node/memory_node.rb', line 4

def initialize(io, index , edge_count , final, hash, edges_pos )
  @io = io
  @index = index
  @edge_count = edge_count
  @final = final
  @hash = hash
  @edges_pos = edges_pos
end

Instance Attribute Details

#edge_countObject

Returns the value of attribute edge_count.



3
4
5
# File 'lib/dawg/node/memory_node.rb', line 3

def edge_count
  @edge_count
end

#edges_posObject

Returns the value of attribute edges_pos.



3
4
5
# File 'lib/dawg/node/memory_node.rb', line 3

def edges_pos
  @edges_pos
end

#finalObject

Returns the value of attribute final.



3
4
5
# File 'lib/dawg/node/memory_node.rb', line 3

def final
  @final
end

#hashObject

Returns the value of attribute hash.



3
4
5
# File 'lib/dawg/node/memory_node.rb', line 3

def hash
  @hash
end

#indexObject

Returns the value of attribute index.



3
4
5
# File 'lib/dawg/node/memory_node.rb', line 3

def index
  @index
end

#ioObject

Returns the value of attribute io.



3
4
5
# File 'lib/dawg/node/memory_node.rb', line 3

def io
  @io
end

Instance Method Details

#[](letter) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/dawg/node/memory_node.rb', line 13

def [](letter)
  @io.each_edge @index do |char, node_index|
    if letter == char
      return @io.get_node_by_index(node_index)
    end
  end

  nil
end

#each_edge(&block) ⇒ Object



23
24
25
26
27
28
# File 'lib/dawg/node/memory_node.rb', line 23

def each_edge(&block)
  @io.each_edge @index do |char, node_index|
    yield char
  end

end