Class: RGL::Edge::DirectedEdge

### Home Classes Methods

### In Files

- lib/rgl/base.rb

### Parent

Object

### Methods

- ::[]
- ::new
- #<=>
- #==
- #[]
- #eql?
- #hash
- #reverse
- #to_a
- #to_s

### Class/Module Index

Quicksearch

- RGL
- RGL::AdjacencyGraph
- RGL::BFSIterator
- RGL::BellmanFordAlgorithm
- RGL::BellmanFordVisitor
- RGL::BidirectionalGraph
- RGL::BipartiteBFSIterator
- RGL::DFSIterator
- RGL::DFSVisitor
- RGL::DOT
- RGL::DOT::Digraph
- RGL::DOT::DirectedEdge
- RGL::DOT::Edge
- RGL::DOT::Element
- RGL::DOT::Graph
- RGL::DOT::Node
- RGL::DOT::Port
- RGL::DOT::Subgraph
- RGL::DijkstraAlgorithm
- RGL::DijkstraVisitor
- RGL::DirectedAdjacencyGraph
- RGL::Edge
- RGL::Edge::DirectedEdge
- RGL::Edge::UnDirectedEdge
- RGL::EdgePropertiesMap
- RGL::EdmondsKarpAlgorithm
- RGL::EdmondsKarpAlgorithm::EdmondsKarpBFSIterator
- RGL::Graph
- RGL::Graph::TarjanSccVisitor
- RGL::GraphIterator
- RGL::GraphVisitor
- RGL::GraphVisitor::ClassMethods
- RGL::GraphVisitor::DistanceMapSupport
- RGL::ImplicitGraph
- RGL::MutableGraph
- RGL::MutableGraph::MutableGraphParser
- RGL::NoEdgeError
- RGL::NoVertexError
- RGL::NonNegativeEdgePropertiesMap
- RGL::NotDirectedError
- RGL::NotUndirectedError
- RGL::PrimAlgorithm
- RGL::TopsortIterator
- Enumerable
- Object

No matching classes.

# RGL::Edge::DirectedEdge

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 DirectedEdge or UnDirectedEdge instances are returned (i.e. Graph#edges).

### Attributes

source[RW]
target[RW]

### Public Class Methods

[](*a) click to toggle source

Can be used to create an edge from a two element array.

    # File lib/rgl/base.rb, line 38
    def self.[](*a)
      new(a[0], a[1])
    end

new(a, b) click to toggle source

Create a new DirectedEdge with source a and target b.

    # File lib/rgl/base.rb, line 44
    def initialize(a, b)
      @source, @target = a, b
    end

### Public Instance Methods

<=>(e) click to toggle source

Sort support is dispatched to the <=> method of Array

    # File lib/rgl/base.rb, line 88
    def <=> e
      self.to_a <=> e.to_a
    end

==(edge) click to toggle source
Alias for: eql?
[](index) click to toggle source

Edges can be indexed. edge == edge.source, edge == edge.target for all n>0. Edges can thus be used as a two element array.

    # File lib/rgl/base.rb, line 70
    def [](index)
      index.zero? ? source : target
    end

eql?(edge) click to toggle source

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, line 51
    def eql?(edge)
      (source == edge.source) && (target == edge.target)
    end

Also aliased as: ==
hash() click to toggle source

    # File lib/rgl/base.rb, line 57
    def hash
      source.hash ^ target.hash
    end

reverse() click to toggle source

Returns (v,u) if self == (u,v).

    # File lib/rgl/base.rb, line 63
    def reverse
      self.class.new(target, source)
    end

to_a() click to toggle source

Returns the array [source,target].

    # File lib/rgl/base.rb, line 82
    def to_a
      [source, target]
    end

to_s() click to toggle source

DirectedEdge.to_s == "(1-2)"

    # File lib/rgl/base.rb, line 76
    def to_s
      "(#{source}-#{target})"
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.