您的位置:首页 > 编程语言 > C语言/C++

jhash的C++实现

2016-07-18 17:42 309 查看
#define JHASH_INITVAL           0xdeadbeef

/* __jhash_final - final mixing of 3 32-bit values (a,b,c) into c */
#define __jhash_final(a, b, c)                  \
{                                               \
c ^= b; c -= rol32(b, 14);              \
a ^= c; a -= rol32(c, 11);              \
b ^= a; b -= rol32(a, 25);              \
c ^= b; c -= rol32(b, 16);              \
a ^= c; a -= rol32(c, 4);               \
b ^= a; b -= rol32(a, 14);              \
c ^= b; c -= rol32(b, 24);              \
}

typedef unsigned int u_int32_t;
typedef u_int32_t u32;
typedef u_int32_t __u32;
typedef u_int32_t _u32;
/**
* rol32 - rotate a 32-bit value left
* @word: value to rotate
* @shift: bits to roll
*/
static inline _u32 rol32(__u32 word, unsigned int shift)
{
return (word << shift) | (word >> (32 - shift));
}

static inline u32 jhash_3words(u32 a, u32 b, u32 c, u32 initval)
{
a += JHASH_INITVAL;
b += JHASH_INITVAL;
c += initval;

__jhash_final(a, b, c);

return c;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  c语言