我只想对64位整数进行哈希运算。我在给定here的情况下使用murmurhash3的实现。考虑到这一限制,代码中是否有一些改进。我不能完全弄清楚,但我认为第171行的for循环可能是目标。请在这方面提出一些建议。
发布于 2012-06-15 15:16:26
如果你只需要哈希64位数字,那么使用数字值,因为murmur3所做的一切都是浪费CPU周期,将相同的输入数字混合到相同的输出数字中,唯一的例外是你改变了种子。
如果你真的想要优化一个固定的大小,你可以复制这个函数,然后稍微修改一下(允许编译器不断地传播和不断地折叠来完成繁重的任务):
void MurmurHash3_x86_128_uint64 ( const void * key, uint32_t seed, void * out)
{
const int len = sizeof(uint64_t);
//now len is a compile time constant, and can be folded when this
//function is not inlined (else it would just be a constant input,
//which could only be folded when the function is inlined)
const uint8_t * data = (const uint8_t*)key;
const int nblocks = len / 16;如果您在以后的任何阶段使用C++,那么将其转换为模板将很有意义,如下所示:
template<const size_t len>
void MurmurHash3_x86_128_uint64 ( const void * key, uint32_t seed, void * out)
{
const uint8_t * data = (const uint8_t*)key;
const int nblocks = len / 16;还要注意,一些更智能的编译器(ICC、MSVC、GCC)会检测函数是否只使用相同的常量参数(包括部分常量参数列表)调用,并将这些常量合并到函数中(这需要启用“整个程序优化”选项)。
https://stackoverflow.com/questions/11046067
复制相似问题