Skip to content
Snippets Groups Projects
Verified Commit 6ae08640 authored by Bruce Cowan's avatar Bruce Cowan :airplane:
Browse files

Handle different unsigned sizes for hash function

parent 4c22ddf7
No related branches found
No related tags found
No related merge requests found
......@@ -4,6 +4,8 @@
* SPDX-License-Identifier: Apache-2.0
*/
#include "config.h"
#include "hash.h"
#include <string.h>
......@@ -16,13 +18,26 @@ str_hash (const void *data)
size_t length = strlen ((const char *) data);
XXH64_hash_t hash = XXH3_64bits (data, length);
return (unsigned) (hash ^ (hash >> 32));
#if (SIZEOF_UNSIGNED == 2)
unsigned ret = hash & 0xffff;
ret ^= (unsigned) (hash >> 16 & 0xffff);
ret ^= (unsigned) (hash >> 32 & 0xffff);
ret ^= (unsigned) (hash >> 48 & 0xffff);
return ret;
#elif (SIZEOF_UNSIGNED == 4)
return (hash & 0xffffffff) ^ (hash >> 32 & 0xffffffff);
#elif (SIZEOF_UNSIGNED == 8)
return (unsigned) hash;
#else
# error "Unsupported unsigned integer size"
#endif
}
bool
str_equal (const void *a,
const void *b)
{
return !strcmp (a, b);
return !strcmp ((const char *) a, (const char *) b);
}
......@@ -16,6 +16,8 @@ xxhash_dep = dependency('libxxhash')
conf_data = configuration_data()
conf_data.set('SIZEOF_UNSIGNED', cc.sizeof('unsigned'))
if cc.has_function('reallocarray', prefix: '#define _GNU_SOURCE\n#include <stdlib.h>')
conf_data.set('HAVE_REALLOCARRAY', 1)
endif
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment