From 35267fc801b63b399f6b1d6f474612af491f9afe Mon Sep 17 00:00:00 2001 From: Baptiste Daroussin Date: Tue, 18 Aug 2015 17:07:05 +0200 Subject: [PATCH] Convert to use XXHASH --- libpkg/Makefile.am | 1 + libpkg/private/pkg.h | 14 +++++++++----- libpkg/private/utils.h | 2 +- libpkg/utils.c | 26 ++++++++++++++++++++++++++ 4 files changed, 37 insertions(+), 6 deletions(-) diff --git a/libpkg/Makefile.am b/libpkg/Makefile.am index cb7c129..bf6231f 100644 --- a/libpkg/Makefile.am +++ b/libpkg/Makefile.am @@ -8,6 +8,7 @@ pkg_common_cflags= -I$(top_srcdir)/libpkg -I$(top_builddir)/libpkg \ -I$(top_srcdir)/external/expat/lib \ -I$(top_srcdir)/external/libucl/include \ -I$(top_srcdir)/external/libucl/klib \ + -I$(top_srcdir)/external/libucl/src \ -I$(top_srcdir)/external/picosat \ -I$(top_srcdir)/external/uthash \ -I$(top_srcdir)/external/sqlite \ diff --git a/libpkg/private/pkg.h b/libpkg/private/pkg.h index 3852042..ff4ba98 100644 --- a/libpkg/private/pkg.h +++ b/libpkg/private/pkg.h @@ -92,6 +92,7 @@ ARCHIVE_EXTRACT_TIME | ARCHIVE_EXTRACT_ACL | \ ARCHIVE_EXTRACT_FFLAGS|ARCHIVE_EXTRACT_XATTR) + #define HASH_FREE(data, free_func) do { \ __typeof(data) hf1, hf2; \ HASH_ITER(hh, data, hf1, hf2) { \ @@ -121,6 +122,9 @@ return (EPKG_OK); \ } while (0) +#define KHASH_MAP_INIT_STRING(name, khval_t) \ + KHASH_INIT(name, kh_cstr_t, khval_t, 1, string_hash_func, kh_str_hash_equal) + #define kh_string_next(head, data) do { \ khint_t k; \ if (head == NULL) \ @@ -198,11 +202,11 @@ struct pkg_repo_it; struct pkg_repo; struct pkg_message; -KHASH_MAP_INIT_STR(pkg_deps, struct pkg_dep *); -KHASH_MAP_INIT_STR(pkg_files, struct pkg_file *); -KHASH_MAP_INIT_STR(pkg_dirs, struct pkg_dir *); -KHASH_MAP_INIT_STR(pkg_config_files, struct pkg_config_file *); -KHASH_MAP_INIT_STR(strings, char *); +KHASH_MAP_INIT_STRING(pkg_deps, struct pkg_dep *); +KHASH_MAP_INIT_STRING(pkg_files, struct pkg_file *); +KHASH_MAP_INIT_STRING(pkg_dirs, struct pkg_dir *); +KHASH_MAP_INIT_STRING(pkg_config_files, struct pkg_config_file *); +KHASH_MAP_INIT_STRING(strings, char *); struct pkg { bool direct; diff --git a/libpkg/private/utils.h b/libpkg/private/utils.h index b357338..d839ee8 100644 --- a/libpkg/private/utils.h +++ b/libpkg/private/utils.h @@ -67,7 +67,7 @@ struct rsa_key { RSA *key; }; - +int32_t string_hash_func(const char *); void sbuf_init(struct sbuf **); int sbuf_set(struct sbuf **, const char *); void sbuf_reset(struct sbuf *); diff --git a/libpkg/utils.c b/libpkg/utils.c index 756ef0a..337625e 100644 --- a/libpkg/utils.c +++ b/libpkg/utils.c @@ -46,6 +46,7 @@ #include #include #include +#include #include @@ -53,6 +54,31 @@ #include "private/event.h" #include "private/utils.h" +int64_t +pkg_hash_seed(void) +{ + static int64_t seed = 0; + + if (seed == 0) + seed = time(NULL); + return (seed); +} + +#if (defined(WORD_BIT) && WORD_BIT == 64) || \ + (defined(__WORDSIZE) && __WORDSIZE == 64) || \ + defined(__x86_64__) || \ + defined(__amd64__) +#define XXHASHIMPL XXH64 +#else +#define XXHASHIMPL XXH32 +#endif + +int32_t +string_hash_func(const char *key) +{ + return (XXHASHIMPL(key, strlen(key), pkg_hash_seed())); +} + void sbuf_init(struct sbuf **buf) { -- 2.4.6