Class SimpleMutableBidiGraph<V,A>

java.lang.Object
org.jhotdraw8.graph.SimpleMutableBidiGraph<V,A>
Type Parameters:
V - the vertex data type
A - the arrow data type
All Implemented Interfaces:
BareBidiGraph<V,A>, BareDirectedGraph<V,A>, BareDirectedVertexGraph<V>, BidiGraph<V,A>, DirectedGraph<V,A>, MutableBidiGraph<V,A>, MutableDirectedGraph<V,A>

public class SimpleMutableBidiGraph<V,A> extends Object implements MutableBidiGraph<V,A>
A mutable bidi graph with balanced performance for all operations.
  • Insertion of a vertex is done in amortized O(1).
  • Insertion of an arrow is done in amortized O(1).
  • Removal of a vertex is done in amortized O(|A'|), where |A'| is the number of ingoing and outgoing arrows of the vertex.
  • Removal of an arrow is done in amortized O(|A'|), where |A'| is the number of ingoing and outgoing arrows of the involved vertices.
Memory locality is poor. If you need to perform query operations on the graph, then an immutable graph will give you better performance.

Implementation:

Example graph:

     0 ──→ 1 ──→ 2
     │     │
     ↓     ↓
     3 ←── 4
 
If the graph is inserted in the following sequence into the builder:
     addVertex(0);
     addVertex(1);
     addVertex(2);
     addVertex(3);
     addVertex(4);
     addArrow(0, 1);
     addArrow(0, 3);
     addArrow(1, 2);
     addArrow(1, 4);
     addArrow(4, 3);
 
Then the internal representation is as follows:
 vertex#  next- and prev-arrows

    0:    next={1, 3};  prev={}
    1:    next={2, 4};  prev={0}
    2:    next={};      prev={1}
    3:    next={};      prev={0, 4}
    4:    next={3};     prev={1}
 
Author:
Werner Randelshofer