Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:01:58

0001 #ifndef CondCommon_Hash64_h
0002 #define CondCommon_Hash64_h
0003 
0004 namespace cond {
0005 
0006   /*
0007     --------------------------------------------------------------------
0008     lookup8.c, by Bob Jenkins, January 4 1997, Public Domain.
0009     hash(), hash2(), hash3, and mix() are externally useful functions.
0010     Routines to test the hash are included if SELF_TEST is defined.
0011     You can use this free for any purpose.  It has no warranty.
0012     --------------------------------------------------------------------
0013   */
0014 
0015   /*
0016     --------------------------------------------------------------------
0017     hash() -- hash a variable-length key into a 64-bit value
0018     k     : the key (the unaligned variable-length array of bytes)
0019     len   : the length of the key, counting by bytes
0020     level : can be any 8-byte value
0021     Returns a 64-bit value.  Every bit of the key affects every bit of
0022     the return value.  No funnels.  Every 1-bit and 2-bit delta achieves
0023     avalanche.  About 41+5len instructions.
0024     
0025     The best hash table sizes are powers of 2.  There is no need to do
0026     mod a prime (mod is sooo slow!).  If you need less than 64 bits,
0027     use a bitmask.  For example, if you need only 10 bits, do
0028     h = (h & hashmask(10));
0029     In which case, the hash table should have hashsize(10) elements.
0030     
0031     If you are hashing n strings (ub1 **)k, do it like this:
0032     for (i=0, h=0; i<n; ++i) h = hash( k[i], len[i], h);
0033     
0034     By Bob Jenkins, Jan 4 1997.  bob_jenkins@burtleburtle.net.  You may
0035     use this code any way you wish, private, educational, or commercial,
0036     but I would appreciate if you give me credit.
0037     
0038     See http://burtleburtle.net/bob/hash/evahash.html
0039     Use for hash table lookup, or anything where one collision in 2^^64
0040     is acceptable.  Do NOT use for cryptographic purposes.
0041     --------------------------------------------------------------------
0042   */
0043   /*
0044     --------------------------------------------------------------------
0045     This is identical to hash() on little-endian machines, and it is much
0046     faster than hash(), but a little slower than hash2(), and it requires
0047     -- that all your machines be little-endian, for example all Intel x86
0048     chips or all VAXen.  It gives wrong results on big-endian machines.
0049     --------------------------------------------------------------------
0050   */
0051 
0052   unsigned long long hash64(unsigned char* k, unsigned long long length, unsigned long long level);
0053 
0054 }  // namespace cond
0055 #endif