Class: GADDAG::Arc

Inherits:
Object
  • Object
show all
Defined in:
lib/gaddag/arc.rb

Overview

Represents an arc pointing to a destination node with optional final letters

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(destination) ⇒ Arc

Initializes a GADDAG arc

Parameters:

  • destination (Node)

    the destination node



22
23
24
25
# File 'lib/gaddag/arc.rb', line 22

def initialize(destination)
  @destination = destination
  @final_letters = Set.new
end

Instance Attribute Details

#destinationObject (readonly)

The destination node



10
11
12
# File 'lib/gaddag/arc.rb', line 10

def destination
  @destination
end

#final_lettersObject (readonly)

A set of letters which form a word after being appended to the letter path



13
14
15
# File 'lib/gaddag/arc.rb', line 13

def final_letters
  @final_letters
end

Instance Method Details

#add_final_letter(letter) ⇒ Object

Adds a final letter to the arc. A final letter is a letter that, when appended to the letter path, forms a valid word.

Parameters:

  • letter (String)

    the letter that is to be marked as final



30
31
32
# File 'lib/gaddag/arc.rb', line 30

def add_final_letter(letter)
  @final_letters.add(letter)
end

#final_pathsArray<Path>

Returns all paths starting at this arc that are final

Returns:

  • (Array<Path>)

    a list of final paths that start at this arc



36
37
38
# File 'lib/gaddag/arc.rb', line 36

def final_paths
  final_letters.map { |fl| Path.new([fl]) } + destination.final_paths
end