A minimal hash function for C?

后端 未结 6 533
攒了一身酷
攒了一身酷 2021-01-29 23:41

I can\'t use boost:hash because I have to stick with C and can\'t use C++.

But, I need to hash a large number (10K to 100k) of tokens strings (5 to 40 bytes length) so t

6条回答
  •  迷失自我
    2021-01-30 00:00

    xxhash is quite fast and easy option. A simple code would use XXH32 function:

    unsigned int XXH32 (const void* input, int len, unsigned int seed);
    

    It is 32 bit hash. Since len is int, for larger data more than 2^31-1 bytes use these:

    void*         XXH32_init   (unsigned int seed);
    XXH_errorcode XXH32_update (void* state, const void* input, int len);
    unsigned int  XXH32_digest (void* state);
    

提交回复
热议问题