Class: RGL::Edge::DirectedEdge
- Inherits:
-
Object
- Object
- RGL::Edge::DirectedEdge
- Defined in:
- lib/rgl/base.rb
Overview
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).
Direct Known Subclasses
Instance Attribute Summary collapse
-
#source ⇒ Object
Returns the value of attribute source.
-
#target ⇒ Object
Returns the value of attribute target.
Class Method Summary collapse
-
.[](*a) ⇒ Object
Can be used to create an edge from a two element array.
Instance Method Summary collapse
-
#<=>(e) ⇒ Object
Sort support is dispatched to the <=> method of Array.
-
#[](index) ⇒ Object
Edges can be indexed.
-
#eql?(edge) ⇒ Boolean
(also: #==)
Two directed edges (u,v) and (x,y) are equal iff u == x and v == y.
-
#initialize(a, b) ⇒ DirectedEdge
constructor
Create a new DirectedEdge with source a and target b.
-
#reverse ⇒ Object
Returns (v,u) if self == (u,v).
-
#to_a ⇒ Object
Returns the array [source,target].
-
#to_s ⇒ Object
DirectedEdge.to_s == “(1-2)”.
Constructor Details
#initialize(a, b) ⇒ DirectedEdge
Create a new DirectedEdge with source a and target b.
35 36 37 |
# File 'lib/rgl/base.rb', line 35 def initialize (a,b) @source, @target = a,b end |
Instance Attribute Details
#source ⇒ Object
Returns the value of attribute source.
27 28 29 |
# File 'lib/rgl/base.rb', line 27 def source @source end |
#target ⇒ Object
Returns the value of attribute target.
27 28 29 |
# File 'lib/rgl/base.rb', line 27 def target @target end |
Class Method Details
.[](*a) ⇒ Object
Can be used to create an edge from a two element array.
30 31 32 |
# File 'lib/rgl/base.rb', line 30 def self.[](*a) new(a[0],a[1]) end |
Instance Method Details
#<=>(e) ⇒ Object
Sort support is dispatched to the <=> method of Array
63 64 65 |
# File 'lib/rgl/base.rb', line 63 def <=> e self.to_a <=> e.to_a end |
#[](index) ⇒ Object
53 |
# File 'lib/rgl/base.rb', line 53 def [](index); index.zero? ? source : target; end |
#eql?(edge) ⇒ Boolean Also known as: ==
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 ==.
41 42 43 |
# File 'lib/rgl/base.rb', line 41 def eql?(edge) source == edge.source and target == edge.target end |
#reverse ⇒ Object
Returns (v,u) if self == (u,v).
47 48 49 |
# File 'lib/rgl/base.rb', line 47 def reverse self.class.new(target, source) end |
#to_a ⇒ Object
Returns the array [source,target].
60 |
# File 'lib/rgl/base.rb', line 60 def to_a; [source,target]; end |
#to_s ⇒ Object
DirectedEdge.to_s == “(1-2)”
56 57 58 |
# File 'lib/rgl/base.rb', line 56 def to_s "(#{source}-#{target})" end |