java.lang.Object
net.i2p.router.web.helpers.HashComparator
All Implemented Interfaces:
Serializable, Comparator<Hash>

class HashComparatorextends Object implements Comparator<Hash>, Serializable
Sorts in true binary order, not Base64 string order. A-Z a-z 0-9 -~.
  • Field Details

    • _instance

      public static final HashComparator _instance
      Shared stateless instance of the comparator.
  • Constructor Details

    • HashComparator

      HashComparator()
      Constructor. The ordering is fixed by the hash byte layout, so an instance holds no state and the shared _instance below is used instead.
  • Method Details

    • getInstance

      public static HashComparator getInstance()
      Thread safe, no state.
      Returns:
      the shared comparator, which holds no state
    • compare

      public int compare(Hash l, Hash r)
      Orders two hashes by their raw data bytes.
      Specified by:
      compare in interface Comparator<Hash>
    • comp

      public static int comp(Hash l, Hash r)
      Orders two hashes by their raw data bytes, statically.
      Parameters:
      l - left-hand Hash, compared through its raw data bytes
      r - right-hand Hash, compared through its raw data bytes
      Returns:
      negative, zero or positive as l's bytes are less than, equal to, or greater than r's