From a02ad5005fd61b3eacbda7f60da97240e01312e6 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Tue, 5 Mar 2019 12:06:13 +0000 Subject: [PATCH] enhanced hash macros --- qse/include/qse/Makefile.am | 2 +- qse/include/qse/Makefile.in | 9 +++--- qse/include/qse/hash.h | 61 ++++++++++++++++++++++--------------- qse/lib/cmn/htl.c | 3 +- 4 files changed, 42 insertions(+), 33 deletions(-) diff --git a/qse/include/qse/Makefile.am b/qse/include/qse/Makefile.am index 82ef73dd..d31fbc67 100644 --- a/qse/include/qse/Makefile.am +++ b/qse/include/qse/Makefile.am @@ -4,7 +4,7 @@ pkgincludedir = $(includedir)/qse pkginclude_HEADERS = \ conf-msw.h conf-os2.h conf-dos.h conf-vms.h conf-mac.h conf-inf.h \ - types.h macros.h pack1.h unpack.h + types.h macros.h hash.h pack1.h unpack.h if ENABLE_CXX pkginclude_HEADERS += \ diff --git a/qse/include/qse/Makefile.in b/qse/include/qse/Makefile.in index aa277529..6ac25b00 100644 --- a/qse/include/qse/Makefile.in +++ b/qse/include/qse/Makefile.in @@ -136,9 +136,9 @@ am__can_run_installinfo = \ *) (install-info --version) >/dev/null 2>&1;; \ esac am__pkginclude_HEADERS_DIST = conf-msw.h conf-os2.h conf-dos.h \ - conf-vms.h conf-mac.h conf-inf.h types.h macros.h pack1.h \ - unpack.h Types.hpp Growable.hpp Hashable.hpp Uncopyable.hpp \ - RefCounted.hpp Exception.hpp Cstr.hpp + conf-vms.h conf-mac.h conf-inf.h types.h macros.h hash.h \ + pack1.h unpack.h Types.hpp Growable.hpp Hashable.hpp \ + Uncopyable.hpp RefCounted.hpp Exception.hpp Cstr.hpp am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; am__vpath_adj = case $$p in \ $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ @@ -382,7 +382,6 @@ pdfdir = @pdfdir@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ -runstatedir = @runstatedir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ @@ -393,7 +392,7 @@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ SUBDIRS = cmn cry si awk sed xli http rad dhcp sttp pkginclude_HEADERS = conf-msw.h conf-os2.h conf-dos.h conf-vms.h \ - conf-mac.h conf-inf.h types.h macros.h pack1.h unpack.h \ + conf-mac.h conf-inf.h types.h macros.h hash.h pack1.h unpack.h \ $(am__append_1) all: config.h $(MAKE) $(AM_MAKEFLAGS) all-recursive diff --git a/qse/include/qse/hash.h b/qse/include/qse/hash.h index 5461e486..b43e3960 100644 --- a/qse/include/qse/hash.h +++ b/qse/include/qse/hash.h @@ -30,13 +30,15 @@ #include #include -#if MOO_SIZEOF_SIZE_T == 4 +#if (QSE_SIZEOF_SIZE_T == 4) # define QSE_HASH_FNV_MAGIC_INIT (0x811c9dc5) # define QSE_HASH_FNV_MAGIC_PRIME (0x01000193) -#elif MOO_SIZEOF_SIZE_T == 8 +#elif (QSE_SIZEOF_SIZE_T == 8) + # define QSE_HASH_FNV_MAGIC_INIT (0xCBF29CE484222325) -# define QSE_HASH_FNV_MAGIC_PRIME (0x100000001B3) -#elif MOO_SIZEOF_SIZE_T == 16 +# define QSE_HASH_FNV_MAGIC_PRIME (0x100000001B3l) + +#elif (QSE_SIZEOF_SIZE_T == 16) # define QSE_HASH_FNV_MAGIC_INIT (0x6C62272E07BB014262B821756295C58D) # define QSE_HASH_FNV_MAGIC_PRIME (0x1000000000000000000013B) #endif @@ -45,47 +47,56 @@ /* FNV-1 hash */ # define QSE_HASH_INIT QSE_HASH_FNV_MAGIC_INIT # define QSE_HASH_VALUE(hv,v) (((hv) ^ (v)) * QSE_HASH_FNV_MAGIC_PRIME) + #else /* SDBM hash */ # define QSE_HASH_INIT 0 # define QSE_HASH_VALUE(hv,v) (((hv) << 6) + ((hv) << 16) - (hv) + (v)) #endif -#define QSE_HASH_VALUES(hv, ptr, len, type) do { \ +#define QSE_HASH_VPTL(hv, ptr, len, type) do { \ hv = QSE_HASH_INIT; \ - QSE_HASH_MORE_VALUES (hv, ptr, len, type); \ + QSE_HASH_MORE_VPTL (hv, ptr, len, type); \ } while(0) -#define QSE_HASH_MORE_VALUES(hv, ptr, len, type) do { \ - type* p = (type*)(ptr); \ - type* q = (type*)p + (len); \ - while (p < q) { hv = QSE_HASH_VALUE(hv, *p); p++; } \ +#define QSE_HASH_MORE_VPTL(hv, ptr, len, type) do { \ + type* __qse_hash_more_values_p = (type*)(ptr); \ + type* __qse_hash_more_values_q = (type*)__qse_hash_more_values_p + (len); \ + while (__qse_hash_more_values_p < __qse_hash_more_values_q) \ + { \ + hv = QSE_HASH_VALUE(hv, *__qse_hash_more_values_p); \ + __qse_hash_more_values_p++; \ + } \ } while(0) -#define QSE_HASH_VSTR(hv, ptr, type) do { \ +#define QSE_HASH_VPTR(hv, ptr, type) do { \ hv = QSE_HASH_INIT; \ - QSE_HASH_MORE_VALUES (hv, ptr, type); \ + QSE_HASH_MORE_VPTL (hv, ptr, type); \ } while(0) -#define QSE_HASH_MORE_VSTR(hv, ptr, type) do { \ - type* p = (type*)(ptr); \ - while (*p) { hv = QSE_HASH_VALUE(hv, *p); p++; } \ +#define QSE_HASH_MORE_VPTR(hv, ptr, type) do { \ + type* __qse_hash_more_values_p = (type*)(ptr); \ + while (*__qse_hash_more_values_p) \ + { \ + hv = QSE_HASH_VALUE(hv, *__qse_hash_more_values_p); \ + __qse_hash_more_values_p++; \ + } \ } while(0) -#define QSE_HASH_BYTES(hv, ptr, len) QSE_HASH_VALUES(hv, ptr, len, const qse_uint8_t) -#define QSE_HASH_MORE_BYTES(hv, ptr, len) QSE_HASH_MORE_VALUES(hv, ptr, len, const qse_uint8_t) +#define QSE_HASH_BYTES(hv, ptr, len) QSE_HASH_VPTL(hv, ptr, len, const qse_uint8_t) +#define QSE_HASH_MORE_BYTES(hv, ptr, len) QSE_HASH_MORE_VPTL(hv, ptr, len, const qse_uint8_t) -#define QSE_HASH_MCHARS(hv, ptr, len) QSE_HASH_VALUES(hv, ptr, len, const qse_mchar_t) -#define QSE_HASH_MORE_MCHARS(hv, ptr, len) QSE_HASH_MORE_VALUES(hv, ptr, len, const qse_mchar_t) +#define QSE_HASH_MCHARS(hv, ptr, len) QSE_HASH_VPTL(hv, ptr, len, const qse_mchar_t) +#define QSE_HASH_MORE_MCHARS(hv, ptr, len) QSE_HASH_MORE_VPTL(hv, ptr, len, const qse_mchar_t) -#define QSE_HASH_WCHARS(hv, ptr, len) QSE_HASH_VALUES(hv, ptr, len, const qse_wchar_t) -#define QSE_HASH_MORE_WCHARS(hv, ptr, len) QSE_HASH_MORE_VALUES(hv, ptr, len, const qse_wchar_t) +#define QSE_HASH_WCHARS(hv, ptr, len) QSE_HASH_VPTL(hv, ptr, len, const qse_wchar_t) +#define QSE_HASH_MORE_WCHARS(hv, ptr, len) QSE_HASH_MORE_VPTL(hv, ptr, len, const qse_wchar_t) -#define QSE_HASH_MBS(hv, ptr) QSE_HASH_VSTR(hv, ptr, const qse_mchar_t) -#define QSE_HASH_MORE_MBS(hv, ptr) QSE_HASH_MORE_VSTR(hv, ptr, const qse_mchar_t) +#define QSE_HASH_MBS(hv, ptr) QSE_HASH_VPTR(hv, ptr, const qse_mchar_t) +#define QSE_HASH_MORE_MBS(hv, ptr) QSE_HASH_MORE_VPTR(hv, ptr, const qse_mchar_t) -#define QSE_HASH_WCS(hv, ptr) QSE_HASH_VSTR(hv, ptr, const qse_wchar_t) -#define QSE_HASH_MORE_WCS(hv, ptr) QSE_HASH_MORE_VSTR(hv, ptr, const qse_wchar_t) +#define QSE_HASH_WCS(hv, ptr) QSE_HASH_VPTR(hv, ptr, const qse_wchar_t) +#define QSE_HASH_MORE_WCS(hv, ptr) QSE_HASH_MORE_VPTR(hv, ptr, const qse_wchar_t) #endif diff --git a/qse/lib/cmn/htl.c b/qse/lib/cmn/htl.c index 1db0aa98..6b8c5866 100644 --- a/qse/lib/cmn/htl.c +++ b/qse/lib/cmn/htl.c @@ -864,7 +864,6 @@ qse_uint32_t qse_mbshash32 (const qse_mchar_t* p) qse_uint32_t qse_wcshash32 (const qse_wchar_t* p) { - qse_uint32_t hash = FNV_MAGIC_INIT; while (*p) @@ -908,7 +907,7 @@ qse_uint32_t qse_wcscasehash32 (const qse_wchar_t* p) hash ^= (qse_uint32_t)(wc); hash *= FNV_MAGIC_PRIME; #else - hash = qse_genhash_update (&wc, QSE_SIZEOF(wc), hash); + hash = qse_genhash_update(&wc, QSE_SIZEOF(wc), hash); #endif }