Class ElementOrder<V>

  • All Implemented Interfaces:
    java.io.Serializable

    class ElementOrder<V>
    extends java.lang.Object
    implements java.io.Serializable
    Helper class to maintain a total order for a set of elements.

    The user can choose between using a comparator, using the natural ordering of the elements or maintaining internally a mapping to long integers. In the latter case the user is also responsible for notifying this class whenever elements are removed, in order to cleanup any internal state. Construction of elements is performed in a lazy manner.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.Comparator<V> comparator  
      private java.util.Map<V,​java.lang.Long> indices  
      private long nextId  
      private static long serialVersionUID  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private ElementOrder​(java.util.Comparator<V> comparator, java.util.Map<V,​java.lang.Long> indices)
      Create a new element order.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static <V> ElementOrder<V> comparator​(java.util.Comparator<V> comparator)
      Create an element order with a comparator
      int compare​(V v, V u)
      Compare two elements
      private long computeNextId​(V vertex)  
      static <V> ElementOrder<V> internal()
      Create an internal element order which maintains a map from elements to long values.
      V min​(V v, V u)
      Get the minimum of two elements.
      static <V> ElementOrder<V> natural()
      Create an element order with the natural ordering
      void notifyAddition​(V v)
      Notify about a new element.
      void notifyRemoval​(V v)
      Notify about an element being removed.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • comparator

        private java.util.Comparator<V> comparator
      • indices

        private java.util.Map<V,​java.lang.Long> indices
      • nextId

        private long nextId
    • Constructor Detail

      • ElementOrder

        private ElementOrder​(java.util.Comparator<V> comparator,
                             java.util.Map<V,​java.lang.Long> indices)
        Create a new element order.
        Parameters:
        comparator - the comparator to use
        indices - internal map from elements to long indices
    • Method Detail

      • comparator

        public static <V> ElementOrder<V> comparator​(java.util.Comparator<V> comparator)
        Create an element order with a comparator
        Type Parameters:
        V - the element type
        Parameters:
        comparator - the comparator
        Returns:
        the element order
      • natural

        public static <V> ElementOrder<V> natural()
        Create an element order with the natural ordering
        Type Parameters:
        V - the element type
        Returns:
        the element order
      • internal

        public static <V> ElementOrder<V> internal()
        Create an internal element order which maintains a map from elements to long values.
        Type Parameters:
        V - the element type
        Returns:
        the element order
      • compare

        public int compare​(V v,
                           V u)
        Compare two elements
        Parameters:
        v - first element
        u - second element
        Returns:
        the value 0 if v is equal to u; a value less than 0 if v is less than u; and a value greater than 0 if v is greater than u.
      • min

        public V min​(V v,
                     V u)
        Get the minimum of two elements.
        Parameters:
        v - first element
        u - second element
        Returns:
        the minimum of two elements
      • notifyAddition

        public void notifyAddition​(V v)
        Notify about a new element.
        Parameters:
        v - the element
      • notifyRemoval

        public void notifyRemoval​(V v)
        Notify about an element being removed. This method only affects the case that an internal map to long integers is maintained.
        Parameters:
        v - the element
      • computeNextId

        private long computeNextId​(V vertex)