Class: DS::GraphAsTriMatrix

Inherits:
GraphAsMatrix show all
Defined in:
lib/ds/graphs/graph_as_tri_matrix.rb

Instance Method Summary collapse

Methods inherited from GraphAsMatrix

#add_edges, #each_edge, #each_vertex, #edge?, #get_edge, #neighbors, #remove, #vertex_size, #vmax

Constructor Details

#initialize(edges) ⇒ GraphAsTriMatrix

Returns a new instance of GraphAsTriMatrix.



4
5
6
7
8
9
10
11
# File 'lib/ds/graphs/graph_as_tri_matrix.rb', line 4

def initialize(edges)
  @store = TriMatrix.new(0)
  @max = 0
  @map = []
  @v = 0

  add_edges(edges)
end

Instance Method Details

#degree(x) ⇒ Object

Returns vertex degree.



14
15
16
17
18
19
20
21
# File 'lib/ds/graphs/graph_as_tri_matrix.rb', line 14

def degree(x)
  x = @map.index(x)
  sum = 0
  0.upto @max do |i|
    sum += @store[x,i] if @store[x,i] 
  end
  sum
end