Class VertexDegreeComparator<V,E>

java.lang.Object
org.jgrapht.alg.util.VertexDegreeComparator<V,E>
Type Parameters:
V - the graph vertex type
E - the graph edge type
All Implemented Interfaces:
Comparator<V>

public abstract class VertexDegreeComparator<V,E> extends Object implements Comparator<V>
Compares two vertices based on their degree.

Used by greedy algorithms that need to sort vertices by their degree. Two vertices are considered equal if their degrees are equal.

Author:
Linda Buisman
  • Method Details

    • of

      public static <V> Comparator<V> of(Graph<V,?> g)
      Returns a Comparator that compares vertices by their degrees in the specified graph.

      The comparator compares in ascending order of degrees (lower degree first). To obtain a comparator that compares in descending order call Comparator.reversed() on the returned comparator.

      Type Parameters:
      V - the graph vertex type
      Parameters:
      g - graph with respect to which the degree is calculated.
      Returns:
      a Comparator to compare vertices by their degree in ascending order