FreeBSD/sys/libkern/jenkins_hash.c
/*
--------------------------------------------------------------------
 This works on all machines.  To be useful, it requires
 -- that the key be an array of uint32_t's, and
 -- that the length be the number of uint32_t's in the key

 The function hashword() is identical to hashlittle() on little-endian
 machines, and identical to hashbig() on big-endian machines,
 except that the length has to be measured in uint32_ts rather than in
 bytes.  hashlittle() is more complicated than hashword() only because
 hashlittle() has to dance around fitting the key bytes into registers.
--------------------------------------------------------------------
*/
This works on all machines.  To be useful, it requires
that the key be an array of uint32_t's, and
that the length be the number of uint32_t's in the key

The function hashword() is identical to hashlittle() on little-endian
machines, and identical to hashbig() on big-endian machines,
except that the length has to be measured in uint32_ts rather than in
bytes.  hashlittle() is more complicated than hashword() only because
hashlittle() has to dance around fitting the key bytes into registers.
This works on all machines . To be useful it requires that the key be an array of uint32_t ' s and that the length be the number of uint32_t ' s in the key The function hashword () is identical to hashlittle () on little - endian machines and identical to hashbig () on big - endian machines except that the length has to be measured in uint32_ts rather than in bytes . hashlittle () is more complicated than hashword () only because hashlittle () has to dance around fitting the key bytes into registers .
uint32_t jenkins_hash32(
const uint32_t *k,                   
size_t          length,               
uint32_t        initval)         
{
  uint32_t a,b,c;
  a = b = c = 0xdeadbeef + (((uint32_t)length)<<2) + initval;
  while (length > 3)
  {
    a += k[0];
    b += k[1];
    c += k[2];
    mix(a,b,c);
    length -= 3;
    k += 3;
  }
  switch(length)                     
  { 
  case 3 : c+=k[2];
  case 2 : b+=k[1];
  case 1 : a+=k[0];
    final(a,b,c);
  case 0:     
    break;
  }
  return c;
}
uint32_t jenkins_hash32 ( const uint32_t * k , size_t length , uint32_t initval ) { uint32_t a , b , c ; a = b = c = 0xdeadbeef + ( ( ( uint32_t ) length ) << 2 ) + initval ; while ( length > 3 ) { a += k [ 0 ] ; b += k [ 1 ] ; c += k [ 2 ] ; mix ( a , b , c ) ; length -= 3 ; k += 3 ; } switch ( length ) { case 3 : c += k [ 2 ] ; case 2 : b += k [ 1 ] ; case 1 : a += k [ 0 ] ; final ( a , b , c ) ; case 0 : break ; } return c ; }
This works on all machines.
This works on all machines .
/* the key, an array of uint32_t values */ /* the length of the key, in uint32_ts */ /* the previous hash, or an arbitrary value */ /* Set up the internal state */ /*------------------------------------------------- handle most of the key */ /*------------------------------------------- handle the last 3 uint32_t's */ /* all the case statements fall through */ /* case 0: nothing left to add */ /*------------------------------------------------------ report the result */