XXH64功能在调试模式和释放模式下具有不同的值

时间:2017-11-30 09:51:57

标签: hash release-mode debug-mode

XXH_PUBLIC_API unsigned long long XXH64(const void* input, size_t len, unsigned long long seed)
{
#if 0
    /* Simple version, good for code maintenance, but unfortunately slow for small inputs */
    XXH64_state_t state;
    XXH64_reset(&state, seed);
    XXH64_update(&state, input, len);
    return XXH64_digest(&state);
#else
    XXH_endianess endian_detected = (XXH_endianess)XXH_CPU_LITTLE_ENDIAN;

    if (XXH_FORCE_ALIGN_CHECK) {
        if ((((size_t)input) & 7) == 0) {  /* Input is aligned, let's leverage the speed advantage */
            if ((endian_detected == XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT)
                return XXH64_endian_align(input, len, seed, XXH_littleEndian, XXH_aligned);
            else
                return XXH64_endian_align(input, len, seed, XXH_bigEndian, XXH_aligned);
        }
    }

    if ((endian_detected == XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT)
        return XXH64_endian_align(input, len, seed, XXH_littleEndian, XXH_unaligned);
    else
        return XXH64_endian_align(input, len, seed, XXH_bigEndian, XXH_unaligned);
#endif
}

这是XXH64哈希函数(http://www.opensource.org/licenses/bsd-license.php

当我在释放模式和调试模式下运行代码时

char buf[65];
unsigned int hash2 = 0;

sprintf(buf, "%I64u", (unsigned long long)_message);

unsigned long long hash = XXH64(buf,sizeof(buf)-1,0);
hash = hash % _n;
hash2 = (unsigned int)hash;
printf("message's hash value : %u \n", hash2);

每种模式都有不同的哈希值和相同的代码。

0 个答案:

没有答案