Package org.jgrapht.alg.util
Class VertexDegreeComparator<V,E>
java.lang.Object
org.jgrapht.alg.util.VertexDegreeComparator<V,E>
- All Implemented Interfaces:
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.
- Since:
- Nov 6, 2003
- Author:
- Linda Buisman
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a comparator for comparing the degrees of vertices in the specified graph.VertexDegreeComparator(UndirectedGraph<V, E> g, boolean ascendingOrder) Creates a comparator for comparing the degrees of vertices in the specified graph. -
Method Summary
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Comparator
equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
-
Constructor Details
-
VertexDegreeComparator
Creates a comparator for comparing the degrees of vertices in the specified graph. The comparator compares in ascending order of degrees (lowest first).- Parameters:
g- graph with respect to which the degree is calculated.
-
VertexDegreeComparator
Creates a comparator for comparing the degrees of vertices in the specified graph.- Parameters:
g- graph with respect to which the degree is calculated.ascendingOrder- true - compares in ascending order of degrees (lowest first), false - compares in descending order of degrees (highest first).
-
-
Method Details
-
compare
Compare the degrees ofv1andv2, taking into account whether ascending or descending order is used.- Specified by:
comparein interfaceComparator<V>- Parameters:
v1- the first vertex to be compared.v2- the second vertex to be compared.- Returns:
- -1 if
v1comes beforev2, +1 ifv1comes afterv2, 0 if equal.
-