Module org.jhotdraw8.graph
Package org.jhotdraw8.graph
Class MutableIntAttributed16BitIndexedBidiGraph
java.lang.Object
org.jhotdraw8.graph.MutableIntAttributed16BitIndexedBidiGraph
- All Implemented Interfaces:
IndexedBidiGraph,IndexedDirectedGraph,IntAttributedIndexedBidiGraph,IntAttributedIndexedDirectedGraph,MutableIndexedBidiGraph
public class MutableIntAttributed16BitIndexedBidiGraph
extends Object
implements MutableIndexedBidiGraph, IntAttributedIndexedBidiGraph
A mutable indexed bi-directional graph.
Supports up to 2^16 - 1 vertices.
This implementation uses large contiguous arrays. Each row occupies
maxArity + 1 elements in the array for the arrows.
If the arity of the vertices is unevenly distributed, a dfs- or bfs-search is likely to encounter a different cash line or page for every vertex.
XXX delete me, this representation is inefficient
-
Constructor Summary
ConstructorsConstructorDescriptionMutableIntAttributed16BitIndexedBidiGraph(int vertexCapacity, int maxArity) Creates a new instance. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddArrowAsInt(int v, int u) Adds an arrow from vertex 'v' to vertex 'u' with arrow data 0.voidaddArrowAsInt(int v, int u, int arrowData) Adds an arrow from vertex 'v' to vertex 'u'.voidAdds a vertex to the graph.voidaddVertexAsInt(int v) Adds a vertex at the specified index to the graph.voidclear()Removes all vertices and all arrows.intfindIndexOfNextAsInt(int v, int u) Returns the index of vertex b.intfindIndexOfPrevAsInt(int v, int u) Returns the index of the arrow fromvtouin the list of next-vertices fromv.intReturns the number of arrows.intgetNextArrowAsInt(int v, int i) Returns thei-th next arrow ofv.intgetNextAsInt(int v, int i) Returns thei-th next vertex ofv.intgetNextCount(int v) Returns the number of next vertices of v.intgetPrevArrowAsInt(int v, int i) Returns the arrow data of thei-th ingoing arrow tov.intgetPrevAsInt(int v, int i) Returns thei-th previous vertex ofv.intgetPrevCount(int v) Returns the number of direct predecessor vertices of v.intReturns the number of verticesV.intgetVertexDataAsInt(int vidx) Returns the data of the specified vertex.intgetVertexDataFromNextAsInt(int vidx) intgetVertexDataFromPrevAsInt(int vidx) nextVerticesEnumerator(int v) Returns the direct successor vertices of the specified vertex.prevVerticesEnumerator(int v) Returns the direct successor vertices of the specified vertex.voidremoveAllNextAsInt(int v) Removes all arrows starting at the specified vertex.voidremoveAllPrevAsInt(int v) Removes all arrows ending at the specified vertex.voidremoveNextAsInt(int v, int index) Removes the i-th arrow starting at vertex 'v'voidremovePrevAsInt(int vidx, int i) Removes the i-th arrow ending at vertex 'v'voidremoveVertexAsInt(int v) Removes vertex 'v'seachNextVerticesAsInt(int vidx, boolean dfs) Returns a breadth first spliterator that starts at the specified vertex.seachNextVerticesAsInt(int vidx, @NonNull AddToIntSet visited, boolean dfs) searchNextVerticesWithVertexData(int vidx, boolean dfs) Returns a breadth first spliterator that starts at the specified vertex.searchNextVerticesWithVertexData(int vidx, @NonNull AddToIntSet visited, boolean dfs) searchPrevVerticesAsInt(int vidx, boolean dfs) Returns a backward breadth first spliterator that starts at the specified vertex.searchPrevVerticesAsInt(int vidx, @NonNull AddToIntSet visited, boolean dfs) searchPrevVerticesWithVertexData(int vidx, boolean dfs) Returns a backward breadth first spliterator that starts at the specified vertex.searchPrevVerticesWithVertexData(int vidx, @NonNull AddToIntSet visited, boolean dfs) voidsetVertexAsInt(int vidx, int data) Sets the vertex data for the specified vertex.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.jhotdraw8.graph.IndexedBidiGraph
isPrevAsIntMethods inherited from interface org.jhotdraw8.graph.IndexedDirectedGraph
isNextAsIntMethods inherited from interface org.jhotdraw8.graph.MutableIndexedBidiGraph
removeArrowAsInt
-
Constructor Details
-
MutableIntAttributed16BitIndexedBidiGraph
public MutableIntAttributed16BitIndexedBidiGraph(int vertexCapacity, int maxArity) Creates a new instance.- Parameters:
vertexCapacity- the initial vertex capacitymaxArity- the maximal number of arrows per vertex
-
-
Method Details
-
clear
public void clear()Removes all vertices and all arrows. -
addArrowAsInt
public void addArrowAsInt(int v, int u) Description copied from interface:MutableIndexedBidiGraphAdds an arrow from vertex 'v' to vertex 'u' with arrow data 0.- Specified by:
addArrowAsIntin interfaceMutableIndexedBidiGraph- Parameters:
v- index of vertex 'v'u- index of vertex 'u'
-
addArrowAsInt
public void addArrowAsInt(int v, int u, int arrowData) Description copied from interface:MutableIndexedBidiGraphAdds an arrow from vertex 'v' to vertex 'u'.- Specified by:
addArrowAsIntin interfaceMutableIndexedBidiGraph- Parameters:
v- index of vertex 'v'u- index of vertex 'u'arrowData- the arrow data
-
addVertexAsInt
public void addVertexAsInt()Description copied from interface:MutableIndexedBidiGraphAdds a vertex to the graph.- Specified by:
addVertexAsIntin interfaceMutableIndexedBidiGraph
-
addVertexAsInt
public void addVertexAsInt(int v) Description copied from interface:MutableIndexedBidiGraphAdds a vertex at the specified index to the graph.- Specified by:
addVertexAsIntin interfaceMutableIndexedBidiGraph- Parameters:
v- index of vertex 'v'
-
findIndexOfNextAsInt
public int findIndexOfNextAsInt(int v, int u) Description copied from interface:IndexedDirectedGraphReturns the index of vertex b.- Specified by:
findIndexOfNextAsIntin interfaceIndexedDirectedGraph- Parameters:
v- a vertexu- another vertex- Returns:
- index of vertex b. Returns a value < 0 if b is not a next vertex of a.
-
findIndexOfPrevAsInt
public int findIndexOfPrevAsInt(int v, int u) Description copied from interface:IndexedBidiGraphReturns the index of the arrow fromvtouin the list of next-vertices fromv.- Specified by:
findIndexOfPrevAsIntin interfaceIndexedBidiGraph- Parameters:
v- vertexvu- vertexu- Returns:
- index of vertex
uin the list of next-vertices fromv. Returns a value < 0 ifuis not in the list.
-
getArrowCount
public int getArrowCount()Description copied from interface:IndexedDirectedGraphReturns the number of arrows.- Specified by:
getArrowCountin interfaceIndexedDirectedGraph- Returns:
- arrow count
-
getNextAsInt
public int getNextAsInt(int v, int i) Description copied from interface:IndexedDirectedGraphReturns thei-th next vertex ofv.- Specified by:
getNextAsIntin interfaceIndexedDirectedGraph- Parameters:
v- a vertex indexi- the index of the desired next vertex,i ∈ {0, ..., getNextCount(v) -1 }.- Returns:
- the vertex index of the i-th next vertex of v.
-
getNextCount
public int getNextCount(int v) Description copied from interface:IndexedDirectedGraphReturns the number of next vertices of v.- Specified by:
getNextCountin interfaceIndexedDirectedGraph- Parameters:
v- a vertex- Returns:
- the number of next vertices of v.
-
getPrevAsInt
public int getPrevAsInt(int v, int i) Description copied from interface:IndexedBidiGraphReturns thei-th previous vertex ofv.- Specified by:
getPrevAsIntin interfaceIndexedBidiGraph- Parameters:
v- index of vertex vi- index of ingoing arrow- Returns:
- the vertex index of the ingoing arrow
-
getPrevCount
public int getPrevCount(int v) Description copied from interface:IndexedBidiGraphReturns the number of direct predecessor vertices of v.- Specified by:
getPrevCountin interfaceIndexedBidiGraph- Parameters:
v- index of vertex v- Returns:
- the number of next vertices of v.
-
getVertexCount
public int getVertexCount()Description copied from interface:IndexedDirectedGraphReturns the number of verticesV.- Specified by:
getVertexCountin interfaceIndexedDirectedGraph- Returns:
- vertex count
-
nextVerticesEnumerator
Description copied from interface:IndexedDirectedGraphReturns the direct successor vertices of the specified vertex.- Specified by:
nextVerticesEnumeratorin interfaceIndexedDirectedGraph- Parameters:
v- a vertex index- Returns:
- a collection view on the direct successor vertices of vertex
-
prevVerticesEnumerator
Description copied from interface:IndexedBidiGraphReturns the direct successor vertices of the specified vertex.- Specified by:
prevVerticesEnumeratorin interfaceIndexedBidiGraph- Parameters:
v- index of vertex v- Returns:
- a collection view on the direct successor vertices of vertex
-
removeAllPrevAsInt
public void removeAllPrevAsInt(int v) Description copied from interface:MutableIndexedBidiGraphRemoves all arrows ending at the specified vertex.- Specified by:
removeAllPrevAsIntin interfaceMutableIndexedBidiGraph- Parameters:
v- index of vertex 'v'
-
removeAllNextAsInt
public void removeAllNextAsInt(int v) Description copied from interface:MutableIndexedBidiGraphRemoves all arrows starting at the specified vertex.- Specified by:
removeAllNextAsIntin interfaceMutableIndexedBidiGraph- Parameters:
v- index of vertex 'v'
-
removeNextAsInt
public void removeNextAsInt(int v, int index) Description copied from interface:MutableIndexedBidiGraphRemoves the i-th arrow starting at vertex 'v'- Specified by:
removeNextAsIntin interfaceMutableIndexedBidiGraph- Parameters:
v- index of vertex 'v'index- the index of the arrow starting at 'v'
-
removePrevAsInt
public void removePrevAsInt(int vidx, int i) Description copied from interface:MutableIndexedBidiGraphRemoves the i-th arrow ending at vertex 'v'- Specified by:
removePrevAsIntin interfaceMutableIndexedBidiGraph- Parameters:
vidx- index of vertex 'v'i- the index of the arrow ending at 'v'
-
removeVertexAsInt
public void removeVertexAsInt(int v) Description copied from interface:MutableIndexedBidiGraphRemoves vertex 'v'- Specified by:
removeVertexAsIntin interfaceMutableIndexedBidiGraph- Parameters:
v- index of vertex 'v'
-
setVertexAsInt
public void setVertexAsInt(int vidx, int data) Sets the vertex data for the specified vertex.- Parameters:
vidx- the index of the vertexdata- the vertex data
-
getNextArrowAsInt
public int getNextArrowAsInt(int v, int i) Description copied from interface:IndexedDirectedGraphReturns thei-th next arrow ofv.- Specified by:
getNextArrowAsIntin interfaceIndexedDirectedGraph- Specified by:
getNextArrowAsIntin interfaceIntAttributedIndexedDirectedGraph- 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.
-
getPrevArrowAsInt
public int getPrevArrowAsInt(int v, int i) Description copied from interface:IndexedBidiGraphReturns the arrow data of thei-th ingoing arrow tov.- Specified by:
getPrevArrowAsIntin interfaceIndexedBidiGraph- Parameters:
v- index of vertex vi- index of ingoing arrow- Returns:
- the arrow data of the ingoing arrow
-
getVertexDataAsInt
public int getVertexDataAsInt(int vidx) Description copied from interface:IntAttributedIndexedDirectedGraphReturns the data of the specified vertex.- Specified by:
getVertexDataAsIntin interfaceIntAttributedIndexedDirectedGraph- Parameters:
vidx- a vertex- Returns:
- the vertex data
-
getVertexDataFromNextAsInt
public int getVertexDataFromNextAsInt(int vidx) -
getVertexDataFromPrevAsInt
public int getVertexDataFromPrevAsInt(int vidx) -
seachNextVerticesAsInt
Returns a breadth first spliterator that starts at the specified vertex.- Parameters:
vidx- the index of the vertexdfs- whether to search depth-first instead of breadth-first- Returns:
- the spliterator
-
seachNextVerticesAsInt
public @NonNull Enumerator.OfInt seachNextVerticesAsInt(int vidx, @NonNull AddToIntSet visited, boolean dfs) -
searchPrevVerticesAsInt
Returns a backward breadth first spliterator that starts at the specified vertex.- Parameters:
vidx- the index of the vertexdfs-- Returns:
- the spliterator
-
searchPrevVerticesAsInt
public @NonNull Enumerator.OfInt searchPrevVerticesAsInt(int vidx, @NonNull AddToIntSet visited, boolean dfs) -
searchNextVerticesWithVertexData
Returns a breadth first spliterator that starts at the specified vertex.- Parameters:
vidx- the index of the vertexdfs-- Returns:
- the spliterator contains the vertex data in the 32 high-bits and the vertex index in the 32 low-bits of the long.
-
searchNextVerticesWithVertexData
public @NonNull Enumerator.OfLong searchNextVerticesWithVertexData(int vidx, @NonNull AddToIntSet visited, boolean dfs) -
searchPrevVerticesWithVertexData
Returns a backward breadth first spliterator that starts at the specified vertex.- Parameters:
vidx- the index of the vertexdfs-- Returns:
- the spliterator contains the vertex data in the 32 high-bits and the vertex index in the 32 low-bits of the long.
-
searchPrevVerticesWithVertexData
public @NonNull Enumerator.OfLong searchPrevVerticesWithVertexData(int vidx, @NonNull AddToIntSet visited, boolean dfs)
-