Class VertexCollection

java.lang.Object
org.graph4j.util.VertexCollection
All Implemented Interfaces:
Iterable<Integer>
Direct Known Subclasses:
VertexList, VertexQueue, VertexSet, VertexStack

public abstract class VertexCollection extends Object implements Iterable<Integer>
A collection of vertices in a graph.
Author:
Cristian Frăsinaru
See Also:
  • Field Details

    • graph

      protected Graph graph
    • vertices

      protected int[] vertices
    • numVertices

      protected int numVertices
    • first

      protected int first
    • bitset

      protected BitSet bitset
    • DEFAULT_CAPACITY

      protected static final int DEFAULT_CAPACITY
      See Also:
  • Constructor Details

    • VertexCollection

      protected VertexCollection()
    • VertexCollection

      public VertexCollection(Graph graph)
      Parameters:
      graph - the graph the vertices belong to.
    • VertexCollection

      public VertexCollection(Graph graph, int initialCapacity)
      Parameters:
      graph - the graph the vertices belong to.
      initialCapacity - the initial capacity of this collection.
    • VertexCollection

      public VertexCollection(Graph graph, int[] vertices)
      Parameters:
      graph - the graph the vertices belong to.
      vertices - the initial set of vertices.
  • Method Details

    • getGraph

      public Graph getGraph()
      Returns:
      the graph containing the vertices.
    • isEmpty

      public boolean isEmpty()
      Returns:
      true if this collection has no vertices.
    • numVertices

      public int numVertices()
      Same as size().
      Returns:
      the number of vertices in the collection.
    • size

      public int size()
      Same as numVertices().
      Returns:
      the number of vertices in the collection.
    • iterator

      public Iterator<Integer> iterator()
      Specified by:
      iterator in interface Iterable<Integer>
      Returns:
      an iterator over the vertices in the collection.
    • 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:
      true if 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:
      true if 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

      protected static void union(VertexCollection set, int[] other, VertexCollection result)
    • 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:
      true if the vertices form a clique, false otherwise.
      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:
      true if the vertices form a stable set, false otherwise.
      Throws:
      IllegalArgumentException - if the graph is directed.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • vertexToString

      protected String vertexToString(int i)
    • toString

      public String toString()
      Overrides:
      toString in class Object