FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

Hasher.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2010 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software: you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
00023 
00024 Description
00025     Hashing functions, mostly from Bob Jenkins
00026 \*---------------------------------------------------------------------------*/
00027 
00028 #include "Hasher.H"
00029 #include "HasherInt.H"
00030 
00031 #if defined (__GLIBC__)
00032 #  include <endian.h>
00033 #endif
00034 
00035 // Left-rotate a 32-bit value and carry by nBits
00036 #define bitRotateLeft(x, nBits)  (((x) << (nBits)) | ((x) >> (32 - (nBits))))
00037 
00038 
00039 // ----------------------------------------------------------------------------
00040 // lookup3.c, by Bob Jenkins, May 2006, Public Domain.
00041 //
00042 // These are functions for producing 32-bit hashes for hash table lookup.
00043 // hashword(), hashlittle(), hashlittle2(), hashbig(), mix(), and final()
00044 // are externally useful functions.  Routines to test the hash are included
00045 // if SELF_TEST is defined.  You can use this free for any purpose.  It's in
00046 // the public domain.  It has no warranty.
00047 //
00048 // You probably want to use hashlittle().  hashlittle() and hashbig()
00049 // hash byte arrays.  hashlittle() is is faster than hashbig() on
00050 // little-endian machines.  Intel and AMD are little-endian machines.
00051 // On second thought, you probably want hashlittle2(), which is identical to
00052 // hashlittle() except it returns two 32-bit hashes for the price of one.
00053 // You could implement hashbig2() if you wanted but I haven't bothered here.
00054 //
00055 // If you want to find a hash of, say, exactly 7 integers, do
00056 //   a = i1;  b = i2;  c = i3;
00057 //   mix(a,b,c);
00058 //   a += i4; b += i5; c += i6;
00059 //   mix(a,b,c);
00060 //   a += i7;
00061 //   final(a,b,c);
00062 // then use c as the hash value.  If you have a variable length array of
00063 // 4-byte integers to hash, use hashword().  If you have a byte array (like
00064 // a character string), use hashlittle().  If you have several byte arrays, or
00065 // a mix of things, see the comments above hashlittle().
00066 //
00067 // Why is this so big?  I read 12 bytes at a time into 3 4-byte integers,
00068 // then mix those integers.  This is fast (you can do a lot more thorough
00069 // mixing with 12*3 instructions on 3 integers than you can with 3 instructions
00070 // on 1 byte), but shoehorning those bytes into integers efficiently is messy.
00071 // ----------------------------------------------------------------------------
00072 
00073 // ----------------------------------------------------------------------------
00074 // mix -- mix 3 32-bit values reversibly.
00075 //
00076 // This is reversible, so any information in (a,b,c) before mix_hash() is
00077 // still in (a,b,c) after mix_hash().
00078 //
00079 // If four pairs of (a,b,c) inputs are run through mix_hash(), or through
00080 // mix_hash() in reverse, there are at least 32 bits of the output that
00081 // are sometimes the same for one pair and different for another pair.
00082 // This was tested for:
00083 // * pairs that differed by one bit, by two bits, in any combination
00084 //   of top bits of (a,b,c), or in any combination of bottom bits of
00085 //   (a,b,c).
00086 // * "differ" is defined as +, -, ^, or ~^.  For + and -, I transformed
00087 //   the output delta to a Gray code (a^(a>>1)) so a string of 1's (as
00088 //   is commonly produced by subtraction) look like a single 1-bit
00089 //   difference.
00090 // * the base values were pseudorandom, all zero but one bit set, or
00091 //   all zero plus a counter that starts at zero.
00092 //
00093 // Some k values for my "a-=c; a^=rot(c,k); c+=b;" arrangement that
00094 // satisfy this are
00095 //     4  6  8 16 19  4
00096 //     9 15  3 18 27 15
00097 //    14  9  3  7 17  3
00098 // Well, "9 15 3 18 27 15" didn't quite get 32 bits diffing
00099 // for "differ" defined as + with a one-bit base and a two-bit delta.  I
00100 // used http://burtleburtle.net/bob/hash/avalanche.html to choose
00101 // the operations, constants, and arrangements of the variables.
00102 //
00103 // This does not achieve avalanche.  There are input bits of (a,b,c)
00104 // that fail to affect some output bits of (a,b,c), especially of a.  The
00105 // most thoroughly mixed value is c, but it doesn't really even achieve
00106 // avalanche in c.
00107 //
00108 // This allows some parallelism.  Read-after-writes are good at doubling
00109 // the number of bits affected, so the goal of mixing pulls in the opposite
00110 // direction as the goal of parallelism.  I did what I could.  Rotates
00111 // seem to cost as much as shifts on every machine I could lay my hands
00112 // on, and rotates are much kinder to the top and bottom bits, so I used
00113 // rotates.
00114 // ----------------------------------------------------------------------------
00115 
00116 #define bitMixer(a, b, c)                                                     \
00117     {                                                                         \
00118         a -= c; a ^= bitRotateLeft(c, 4); c += b;                             \
00119         b -= a; b ^= bitRotateLeft(a, 6); a += c;                             \
00120         c -= b; c ^= bitRotateLeft(b, 8); b += a;                             \
00121         a -= c; a ^= bitRotateLeft(c,16); c += b;                             \
00122         b -= a; b ^= bitRotateLeft(a,19); a += c;                             \
00123         c -= b; c ^= bitRotateLeft(b, 4); b += a;                             \
00124     }
00125 
00126 
00127 // ----------------------------------------------------------------------------
00128 // final -- final mixing of 3 32-bit values (a,b,c) into c
00129 //
00130 // Pairs of (a,b,c) values differing in only a few bits will usually
00131 // produce values of c that look totally different.  This was tested for
00132 // * pairs that differed by one bit, by two bits, in any combination
00133 //   of top bits of (a,b,c), or in any combination of bottom bits of
00134 //   (a,b,c).
00135 // * "differ" is defined as +, -, ^, or ~^.  For + and -, I transformed
00136 //   the output delta to a Gray code (a^(a>>1)) so a string of 1's (as
00137 //   is commonly produced by subtraction) look like a single 1-bit
00138 //   difference.
00139 // * the base values were pseudorandom, all zero but one bit set, or
00140 //   all zero plus a counter that starts at zero.
00141 //
00142 // These constants passed:
00143 //  14 11 25 16 4 14 24
00144 //  12 14 25 16 4 14 24
00145 // and these came close:
00146 //   4  8 15 26 3 22 24
00147 //  10  8 15 26 3 22 24
00148 //  11  8 15 26 3 22 24
00149 // ----------------------------------------------------------------------------
00150 
00151 #define bitMixerFinal(a, b, c)                                                \
00152     {                                                                         \
00153         c ^= b; c -= bitRotateLeft(b, 14);                                    \
00154         a ^= c; a -= bitRotateLeft(c, 11);                                    \
00155         b ^= a; b -= bitRotateLeft(a, 25);                                    \
00156         c ^= b; c -= bitRotateLeft(b, 16);                                    \
00157         a ^= c; a -= bitRotateLeft(c, 4);                                     \
00158         b ^= a; b -= bitRotateLeft(a, 14);                                    \
00159         c ^= b; c -= bitRotateLeft(b, 24);                                    \
00160     }
00161 
00162 
00163 // * * * * * * * * * * * * * * Static Functions  * * * * * * * * * * * * * * //
00164 
00165 // ----------------------------------------------------------------------------
00166 // hashlittle() -- hash a variable-length key into a 32-bit value
00167 //   k       : the key (the unaligned variable-length array of bytes)
00168 //   length  : the length of the key, counting by bytes
00169 //   initval : can be any 4-byte value
00170 // Returns a 32-bit value.  Every bit of the key affects every bit of
00171 // the return value.  Two keys differing by one or two bits will have
00172 // totally different hash values.
00173 //
00174 // The best hash table sizes are powers of 2.  There is no need to do
00175 // mod a prime (mod is sooo slow!).  If you need less than 32 bits,
00176 // use a bitmask.  For example, if you need only 10 bits, do
00177 //   h = (h & hashmask(10));
00178 // In which case, the hash table should have hashsize(10) elements.
00179 //
00180 // If you are hashing n strings (uint8_t **)k, do it like this:
00181 //   for (i=0, h=0; i<n; ++i) h = hashlittle( k[i], len[i], h);
00182 //
00183 // By Bob Jenkins, 2006.  bob_jenkins@burtleburtle.net.  You may use this
00184 // code any way you wish, private, educational, or commercial.  It's free.
00185 //
00186 // Use for hash table lookup, or anything where one collision in 2^^32 is
00187 // acceptable.  Do NOT use for cryptographic purposes.
00188 // ----------------------------------------------------------------------------
00189 
00190 //- specialized little-endian code
00191 #if !defined (__BYTE_ORDER) || (__BYTE_ORDER == __LITTLE_ENDIAN)
00192 static unsigned jenkins_hashlittle
00193 (
00194     const void *key,
00195     size_t length,
00196     unsigned initval
00197 )
00198 {
00199     uint32_t a, b, c;
00200     union { const void *ptr; size_t i; } u; // to cast key to (size_t) happily
00201 
00202     // Set up the internal state
00203     a = b = c = 0xdeadbeef + static_cast<uint32_t>(length) + initval;
00204 
00205     u.ptr = key;
00206     if ((u.i & 0x3) == 0)
00207     {
00208         // 32-bit chunks
00209         const uint32_t *k = reinterpret_cast<const uint32_t*>(key);
00210 
00211         // all but last block: aligned reads and affect 32 bits of (a,b,c)
00212         while (length > 12)
00213         {
00214             a += k[0];
00215             b += k[1];
00216             c += k[2];
00217             bitMixer(a,b,c);
00218             length -= 12;
00219             k += 3;
00220         }
00221 
00222         // handle the last (probably partial) block byte-wise
00223         const uint8_t *k8 = reinterpret_cast<const uint8_t*>(k);
00224         switch (length)
00225         {
00226             case 12: c += k[2]; b += k[1]; a += k[0]; break;
00227             case 11: c += static_cast<uint32_t>(k8[10]) << 16; // fall through
00228             case 10: c += static_cast<uint32_t>(k8[9])  << 8;  // fall through
00229             case 9 : c += k8[8];                               // fall through
00230             case 8 : b += k[1]; a += k[0]; break;
00231             case 7 : b += static_cast<uint32_t>(k8[6]) << 16;  // fall through
00232             case 6 : b += static_cast<uint32_t>(k8[5]) << 8;   // fall through
00233             case 5 : b += k8[4];                               // fall through
00234             case 4 : a += k[0]; break;
00235             case 3 : a += static_cast<uint32_t>(k8[2]) << 16;  // fall through
00236             case 2 : a += static_cast<uint32_t>(k8[1]) << 8;   // fall through
00237             case 1 : a += k8[0]; break;
00238             case 0 : return c;  // zero-length requires no mixing
00239         }
00240     }
00241     else if ((u.i & 0x1) == 0)
00242     {
00243         // 16-bit chunks
00244         const uint16_t *k = reinterpret_cast<const uint16_t*>(key);
00245 
00246         // all but last block: aligned reads and different mixing
00247         while (length > 12)
00248         {
00249             a += k[0] + (static_cast<uint32_t>(k[1]) << 16);
00250             b += k[2] + (static_cast<uint32_t>(k[3]) << 16);
00251             c += k[4] + (static_cast<uint32_t>(k[5]) << 16);
00252             bitMixer(a,b,c);
00253             length -= 12;
00254             k += 6;
00255         }
00256 
00257         // handle the last (probably partial) block
00258         const uint8_t *k8 = reinterpret_cast<const uint8_t*>(k);
00259         switch (length)
00260         {
00261             case 12:
00262                 c += k[4] + (static_cast<uint32_t>(k[5]) << 16);
00263                 b += k[2] + (static_cast<uint32_t>(k[3]) << 16);
00264                 a += k[0] + (static_cast<uint32_t>(k[1]) << 16);
00265                 break;
00266             case 11:
00267                 c += static_cast<uint32_t>(k8[10]) << 16;
00268                 // fall through
00269             case 10:
00270                 c += k[4];
00271                 b += k[2] + (static_cast<uint32_t>(k[3]) << 16);
00272                 a += k[0] + (static_cast<uint32_t>(k[1]) << 16);
00273                 break;
00274             case 9 :
00275                 c += k8[8];
00276                 // fall through
00277             case 8 :
00278                 b += k[2] + (static_cast<uint32_t>(k[3]) << 16);
00279                 a += k[0] + (static_cast<uint32_t>(k[1]) << 16);
00280                 break;
00281             case 7 :
00282                 b += static_cast<uint32_t>(k8[6]) << 16;
00283                 // fall through
00284             case 6 :
00285                 b += k[2];
00286                 a += k[0] + (static_cast<uint32_t>(k[1]) << 16);
00287                 break;
00288             case 5 :
00289                 b += k8[4];
00290                 // fall through
00291             case 4 :
00292                 a += k[0] + (static_cast<uint32_t>(k[1]) << 16);
00293                 break;
00294             case 3 :
00295                 a += static_cast<uint32_t>(k8[2]) << 16;
00296                 // fall through
00297             case 2 :
00298                 a += k[0];
00299                 break;
00300             case 1 :
00301                 a += k8[0];
00302                 break;
00303             case 0 : return c;     // zero-length requires no mixing
00304         }
00305     }
00306     else
00307     {
00308         const uint8_t *k = reinterpret_cast<const uint8_t*>(key);
00309 
00310         // all but the last block: affect some 32 bits of (a,b,c)
00311         while (length > 12)
00312         {
00313             a += k[0];
00314             a += static_cast<uint32_t>(k[1]) << 8;
00315             a += static_cast<uint32_t>(k[2]) << 16;
00316             a += static_cast<uint32_t>(k[3]) << 24;
00317             b += k[4];
00318             b += static_cast<uint32_t>(k[5]) << 8;
00319             b += static_cast<uint32_t>(k[6]) << 16;
00320             b += static_cast<uint32_t>(k[7]) << 24;
00321             c += k[8];
00322             c += static_cast<uint32_t>(k[9])  << 8;
00323             c += static_cast<uint32_t>(k[10]) << 16;
00324             c += static_cast<uint32_t>(k[11]) << 24;
00325 
00326             bitMixer(a,b,c);
00327             length -= 12;
00328             k += 12;
00329         }
00330 
00331         // last block: affect all 32 bits of (c)
00332         switch (length) // most case statements fall through
00333         {
00334             case 12: c += static_cast<uint32_t>(k[11]) << 24;
00335             case 11: c += static_cast<uint32_t>(k[10]) << 16;
00336             case 10: c += static_cast<uint32_t>(k[9]) << 8;
00337             case 9 : c += k[8];
00338 
00339             case 8 : b += static_cast<uint32_t>(k[7]) << 24;
00340             case 7 : b += static_cast<uint32_t>(k[6]) << 16;
00341             case 6 : b += static_cast<uint32_t>(k[5]) << 8;
00342             case 5 : b += k[4];
00343 
00344             case 4 : a += static_cast<uint32_t>(k[3]) << 24;
00345             case 3 : a += static_cast<uint32_t>(k[2]) << 16;
00346             case 2 : a += static_cast<uint32_t>(k[1]) << 8;
00347             case 1 : a += k[0];
00348                 break;
00349 
00350             case 0 : return c;
00351         }
00352     }
00353 
00354     bitMixerFinal(a,b,c);
00355     return c;
00356 }
00357 #endif
00358 
00359 
00360 
00361 
00362 // ----------------------------------------------------------------------------
00363 // hashbig():
00364 // This is the same as hashword() on big-endian machines.  It is different
00365 // from hashlittle() on all machines.  hashbig() takes advantage of
00366 // big-endian byte ordering.
00367 // ----------------------------------------------------------------------------
00368 // specialized big-endian code
00369 #if !defined (__BYTE_ORDER) || (__BYTE_ORDER == __BIG_ENDIAN)
00370 static unsigned jenkins_hashbig
00371 (
00372     const void *key,
00373     size_t length,
00374     unsigned initval
00375 )
00376 {
00377     uint32_t a, b, c;
00378     union { const void *ptr; size_t i; } u; // to cast key to (size_t) happily
00379 
00380     // Set up the internal state
00381     a = b = c = 0xdeadbeef + static_cast<uint32_t>(length) + initval;
00382 
00383     u.ptr = key;
00384     if ((u.i & 0x3) == 0)
00385     {
00386         // 32-bit chunks
00387         const uint32_t *k = reinterpret_cast<const uint32_t*>(key);
00388 
00389         // all but last block: aligned reads and affect 32 bits of (a,b,c)
00390         while (length > 12)
00391         {
00392             a += k[0];
00393             b += k[1];
00394             c += k[2];
00395             bitMixer(a,b,c);
00396             length -= 12;
00397             k += 3;
00398         }
00399 
00400         // handle the last (probably partial) block byte-wise
00401         const uint8_t *k8 = reinterpret_cast<const uint8_t*>(k);
00402 
00403         switch (length) // most the case statements fall through
00404         {
00405             case 12: c += k[2]; b += k[1]; a += k[0]; break;
00406             case 11: c += static_cast<uint32_t>(k8[10]) << 8; // fall through
00407             case 10: c += static_cast<uint32_t>(k8[9]) << 16; // fall through
00408             case 9 : c += static_cast<uint32_t>(k8[8]) << 24; // fall through
00409             case 8 : b += k[1]; a += k[0]; break;
00410             case 7 : b += static_cast<uint32_t>(k8[6]) << 8;  // fall through
00411             case 6 : b += static_cast<uint32_t>(k8[5]) << 16; // fall through
00412             case 5 : b += static_cast<uint32_t>(k8[4]) << 24; // fall through
00413             case 4 : a += k[0]; break;
00414             case 3 : a += static_cast<uint32_t>(k8[2]) << 8;  // fall through
00415             case 2 : a += static_cast<uint32_t>(k8[1]) << 16; // fall through
00416             case 1 : a += static_cast<uint32_t>(k8[0]) << 24; break;
00417             case 0 : return c;
00418         }
00419     }
00420     else
00421     {
00422         // need to read the key one byte at a time
00423         const uint8_t *k = reinterpret_cast<const uint8_t*>(key);
00424 
00425         // all but the last block: affect some 32 bits of (a,b,c)
00426         while (length > 12)
00427         {
00428             a += static_cast<uint32_t>(k[0]) << 24;
00429             a += static_cast<uint32_t>(k[1]) << 16;
00430             a += static_cast<uint32_t>(k[2]) << 8;
00431             a += static_cast<uint32_t>(k[3]);
00432             b += static_cast<uint32_t>(k[4]) << 24;
00433             b += static_cast<uint32_t>(k[5]) << 16;
00434             b += static_cast<uint32_t>(k[6]) << 8;
00435             b += static_cast<uint32_t>(k[7]);
00436             c += static_cast<uint32_t>(k[8]) << 24;
00437             c += static_cast<uint32_t>(k[9]) << 16;
00438             c += static_cast<uint32_t>(k[10]) << 8;
00439             c += static_cast<uint32_t>(k[11]);
00440 
00441             bitMixer(a,b,c);
00442             length -= 12;
00443             k += 12;
00444         }
00445 
00446         // last block: affect all 32 bits of (c)
00447         switch (length) // the case statements fall through
00448         {
00449             case 12: c += k[11];
00450             case 11: c += static_cast<uint32_t>(k[10]) << 8;
00451             case 10: c += static_cast<uint32_t>(k[9]) << 16;
00452             case 9 : c += static_cast<uint32_t>(k[8]) << 24;
00453             case 8 : b += k[7];
00454             case 7 : b += static_cast<uint32_t>(k[6]) << 8;
00455             case 6 : b += static_cast<uint32_t>(k[5]) << 16;
00456             case 5 : b += static_cast<uint32_t>(k[4]) << 24;
00457             case 4 : a += k[3];
00458             case 3 : a += static_cast<uint32_t>(k[2]) << 8;
00459             case 2 : a += static_cast<uint32_t>(k[1]) << 16;
00460             case 1 : a += static_cast<uint32_t>(k[0]) << 24;
00461                 break;
00462             case 0 : return c;
00463         }
00464     }
00465 
00466     bitMixerFinal(a,b,c);
00467     return c;
00468 }
00469 #endif
00470 
00471 
00472 // * * * * * * * * * * * * * * * Global Functions  * * * * * * * * * * * * * //
00473 
00474 
00475 unsigned Foam::Hasher
00476 (
00477     const void *key,
00478     size_t length,
00479     unsigned initval
00480 )
00481 {
00482 #ifdef __BYTE_ORDER
00483 # if (__BYTE_ORDER == __BIG_ENDIAN)
00484     return jenkins_hashbig(key, length, initval);
00485 # else
00486     return jenkins_hashlittle(key, length, initval);
00487 # endif
00488 #else
00489     // endian-ness not known at compile-time: runtime endian test
00490     const short endianTest = 0x0100;
00491 
00492     // yields 0x01 for big endian
00493     if (*(reinterpret_cast<const char *>(&endianTest)))
00494     {
00495         return jenkins_hashbig(key, length, initval);
00496     }
00497     else
00498     {
00499         return jenkins_hashlittle(key, length, initval);
00500     }
00501 #endif
00502 }
00503 
00504 
00505 // ----------------------------------------------------------------------------
00506 //  This works on all machines.  To be useful, it requires
00507 //  -- that the key be an array of uint32_t's, and
00508 //  -- that the length be the number of uint32_t's in the key
00509 //
00510 //  The function hashword() is identical to hashlittle() on little-endian
00511 //  machines, and identical to hashbig() on big-endian machines,
00512 //  except that the length has to be measured in uint32_ts rather than in
00513 //  bytes.  hashlittle() is more complicated than hashword() only because
00514 //  hashlittle() has to dance around fitting the key bytes into registers.
00515 // ----------------------------------------------------------------------------
00516 unsigned Foam::HasherInt
00517 (
00518     const uint32_t *k,
00519     size_t length,
00520     unsigned seed
00521 )
00522 {
00523     uint32_t a, b, c;
00524 
00525     // Set up the internal state
00526     a = b = c = 0xdeadbeef + (static_cast<uint32_t>(length) << 2) + seed;
00527 
00528     // handle most of the key
00529     while (length > 3)
00530     {
00531         a += k[0];
00532         b += k[1];
00533         c += k[2];
00534         bitMixer(a,b,c);
00535         length -= 3;
00536         k += 3;
00537     }
00538 
00539     // handle the last 3 uint32_t's
00540     switch (length)  // all case statements fall through
00541     {
00542         case 3 : c += k[2];
00543         case 2 : b += k[1];
00544         case 1 : a += k[0];
00545             bitMixerFinal(a,b,c);
00546         case 0 :  // case 0: nothing left to add
00547             break;
00548     }
00549 
00550     return c;
00551 }
00552 
00553 
00554 // ----------------------------------------------------------------------------
00555 // hashword2() -- same as hashword(), but take two seeds and return two
00556 // 32-bit values.  pc and pb must both be non-null, and *pc and *pb must
00557 // both be initialized with seeds.  If you pass in (*pb)==0, the output
00558 // (*pc) will be the same as the return value from hashword().
00559 // ----------------------------------------------------------------------------
00560 unsigned Foam::HasherDual
00561 (
00562     const uint32_t *k,
00563     size_t length,
00564     unsigned& hash1,  // IN: seed OUT: primary hash value
00565     unsigned& hash2   // IN: more seed OUT: secondary hash value
00566 )
00567 {
00568     uint32_t a, b, c;
00569 
00570     // Set up the internal state
00571     a = b = c = 0xdeadbeef + (static_cast<uint32_t>(length) << 2) + hash1;
00572     c += hash2;
00573 
00574     // handle most of the key
00575     while (length > 3)
00576     {
00577         a += k[0];
00578         b += k[1];
00579         c += k[2];
00580         bitMixer(a,b,c);
00581         length -= 3;
00582         k += 3;
00583     }
00584 
00585     // handle the last 3 uint32_t's
00586     switch (length)  // all case statements fall through
00587     {
00588         case 3 : c += k[2];
00589         case 2 : b += k[1];
00590         case 1 : a += k[0];
00591             bitMixerFinal(a,b,c);
00592         case 0 :  // case 0: nothing left to add
00593             break;
00594     }
00595 
00596     // report the result
00597     hash1 = c;
00598     hash2 = b;
00599 
00600     // return primary hash value
00601     return c;
00602 }
00603 
00604 
00605 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines