Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Convert to use XXHASH
Baptiste Daroussin committed 10 years ago
commit 35267fc801b63b399f6b1d6f474612af491f9afe
parent 6aa37c8
4 files changed +37 -6
modified 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 \
modified 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;
modified 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 *);
modified libpkg/utils.c
@@ -46,6 +46,7 @@
#include <paths.h>
#include <float.h>
#include <math.h>
+
#include <xxhash.h>

#include <bsd_compat.h>

@@ -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)
{