java.lang.Object
org.jhotdraw8.graph.SimpleMutableBidiGraph<V,A>
- Type Parameters:
V- the vertex data typeA- 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>
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.
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
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new instance.SimpleMutableBidiGraph(int initialVertexCapacity, int initialArrowCapacity) Creates a new instance.Creates a new instance with a copy of the provided graph -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds an arrow from vertex v to vertex u.voidAdds a vertex to the graph if it is not already in the graph.intReturns the number of arrows.Returns the next vertex associated with the specified vertex and outgoing arrow index.getNextArrow(@NonNull V v, int index) Returns the arrow data associated with the specified vertex and outgoing arrow index.intReturns the number of next vertices at the specified vertex.Returns the previous vertex associated with the specified vertex and incoming arrow index.getPrevArrow(@NonNull V vertex, int index) Returns the arrow data associated with the specified vertex and the specified incoming arrow index.intgetPrevCount(@NonNull V vertex) Returns the number of previous vertices at the specified vertex.getVertex(int index) Gets the vertex data at the specified index.intReturns the number of vertices.Returns all vertices.voidremoveArrow(@NonNull V v, @NonNull V u) Removes the first arrow from vertex v to vertex u.voidRemoves the first arrow from vertex v to vertex u that has the same data value.voidremoveNext(@NonNull V v, int k) Removes the k-th next arrow from vertex v.voidRemoves a vertex from the graph if it is in the graph.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.jhotdraw8.graph.BidiGraph
findIndexOfPrev, getPrevArc, getPrevArcs, getPrevArrows, getPrevVertices, isPrev, searchPrevVertices, searchPrevVerticesMethods inherited from interface org.jhotdraw8.graph.DirectedGraph
findArrow, findIndexOfNext, getArrows, getArrows, getNextArc, getNextArcs, getNextArrows, getNextVertices, isNext, searchNextVertices, searchNextVerticesMethods inherited from interface org.jhotdraw8.graph.MutableBidiGraph
addBidiArrow
-
Constructor Details
-
SimpleMutableBidiGraph
public SimpleMutableBidiGraph()Creates a new instance. -
SimpleMutableBidiGraph
public SimpleMutableBidiGraph(int initialVertexCapacity, int initialArrowCapacity) Creates a new instance.- Parameters:
initialVertexCapacity- the initial vertex capacityinitialArrowCapacity- the initial arrow capacity (ignored)
-
SimpleMutableBidiGraph
Creates a new instance with a copy of the provided graph- Parameters:
g- a graph
-
-
Method Details
-
addVertex
Description copied from interface:MutableDirectedGraphAdds a vertex to the graph if it is not already in the graph.- Specified by:
addVertexin interfaceMutableDirectedGraph<V,A> - Parameters:
v- vertex data
-
removeVertex
Description copied from interface:MutableDirectedGraphRemoves a vertex from the graph if it is in the graph.- Specified by:
removeVertexin interfaceMutableDirectedGraph<V,A> - Parameters:
v- vertex data
-
addArrow
Description copied from interface:MutableDirectedGraphAdds an arrow from vertex v to vertex u.This method adds additional an arrow if the arrow is already in the graph.
- Specified by:
addArrowin interfaceMutableDirectedGraph<V,A> - Parameters:
v- vertex data vu- vertex data ua- arrow data
-
removeArrow
Description copied from interface:MutableDirectedGraphRemoves the first arrow from vertex v to vertex u that has the same data value.- Specified by:
removeArrowin interfaceMutableDirectedGraph<V,A> - Parameters:
v- vertex data vu- vertex data ua- arrow data
-
removeArrow
Description copied from interface:MutableDirectedGraphRemoves the first arrow from vertex v to vertex u.- Specified by:
removeArrowin interfaceMutableDirectedGraph<V,A> - Parameters:
v- vertex data vu- vertex data u
-
removeNext
Description copied from interface:MutableDirectedGraphRemoves the k-th next arrow from vertex v.- Specified by:
removeNextin interfaceMutableDirectedGraph<V,A> - Parameters:
v- vertex data vk- index of arrow to be removed
-
getNext
Description copied from interface:BareDirectedVertexGraphReturns the next vertex associated with the specified vertex and outgoing arrow index.- Specified by:
getNextin interfaceBareDirectedVertexGraph<V>- Parameters:
v- a vertexindex- index of outgoing arrow- Returns:
- the next vertex
- See Also:
-
getNextArrow
Description copied from interface:BareDirectedGraphReturns the arrow data associated with the specified vertex and outgoing arrow index.- Specified by:
getNextArrowin interfaceBareDirectedGraph<V,A> - Parameters:
v- a vertexindex- index of outgoing arrow- Returns:
- the next arrow data
- See Also:
-
getNextCount
Description copied from interface:BareDirectedVertexGraphReturns the number of next vertices at the specified vertex.This number is the same as the number of outgoing arrows at the specified vertex.
- Specified by:
getNextCountin interfaceBareDirectedVertexGraph<V>- Parameters:
v- a vertex- Returns:
- the number of next vertices
-
getVertex
Description copied from interface:DirectedGraphGets the vertex data at the specified index.- Specified by:
getVertexin interfaceDirectedGraph<V,A> - Parameters:
index- an index- Returns:
- vertex data
-
getVertices
Description copied from interface:BareDirectedVertexGraphReturns all vertices.- Specified by:
getVerticesin interfaceBareDirectedVertexGraph<V>- Returns:
- a set view on all vertices
-
getVertexCount
public int getVertexCount()Description copied from interface:DirectedGraphReturns the number of vertices.- Specified by:
getVertexCountin interfaceDirectedGraph<V,A> - Returns:
- vertex count
-
getArrowCount
public int getArrowCount()Description copied from interface:DirectedGraphReturns the number of arrows.- Specified by:
getArrowCountin interfaceDirectedGraph<V,A> - Returns:
- arrow count
-
getPrev
Description copied from interface:BareBidiGraphReturns the previous vertex associated with the specified vertex and incoming arrow index.- Specified by:
getPrevin interfaceBareBidiGraph<V,A> - Parameters:
vertex- a vertexindex- index of incoming arrow- Returns:
- the previous vertex
- See Also:
-
getPrevArrow
Description copied from interface:BareBidiGraphReturns the arrow data associated with the specified vertex and the specified incoming arrow index.- Specified by:
getPrevArrowin interfaceBareBidiGraph<V,A> - Parameters:
vertex- a vertexindex- index of incoming arrow- Returns:
- the arrow
- See Also:
-
getPrevCount
Description copied from interface:BareBidiGraphReturns the number of previous vertices at the specified vertex.This number is the same as the number of incoming arrows at the specified vertex.
- Specified by:
getPrevCountin interfaceBareBidiGraph<V,A> - Parameters:
vertex- a vertex- Returns:
- the number of previous vertices
-