18 #ifndef LIBMESH_HASHWORD_H 
   19 #define LIBMESH_HASHWORD_H 
   47 uint32_t rot(uint32_t x, uint32_t k)
 
   49   return (x<<k) | (x>>(32-k));
 
   63 void mix(uint32_t & a, uint32_t & b, uint32_t & c)
 
   65   a -= c;  a ^= rot(c, 4);  c += b;
 
   66   b -= a;  b ^= rot(a, 6);  a += c;
 
   67   c -= b;  c ^= rot(b, 8);  b += a;
 
   68   a -= c;  a ^= rot(c,16);  c += b;
 
   69   b -= a;  b ^= rot(a,19);  a += c;
 
   70   c -= b;  c ^= rot(b, 4);  b += a;
 
   83 void final(uint32_t & a, uint32_t & b, uint32_t & c)
 
   85   c ^= b; c -= rot(b,14);
 
   86   a ^= c; a -= rot(c,11);
 
   87   b ^= a; b -= rot(a,25);
 
   88   c ^= b; c -= rot(b,16);
 
   89   a ^= c; a -= rot(c,4);
 
   90   b ^= a; b -= rot(a,14);
 
   91   c ^= b; c -= rot(b,24);
 
  109 uint64_t fnv_64_buf(
const void * buf, 
size_t len)
 
  112   uint64_t hval = static_cast<uint64_t>(0xcbf29ce484222325ULL);
 
  115   const unsigned char * bp = static_cast<const unsigned char *>(buf);
 
  118   const unsigned char * be = bp + len;
 
  124         (hval << 1) + (hval << 4) + (hval << 5) +
 
  125         (hval << 7) + (hval << 8) + (hval << 40);
 
  128       hval ^= static_cast<uint64_t>(*bp++);
 
  153 uint32_t 
hashword(
const uint32_t * k, 
size_t length, uint32_t initval=0)
 
  158   a = b = c = 0xdeadbeef + ((static_cast<uint32_t>(length))<<2) + initval;
 
  175       libmesh_fallthrough();
 
  177       libmesh_fallthrough();
 
  180       libmesh_fallthrough();
 
  195 uint32_t 
hashword(
const std::vector<uint32_t> & keys, uint32_t initval=0)
 
  197   return hashword(keys.data(), keys.size(), initval);
 
  210 uint32_t 
hashword2(
const uint32_t & first, 
const uint32_t & second, uint32_t initval=0)
 
  215   a = b = c = 0xdeadbeef + 8 + initval;
 
  228 uint64_t 
hashword2(
const uint64_t first, 
const uint64_t second)
 
  233   uint64_t k[2] = {first, second};
 
  236   return fnv_64_buf(k, 8*2);
 
  240 uint16_t 
hashword2(
const uint16_t first, 
const uint16_t second)
 
  242   return static_cast<uint16_t>(first%65449 + (second<<5)%65449);
 
  249 uint64_t 
hashword(
const uint64_t * k, 
size_t length)
 
  251   return fnv_64_buf(k, 8*length);
 
  263 uint16_t 
hashword(
const uint16_t * k, 
size_t length)
 
  284         a = ((k[0]<<16) | (k[1] & 0xffff)); 
 
  285         b = ((k[2]<<16) | (k[3] & 0xffff)); 
 
  289       libmesh_error_msg(
"Unsupported length: " << length);
 
  294   return static_cast<uint16_t>(c);
 
  302 template <
typename Container>
 
  304 typename Container::value_type 
hashword(
const Container & keys)
 
  306   return hashword(keys.data(), keys.size());
 
  314 #endif // LIBMESH_HASHWORD_H