Class: Graphsrb::Node

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

Overview

This class represents a single entry in a adjacency list.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(vertex_id, args = {}) ⇒ Node

Creates a new node



7
8
9
10
# File 'lib/graphsrb/node.rb', line 7

def initialize(vertex_id, args={})
  @vertex = Graphsrb::Vertex.new(vertex_id)
  @weight = args.fetch(:weight, 1)
end

Instance Attribute Details

#vertexObject (readonly)

Returns the value of attribute vertex.



4
5
6
# File 'lib/graphsrb/node.rb', line 4

def vertex
  @vertex
end

#weightObject (readonly)

Returns the value of attribute weight.



4
5
6
# File 'lib/graphsrb/node.rb', line 4

def weight
  @weight
end

Instance Method Details

#==(node) ⇒ Object

Compares two nodes. Two nodes are equal if their vertices are equal.



18
19
20
# File 'lib/graphsrb/node.rb', line 18

def ==(node)
  vertex == node.vertex
end

#update_weight(w) ⇒ Object

Updates weight



13
14
15
# File 'lib/graphsrb/node.rb', line 13

def update_weight(w)
  @weight = w
end