Package org._3pq.jgrapht.alg.util
Class VertexDegreeComparator
- java.lang.Object
-
- org._3pq.jgrapht.alg.util.VertexDegreeComparator
-
- All Implemented Interfaces:
java.util.Comparator
public class VertexDegreeComparator extends java.lang.Object implements java.util.Comparator
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
Constructors Constructor Description VertexDegreeComparator(UndirectedGraph g)
Creates a comparator for comparing the degrees of vertices in the specified graph.VertexDegreeComparator(UndirectedGraph g, boolean ascendingOrder)
Creates a comparator for comparing the degrees of vertices in the specified graph.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
compare(java.lang.Object v1, java.lang.Object v2)
Compare the degrees ofv1
andv2
, taking into account whether ascending or descending order is used.
-
-
-
Constructor Detail
-
VertexDegreeComparator
public VertexDegreeComparator(UndirectedGraph g)
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
public VertexDegreeComparator(UndirectedGraph g, boolean ascendingOrder)
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 Detail
-
compare
public int compare(java.lang.Object v1, java.lang.Object v2)
Compare the degrees ofv1
andv2
, taking into account whether ascending or descending order is used.- Specified by:
compare
in interfacejava.util.Comparator
- Parameters:
v1
- the first vertex to be compared.v2
- the second vertex to be compared.- Returns:
- -1 if
v1
comes beforev2
, +1 ifv1
comes afterv2
, 0 if equal.
-
-