src/tools/tracepp/jhash.h
/* The most generic version, hashes an arbitrary sequence
 * of bytes.  No alignment or length assumptions are made about
 * the input key.
 */
The most generic version, hashes an arbitrary sequence
of bytes.  No alignment or length assumptions are made about
the input key.
The most generic version hashes an arbitrary sequence of bytes . No alignment or length assumptions are made about the input key .
static inline u32 jhash(const void *key, u32 length, u32 initval)
{
    u32 a, b, c, len;
    const u8 *k = (const u8*)key;
    len = length;
    a = b = JHASH_GOLDEN_RATIO;
    c = initval;
    while (len >= 12) {
        a += (k[0] +((u32)k[1]<<8) +((u32)k[2]<<16) +((u32)k[3]<<24));
        b += (k[4] +((u32)k[5]<<8) +((u32)k[6]<<16) +((u32)k[7]<<24));
        c += (k[8] +((u32)k[9]<<8) +((u32)k[10]<<16)+((u32)k[11]<<24));
        __jhash_mix(a,b,c);
        k += 12;
        len -= 12;
    }
    c += length;
    switch (len) {
        case 11: c += ((u32)k[10]<<24);
        case 10: c += ((u32)k[9]<<16);
        case 9 : c += ((u32)k[8]<<8);
        case 8 : b += ((u32)k[7]<<24);
        case 7 : b += ((u32)k[6]<<16);
        case 6 : b += ((u32)k[5]<<8);
        case 5 : b += k[4];
        case 4 : a += ((u32)k[3]<<24);
        case 3 : a += ((u32)k[2]<<16);
        case 2 : a += ((u32)k[1]<<8);
        case 1 : a += k[0];
    };
    __jhash_mix(a,b,c);
    return c;
}
static inline u32 jhash ( const void * key , u32 length , u32 initval ) { u32 a , b , c , len ; const u8 * k = ( const u8 * ) key ; len = length ; a = b = JHASH_GOLDEN_RATIO ; c = initval ; while ( len >= 12 ) { a += ( k [ 0 ] + ( ( u32 ) k [ 1 ] << 8 ) + ( ( u32 ) k [ 2 ] << 16 ) + ( ( u32 ) k [ 3 ] << 24 ) ) ; b += ( k [ 4 ] + ( ( u32 ) k [ 5 ] << 8 ) + ( ( u32 ) k [ 6 ] << 16 ) + ( ( u32 ) k [ 7 ] << 24 ) ) ; c += ( k [ 8 ] + ( ( u32 ) k [ 9 ] << 8 ) + ( ( u32 ) k [ 10 ] << 16 ) + ( ( u32 ) k [ 11 ] << 24 ) ) ; __jhash_mix ( a , b , c ) ; k += 12 ; len -= 12 ; } c += length ; switch ( len ) { case 11 : c += ( ( u32 ) k [ 10 ] << 24 ) ; case 10 : c += ( ( u32 ) k [ 9 ] << 16 ) ; case 9 : c += ( ( u32 ) k [ 8 ] << 8 ) ; case 8 : b += ( ( u32 ) k [ 7 ] << 24 ) ; case 7 : b += ( ( u32 ) k [ 6 ] << 16 ) ; case 6 : b += ( ( u32 ) k [ 5 ] << 8 ) ; case 5 : b += k [ 4 ] ; case 4 : a += ( ( u32 ) k [ 3 ] << 24 ) ; case 3 : a += ( ( u32 ) k [ 2 ] << 16 ) ; case 2 : a += ( ( u32 ) k [ 1 ] << 8 ) ; case 1 : a += k [ 0 ] ; } ; __jhash_mix ( a , b , c ) ; return c ; }
The most generic version, hashes an arbitrary sequence
 of bytes.
The most generic version hashes an arbitrary sequence of bytes .