Package org.graph4j.util
Class VertexCollection
java.lang.Object
org.graph4j.util.VertexCollection
- Direct Known Subclasses:
VertexList,VertexQueue,VertexSet,VertexStack
A collection of vertices in a graph.
- Author:
- Cristian Frăsinaru
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedVertexCollection(Graph graph) VertexCollection(Graph graph, int initialCapacity) VertexCollection(Graph graph, int[] vertices) -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanadd(int v) Adds the vertex in the collection.protected voidaddAll(int... vertices) voidclear()Removes all of the elements from this collection.doublebooleancontains(int v) booleangetGraph()protected voidgrow()inthashCode()protected intindexOf(int v) protected intindexOf(int v, int startPos) booleanisClique()Checks if the specified vertices represent a clique, meaning that the subgraph induced by them is complete.booleanisEmpty()booleanChecks if the specified vertices represent a stable set, meaning that the subgraph induced by them is empty.iterator()intSame assize().protected booleanremove(int v) Removes a vertex from the collection.booleanremoveAll(int... vertices) protected voidremoveFromPos(int pos) voidRemoves the last element in the collection.booleanretainAll(int... vertices) intsize()Same asnumVertices().toString()protected static voidunion(VertexCollection set, int[] other, VertexCollection result) protected StringvertexToString(int i) int[]vertices()For performance reasons, the returned array represents the actual data structure where vertices of the collection are stored, so it must not be modified.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
graph
-
vertices
protected int[] vertices -
numVertices
protected int numVertices -
first
protected int first -
bitset
-
DEFAULT_CAPACITY
protected static final int DEFAULT_CAPACITY- See Also:
-
-
Constructor Details
-
VertexCollection
protected VertexCollection() -
VertexCollection
- Parameters:
graph- the graph the vertices belong to.
-
VertexCollection
- Parameters:
graph- the graph the vertices belong to.initialCapacity- the initial capacity of this collection.
-
VertexCollection
- Parameters:
graph- the graph the vertices belong to.vertices- the initial set of vertices.
-
-
Method Details
-
getGraph
- Returns:
- the graph containing the vertices.
-
isEmpty
public boolean isEmpty()- Returns:
trueif this collection has no vertices.
-
numVertices
public int numVertices()Same assize().- Returns:
- the number of vertices in the collection.
-
size
public int size()Same asnumVertices().- Returns:
- the number of vertices in the collection.
-
iterator
-
vertices
public int[] vertices()For performance reasons, the returned array represents the actual data structure where vertices of the collection are stored, so it must not be modified.- Returns:
- the vertices in the collection.
-
indexOf
protected int indexOf(int v) -
indexOf
protected int indexOf(int v, int startPos) -
add
protected boolean add(int v) Adds the vertex in the collection.- Parameters:
v- a vertex number- Returns:
- true, if the collection changed as a result of this call
-
addAll
protected void addAll(int... vertices) - Parameters:
vertices- an array of vertex numbers.
-
remove
protected boolean remove(int v) Removes a vertex from the collection.- Parameters:
v- a vertex number- Returns:
- true, if the collection changed as a result of this call
-
removeFromPos
protected void removeFromPos(int pos) -
removeAll
public boolean removeAll(int... vertices) - Parameters:
vertices- an array of vertex numbers.- Returns:
trueif the collection was modified as a result of this invocation.
-
removeLast
public void removeLast()Removes the last element in the collection. -
retainAll
public boolean retainAll(int... vertices) - Parameters:
vertices- an array of vertex numbers.- Returns:
trueif the collection was modified as a result of this invocation.
-
clear
public void clear()Removes all of the elements from this collection. The collection will be empty after this method returns. -
contains
public boolean contains(int v) - Parameters:
v- a vertex number.- Returns:
true, if this collection contains the vertex v.
-
union
-
computeVerticesWeight
public double computeVerticesWeight()- Returns:
- the sum of all weights of the vertices in the collection, including duplicates.
-
grow
protected void grow() -
isClique
public boolean isClique()Checks if the specified vertices represent a clique, meaning that the subgraph induced by them is complete.- Returns:
trueif the vertices form a clique,falseotherwise.- Throws:
IllegalArgumentException- if the graph is directed.
-
isStableSet
public boolean isStableSet()Checks if the specified vertices represent a stable set, meaning that the subgraph induced by them is empty.- Returns:
trueif the vertices form a stable set,falseotherwise.- Throws:
IllegalArgumentException- if the graph is directed.
-
hashCode
public int hashCode() -
equals
-
vertexToString
-
toString
-