java.lang.Object
org.jhotdraw8.graph.AbstractDirectedGraphBuilder
org.jhotdraw8.graph.SimpleMutableDirectedGraph<V,A>
- Type Parameters:
V- the vertex data typeA- the arrow data type
- All Implemented Interfaces:
AttributedIndexedDirectedGraph<V,,A> BareDirectedGraph<V,,A> BareDirectedVertexGraph<V>,DirectedGraph<V,,A> IndexedDirectedGraph,MutableDirectedGraph<V,A>
public class SimpleMutableDirectedGraph<V,A>
extends AbstractDirectedGraphBuilder
implements MutableDirectedGraph<V,A>, AttributedIndexedDirectedGraph<V,A>
SimpleMutableDirectedGraph.
- Author:
- Werner Randelshofer
-
Field Summary
Fields inherited from class org.jhotdraw8.graph.AbstractDirectedGraphBuilder
arrowCountIncludingDeletedArrows, ARROWS_NEXT_FIELD, ARROWS_NUM_FIELDS, ARROWS_VERTEX_FIELD, LASTARROW_COUNT_FIELD, LASTARROW_NUM_FIELDS, LASTARROW_POINTER_FIELD, SENTINEL -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new instance with an initial capacity for 16 vertices and 16 arrows.SimpleMutableDirectedGraph(int vertexCapacity, int arrowCapacity) Creates a new instance with the specified initial capacities.SimpleMutableDirectedGraph(int vertexCapacity, int arrowCapacity, boolean identityMap) Creates a new instance with the specified initial capacities.Creates a new instance which contains a copy of the specified graph.SimpleMutableDirectedGraph(@NonNull DirectedGraph<VV, AA> graph, @NonNull Function<VV, V> vertexMapper, @NonNull Function3<VV, VV, AA, A> arrowMapper) Creates a new instance which contains a copy of the specified graph. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a directed arrow from va to vb.voidAdds an arrow from 'va' to 'vb' and an arrow from 'vb' to 'va'.voidAdds a vertex.voidAdds a vertex at the specified index.voidclear()getArrow(int index) Returns the data of the specified arrow.Returns the next vertex associated with the specified vertex and outgoing arrow index.getNextArrow(int v, int index) Returns the specified successor (next) arrow of the specified vertex.getNextArrow(@NonNull V v, int index) Returns the arrow data associated with the specified vertex and outgoing arrow index.intgetNextArrowAsInt(int v, int i) Returns thei-th next arrow ofv.intReturns the number of next vertices at the specified vertex.getVertex(int vi) Gets the vertex data at the specified index.intgetVertexIndex(V v) Returns the index of the vertex.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 org.jhotdraw8.graph.AbstractDirectedGraphBuilder
buildAddArrow, buildAddVertex, buildInsertVertexAt, buildRemoveArrowAt, buildRemoveArrowAt, buildRemoveVertex, buildRemoveVertexAfterArrowsHaveBeenRemoved, doAddArrow, getArrowCount, getArrowIndex, getNextArrowIndex, getNextAsInt, getNextCount, getNextVerticesOrdered, getNextVerticesUnordered, getVertexCount, isOrdered, nextVerticesEnumerator, setOrderedMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.jhotdraw8.graph.AttributedIndexedDirectedGraph
getNextIntEntriesMethods inherited from interface org.jhotdraw8.graph.DirectedGraph
findArrow, findIndexOfNext, getArrowCount, getArrows, getArrows, getNextArc, getNextArcs, getNextArrows, getNextVertices, getVertexCount, isNext, searchNextVertices, searchNextVerticesMethods inherited from interface org.jhotdraw8.graph.IndexedDirectedGraph
findIndexOfNextAsInt, getArrowCount, getNextAsInt, getNextCount, getVertexCount, isNextAsInt, nextVerticesEnumerator
-
Constructor Details
-
SimpleMutableDirectedGraph
public SimpleMutableDirectedGraph()Creates a new instance with an initial capacity for 16 vertices and 16 arrows.Uses a non-identity hash map for storing the vertices.
-
SimpleMutableDirectedGraph
public SimpleMutableDirectedGraph(int vertexCapacity, int arrowCapacity) Creates a new instance with the specified initial capacities.Uses a non-identity hash map for storing the vertices.
- Parameters:
vertexCapacity- the initial capacity for verticesarrowCapacity- the initial capacity for arrows
-
SimpleMutableDirectedGraph
public SimpleMutableDirectedGraph(int vertexCapacity, int arrowCapacity, boolean identityMap) Creates a new instance with the specified initial capacities.- Parameters:
vertexCapacity- the initial capacity for verticesarrowCapacity- the initial capacity for arrowsidentityMap- whether to use an identity hash map for storing the vertices
-
SimpleMutableDirectedGraph
Creates a new instance which contains a copy of the specified graph.- Parameters:
graph- a graph
-
SimpleMutableDirectedGraph
public SimpleMutableDirectedGraph(@NonNull DirectedGraph<VV, AA> graph, @NonNull Function<VV, V> vertexMapper, @NonNull Function3<VV, VV, AA, A> arrowMapper) Creates a new instance which contains a copy of the specified graph.Uses a non-identity hash map for storing the vertices.
- Type Parameters:
VV- the vertex data type of the graphAA- the arrow data type of the graph- Parameters:
graph- a graphvertexMapper- a mapping function for the verticesarrowMapper- a mapping function for the arrows
-
-
Method Details
-
addArrow
Adds a directed arrow from va to vb.- Specified by:
addArrowin interfaceMutableDirectedGraph<V,A> - Parameters:
va- vertex avb- vertex barrow- the arrow
-
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
-
addBidiArrow
Adds an arrow from 'va' to 'vb' and an arrow from 'vb' to 'va'.- Parameters:
va- vertex avb- vertex barrow- the arrow
-
addVertex
Adds a vertex.- Specified by:
addVertexin interfaceMutableDirectedGraph<V,A> - Parameters:
v- vertex
-
addVertex
Adds a vertex at the specified index.- Parameters:
v- vertexvidx- vertex index
-
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
-
clear
public void clear()- Overrides:
clearin classAbstractDirectedGraphBuilder
-
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:
-
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 vertexi- index of outgoing arrow- Returns:
- the next vertex
- 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 interfaceAttributedIndexedDirectedGraph<V,A> - Specified by:
getVertexin interfaceDirectedGraph<V,A> - Parameters:
vi- an index- Returns:
- vertex data
-
getVertexIndex
Description copied from interface:AttributedIndexedDirectedGraphReturns the index of the vertex.- Specified by:
getVertexIndexin interfaceAttributedIndexedDirectedGraph<V,A> - Parameters:
v- a vertex- Returns:
- index of vertex
-
getArrow
Description copied from interface:AttributedIndexedDirectedGraphReturns the data of the specified arrow.- Specified by:
getArrowin interfaceAttributedIndexedDirectedGraph<V,A> - Parameters:
index- index of arrow- Returns:
- arrow data
-
getNextArrow
Description copied from interface:AttributedIndexedDirectedGraphReturns the specified successor (next) arrow of the specified vertex.- Specified by:
getNextArrowin interfaceAttributedIndexedDirectedGraph<V,A> - Parameters:
v- a vertexindex- index of next arrow- Returns:
- the specified arrow
-
getNextArrowAsInt
public int getNextArrowAsInt(int v, int i) Description copied from interface:IndexedDirectedGraphReturns thei-th next arrow ofv.- Specified by:
getNextArrowAsIntin interfaceIndexedDirectedGraph- Parameters:
v- a vertex indexi- the index of the desired arrow,i ∈ {0, ..., getNextCount(v) -1 }.- Returns:
- the arrow data of the i-th next vertex of v.
-
getVertices
Description copied from interface:BareDirectedVertexGraphReturns all vertices.- Specified by:
getVerticesin interfaceBareDirectedVertexGraph<V>- Returns:
- a set view on all vertices
-