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

Make use of XXH3 for hashing

parent a3be0320
No related branches found
No related tags found
No related merge requests found
...@@ -8,7 +8,7 @@ stages: ...@@ -8,7 +8,7 @@ stages:
- test - test
before_script: before_script:
- apk update && apk add build-base meson glib - apk update && apk add build-base meson glib xxhash-dev
build: build:
stage: build stage: build
......
# SPDX-FileCopyrightText: 2018-2020 Bruce Cowan # SPDX-FileCopyrightText: 2018-2022 Bruce Cowan
#
# SPDX-License-Identifier: CC0-1.0 # SPDX-License-Identifier: CC0-1.0
project('stdlib', 'c', project('stdlib', 'c',
...@@ -11,6 +12,7 @@ libm = cc.find_library('m') ...@@ -11,6 +12,7 @@ libm = cc.find_library('m')
glib_dep = dependency('glib-2.0', version: '>= 2.16', required: false) glib_dep = dependency('glib-2.0', version: '>= 2.16', required: false)
openmp_dep = dependency('openmp', required: false) openmp_dep = dependency('openmp', required: false)
thread_dep = dependency('threads', required: false) thread_dep = dependency('threads', required: false)
xxhash_dep = dependency('libxxhash', required: false)
conf_data = configuration_data() conf_data = configuration_data()
......
/* /*
* SPDX-FileCopyrightText: 2018, 2019 Bruce Cowan <bruce@bcowan.me.uk> * SPDX-FileCopyrightText: 2018-2022 Bruce Cowan <bruce@bcowan.me.uk>
* *
* SPDX-License-Identifier: GPL-3.0-or-later * SPDX-License-Identifier: GPL-3.0-or-later
*/ */
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <xxhash.h>
#include <hashtable.h> #include <hashtable.h>
static void static void
...@@ -42,8 +44,10 @@ print_all (void *key, ...@@ -42,8 +44,10 @@ print_all (void *key,
static unsigned static unsigned
str_hash (const void *data) str_hash (const void *data)
{ {
const char *str = (const char *) data; size_t length = strlen ((const char *) data);
return (unsigned) str[0];
XXH64_hash_t hash = XXH3_64bits (data, length);
return (unsigned) (hash ^ (hash >> 32));
} }
static bool static bool
......
# SPDX-FileCopyrightText: 2018-2020 Bruce Cowan <bruce@bcowan.me.uk> # SPDX-FileCopyrightText: 2018-2022 Bruce Cowan <bruce@bcowan.me.uk>
#
# SPDX-License-Identifier: CC0-1.0 # SPDX-License-Identifier: CC0-1.0
executable('add', 'add.c', dependencies: utils_dep) executable('add', 'add.c', dependencies: utils_dep)
...@@ -15,7 +16,6 @@ executable('fixed-sizeof', 'fixed-sizeof.c') ...@@ -15,7 +16,6 @@ executable('fixed-sizeof', 'fixed-sizeof.c')
executable('fgets', 'fgets.c') executable('fgets', 'fgets.c')
executable('gcd', 'gcd.c') executable('gcd', 'gcd.c')
executable('getchar', 'getchar.c') executable('getchar', 'getchar.c')
executable('hashtable-test', 'hashtable-test.c', dependencies: utils_dep)
executable('kepler', 'kepler.c', dependencies: libm) executable('kepler', 'kepler.c', dependencies: libm)
executable('list-test', 'list-test.c', dependencies: utils_dep) executable('list-test', 'list-test.c', dependencies: utils_dep)
executable('next', 'next.c', dependencies: libm) executable('next', 'next.c', dependencies: libm)
...@@ -38,9 +38,13 @@ if host_machine.cpu_family() == 'x86_64' and cc.has_function_attribute('ifunc') ...@@ -38,9 +38,13 @@ if host_machine.cpu_family() == 'x86_64' and cc.has_function_attribute('ifunc')
endif endif
if openmp_dep.found() if openmp_dep.found()
subdir('openmp') subdir('openmp')
endif endif
if thread_dep.found() if thread_dep.found()
subdir('pthread') subdir('pthread')
endif
if xxhash_dep.found()
executable('hashtable-test', 'hashtable-test.c', dependencies: [utils_dep, xxhash_dep])
endif 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