Class: Knossos::Solver::Distances

Inherits:
Object
  • Object
show all
Defined in:
lib/knossos/solver/distances.rb

Instance Method Summary collapse

Constructor Details

#initialize(root:) ⇒ Distances

Returns a new instance of Distances.



4
5
6
7
8
# File 'lib/knossos/solver/distances.rb', line 4

def initialize(root:)
  @root = root
  @cells = {}
  @cells[@root] = 0
end

Instance Method Details

#[](cell) ⇒ Object



10
11
12
# File 'lib/knossos/solver/distances.rb', line 10

def [](cell)
  @cells[cell]
end

#[]=(cell, distance) ⇒ Object



14
15
16
# File 'lib/knossos/solver/distances.rb', line 14

def []=(cell, distance)
  @cells[cell] = distance
end

#cellsObject



18
19
20
# File 'lib/knossos/solver/distances.rb', line 18

def cells
  @cells.keys
end

#maxObject



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/knossos/solver/distances.rb', line 22

def max
  max_distance = 0
  max_cell = @root

  @cells.each do |cell, distance|
    if distance > max_distance
      max_cell = cell
      max_distance = distance
    end
  end

  [max_cell, max_distance]
end