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 each_edge). If a client wants to store edges explicitly DirecteEdge or UnDirectedEdge instances are returned (i.e. Graph#edges).
| [RW] | source | |
| [RW] | target |
Can be used to create an edge from a two element array.
[ show source ]
# File lib/rgl/base.rb, line 30
30: def self.[](*a)
31: new(a[0],a[1])
32: end
Create a new DirectedEdge with source a and target b.
[ show source ]
# File lib/rgl/base.rb, line 35
35: def initialize (a,b)
36: @source, @target = a,b
37: end
Sort support is dispatched to the <=> method of Array
[ show source ]
# File lib/rgl/base.rb, line 63
63: def <=> e
64: self.to_a <=> e.to_a
65: end
Edges can be indexed. edge[0] == edge.source, edge[n] == edge.target for all n>0. Edges can thus be used as a two element array.
[ show source ]
# File lib/rgl/base.rb, line 53
53: def [](index); index.zero? ? source : target; 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 ==.
[ show source ]
# File lib/rgl/base.rb, line 41
41: def eql?(edge)
42: source == edge.source and target == edge.target
43: end
Returns (v,u) if self == (u,v).
[ show source ]
# File lib/rgl/base.rb, line 47
47: def reverse
48: self.class.new(target, source)
49: end
Returns the array [source,target].
[ show source ]
# File lib/rgl/base.rb, line 60
60: def to_a; [source,target]; end
DirectedEdge[1,2].to_s == "(1-2)"
[ show source ]
# File lib/rgl/base.rb, line 56
56: def to_s
57: "(#{source}-#{target})"
58: end