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
Source
# File lib/rgl/base.rb 39 def self.[](*a) 40 new(a[0], a[1]) 41 end
Can be used to create an edge from a two element array.
Source
# File lib/rgl/base.rb 45 def initialize(a, b) 46 @source, @target = a, b 47 end
Create a new DirectedEdge
with source a
and target b
.
Public Instance Methods
Source
# File lib/rgl/base.rb 93 def <=> e 94 self.to_a <=> e.to_a 95 end
Sort support is dispatched to the <=> method of Array
Source
# File lib/rgl/base.rb 70 def [](index) 71 index.zero? ? source : target 72 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.
Source
# File lib/rgl/base.rb 51 def eql?(edge) 52 (source == edge.source) && (target == edge.target) 53 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 +==+.
Source
# File lib/rgl/base.rb 63 def reverse 64 self.class.new(target, source) 65 end
Returns (v,u) if self == (u,v). @return [Edge]
Source
# File lib/rgl/base.rb 87 def to_a 88 [source, target] 89 end
Returns the array [source,target]. @return [Array]