Class: GRATR::Edge

Inherits:
Arc
  • Object
show all
Defined in:
lib/gratr/edge.rb

Overview

An undirected edge is simply an undirected pair (source, target) used in undirected graphs. Edge == Edge

Direct Known Subclasses

MultiEdge

Instance Method Summary collapse

Methods inherited from Arc

[], #initialize, #inspect, #reverse

Constructor Details

This class inherits a constructor from GRATR::Arc

Instance Method Details

#<=>(rhs) ⇒ Object

Sort support



93
94
95
96
# File 'lib/gratr/edge.rb', line 93

def <=>(rhs)
  [[source,target].max,[source,target].min] <=> 
  [[rhs.source,rhs.target].max,[rhs.source,rhs.target].min]
end

#eql?(other) ⇒ Boolean Also known as: ==

Equality allows for the swapping of source and target

Returns:

  • (Boolean)


81
# File 'lib/gratr/edge.rb', line 81

def eql?(other) super or (self.class == other.class and target==other.source and source==other.target); end

#hashObject

Hash is defined such that source and target can be reversed and the hash value will be the same

This will cause problems with self loops



90
# File 'lib/gratr/edge.rb', line 90

def hash() source.hash ^ target.hash; end

#to_sObject

Edge.to_s == “(1=2 ‘label)”



99
100
101
102
103
104
# File 'lib/gratr/edge.rb', line 99

def to_s
  l = label ? " '#{label.to_s}'" : ''
  s = source.to_s
  t = target.to_s
  "(#{[s,t].min}=#{[s,t].max}#{l})"
end