Package 

Class IdUtils


  • 
    public final class IdUtils
    
                        

    Utilities for generating 64-bit long IDs from types such as CharSequence.

    • Method Summary

      Modifier and Type Method Description
      static long hashLong64Bit(long value) Hash a long into 64 bits instead of the normal 32.
      static long hashString64Bit(@Nullable() CharSequence str) Hash a string into 64 bits instead of the normal 32.
      • Methods inherited from class java.lang.Object

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

      • hashLong64Bit

         static long hashLong64Bit(long value)

        Hash a long into 64 bits instead of the normal 32. This uses a xor shift implementation toattempt psuedo randomness so object ids have an even spread for less chance of collisions.

        From http://stackoverflow.com/a/11554034

        http://www.javamex.com/tutorials/random_numbers/xorshift.shtml

      • hashString64Bit

         static long hashString64Bit(@Nullable() CharSequence str)

        Hash a string into 64 bits instead of the normal 32. This allows us to better use strings as amodel id with less chance of collisions. This uses the FNV-1a algorithm for a good mix of speedand distribution.

        Performance comparisons found at http://stackoverflow.com/a/1660613

        Hash implementation from http://www.isthe.com/chongo/tech/comp/fnv/index.html#FNV-1a