Class VertexDegreeComparator<V,​E>

  • Type Parameters:
    V - the graph vertex type
    E - the graph edge type
    All Implemented Interfaces:
    java.util.Comparator<V>

    public class VertexDegreeComparator<V,​E>
    extends java.lang.Object
    implements java.util.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
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  VertexDegreeComparator.Order
      Order in which we sort the vertices: ascending vertex degree or descending vertex degree
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int compare​(V v1, V v2)
      Compare the degrees of v1 and v2, taking into account whether ascending or descending order is used.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.util.Comparator

        equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
    • Constructor Detail

      • VertexDegreeComparator

        public VertexDegreeComparator​(Graph<V,​E> 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​(Graph<V,​E> g,
                                      VertexDegreeComparator.Order order)
        Creates a comparator for comparing the degrees of vertices in the specified graph.
        Parameters:
        g - graph with respect to which the degree is calculated.
        order - order in which the vertices are sorted (ascending or descending)
    • Method Detail

      • compare

        public int compare​(V v1,
                           V v2)
        Compare the degrees of v1 and v2, taking into account whether ascending or descending order is used.
        Specified by:
        compare in interface java.util.Comparator<V>
        Parameters:
        v1 - the first vertex to be compared.
        v2 - the second vertex to be compared.
        Returns:
        -1 if v1 comes before v2, +1 if v1 comes after v2, 0 if equal.