class RGL::Edge::DirectedEdge
An {Edge} is simply a directed pair +(source -> target)+. Most library functions try do omit to instantiate edges. They instead use two vertex parameters for representing edges (see {Graph#each_edge}). If a client wants to store edges explicitly {DirectedEdge} or {UnDirectedEdge} instances are returned (i.e. {Graph#edges}).
Attributes
Public Class Methods
Can be used to create an edge from a two element array.
# File lib/rgl/base.rb 39 def self.[](*a) 40 new(a[0], a[1]) 41 end
Create a new DirectedEdge
with source a
and target b
.
# File lib/rgl/base.rb 45 def initialize(a, b) 46 @source, @target = a, b 47 end
Public Instance Methods
Sort support is dispatched to the <=> method of Array
# File lib/rgl/base.rb 93 def <=> e 94 self.to_a <=> e.to_a 95 end
Edges can be indexed. +edge.at(0) == edge.source+, +edge.at(n) == edge.target+ for all +n>0+. Edges can thus be used as a two element array.
# File lib/rgl/base.rb 70 def [](index) 71 index.zero? ? source : target 72 end
Two directed edges (u,v) and (x,y) are equal iff u == x and v == y. eql?
is needed when edges are inserted into a Set
. eql?
is aliased to +==+.
# File lib/rgl/base.rb 51 def eql?(edge) 52 (source == edge.source) && (target == edge.target) 53 end
# File lib/rgl/base.rb 57 def hash 58 source.hash ^ target.hash 59 end
Returns (v,u) if self == (u,v). @return [Edge]
# File lib/rgl/base.rb 63 def reverse 64 self.class.new(target, source) 65 end
Returns the array [source,target]. @return [Array]
# File lib/rgl/base.rb 87 def to_a 88 [source, target] 89 end
Returns string representation of the edge @example
DirectedEdge[1,2].to_s == "(1-2)"
@return [String]
# File lib/rgl/base.rb 78 def to_s 79 "(#{source}-#{target})" 80 end