enhanced hash macros

This commit is contained in:
hyung-hwan 2019-03-05 12:06:13 +00:00
parent 0a405625ce
commit a02ad5005f
4 changed files with 42 additions and 33 deletions

View File

@ -4,7 +4,7 @@ pkgincludedir = $(includedir)/qse
pkginclude_HEADERS = \ pkginclude_HEADERS = \
conf-msw.h conf-os2.h conf-dos.h conf-vms.h conf-mac.h conf-inf.h \ 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 if ENABLE_CXX
pkginclude_HEADERS += \ pkginclude_HEADERS += \

View File

@ -136,9 +136,9 @@ am__can_run_installinfo = \
*) (install-info --version) >/dev/null 2>&1;; \ *) (install-info --version) >/dev/null 2>&1;; \
esac esac
am__pkginclude_HEADERS_DIST = conf-msw.h conf-os2.h conf-dos.h \ 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 \ conf-vms.h conf-mac.h conf-inf.h types.h macros.h hash.h \
unpack.h Types.hpp Growable.hpp Hashable.hpp Uncopyable.hpp \ pack1.h unpack.h Types.hpp Growable.hpp Hashable.hpp \
RefCounted.hpp Exception.hpp Cstr.hpp Uncopyable.hpp RefCounted.hpp Exception.hpp Cstr.hpp
am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
am__vpath_adj = case $$p in \ am__vpath_adj = case $$p in \
$(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
@ -382,7 +382,6 @@ pdfdir = @pdfdir@
prefix = @prefix@ prefix = @prefix@
program_transform_name = @program_transform_name@ program_transform_name = @program_transform_name@
psdir = @psdir@ psdir = @psdir@
runstatedir = @runstatedir@
sbindir = @sbindir@ sbindir = @sbindir@
sharedstatedir = @sharedstatedir@ sharedstatedir = @sharedstatedir@
srcdir = @srcdir@ srcdir = @srcdir@
@ -393,7 +392,7 @@ top_builddir = @top_builddir@
top_srcdir = @top_srcdir@ top_srcdir = @top_srcdir@
SUBDIRS = cmn cry si awk sed xli http rad dhcp sttp 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 \ 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) $(am__append_1)
all: config.h all: config.h
$(MAKE) $(AM_MAKEFLAGS) all-recursive $(MAKE) $(AM_MAKEFLAGS) all-recursive

View File

@ -30,13 +30,15 @@
#include <qse/types.h> #include <qse/types.h>
#include <qse/macros.h> #include <qse/macros.h>
#if MOO_SIZEOF_SIZE_T == 4 #if (QSE_SIZEOF_SIZE_T == 4)
# define QSE_HASH_FNV_MAGIC_INIT (0x811c9dc5) # define QSE_HASH_FNV_MAGIC_INIT (0x811c9dc5)
# define QSE_HASH_FNV_MAGIC_PRIME (0x01000193) # 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_INIT (0xCBF29CE484222325)
# define QSE_HASH_FNV_MAGIC_PRIME (0x100000001B3) # define QSE_HASH_FNV_MAGIC_PRIME (0x100000001B3l)
#elif MOO_SIZEOF_SIZE_T == 16
#elif (QSE_SIZEOF_SIZE_T == 16)
# define QSE_HASH_FNV_MAGIC_INIT (0x6C62272E07BB014262B821756295C58D) # define QSE_HASH_FNV_MAGIC_INIT (0x6C62272E07BB014262B821756295C58D)
# define QSE_HASH_FNV_MAGIC_PRIME (0x1000000000000000000013B) # define QSE_HASH_FNV_MAGIC_PRIME (0x1000000000000000000013B)
#endif #endif
@ -45,47 +47,56 @@
/* FNV-1 hash */ /* FNV-1 hash */
# define QSE_HASH_INIT QSE_HASH_FNV_MAGIC_INIT # define QSE_HASH_INIT QSE_HASH_FNV_MAGIC_INIT
# define QSE_HASH_VALUE(hv,v) (((hv) ^ (v)) * QSE_HASH_FNV_MAGIC_PRIME) # define QSE_HASH_VALUE(hv,v) (((hv) ^ (v)) * QSE_HASH_FNV_MAGIC_PRIME)
#else #else
/* SDBM hash */ /* SDBM hash */
# define QSE_HASH_INIT 0 # define QSE_HASH_INIT 0
# define QSE_HASH_VALUE(hv,v) (((hv) << 6) + ((hv) << 16) - (hv) + (v)) # define QSE_HASH_VALUE(hv,v) (((hv) << 6) + ((hv) << 16) - (hv) + (v))
#endif #endif
#define QSE_HASH_VALUES(hv, ptr, len, type) do { \ #define QSE_HASH_VPTL(hv, ptr, len, type) do { \
hv = QSE_HASH_INIT; \ hv = QSE_HASH_INIT; \
QSE_HASH_MORE_VALUES (hv, ptr, len, type); \ QSE_HASH_MORE_VPTL (hv, ptr, len, type); \
} while(0) } while(0)
#define QSE_HASH_MORE_VALUES(hv, ptr, len, type) do { \ #define QSE_HASH_MORE_VPTL(hv, ptr, len, type) do { \
type* p = (type*)(ptr); \ type* __qse_hash_more_values_p = (type*)(ptr); \
type* q = (type*)p + (len); \ type* __qse_hash_more_values_q = (type*)__qse_hash_more_values_p + (len); \
while (p < q) { hv = QSE_HASH_VALUE(hv, *p); p++; } \ 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) } while(0)
#define QSE_HASH_VSTR(hv, ptr, type) do { \ #define QSE_HASH_VPTR(hv, ptr, type) do { \
hv = QSE_HASH_INIT; \ hv = QSE_HASH_INIT; \
QSE_HASH_MORE_VALUES (hv, ptr, type); \ QSE_HASH_MORE_VPTL (hv, ptr, type); \
} while(0) } while(0)
#define QSE_HASH_MORE_VSTR(hv, ptr, type) do { \ #define QSE_HASH_MORE_VPTR(hv, ptr, type) do { \
type* p = (type*)(ptr); \ type* __qse_hash_more_values_p = (type*)(ptr); \
while (*p) { hv = QSE_HASH_VALUE(hv, *p); p++; } \ while (*__qse_hash_more_values_p) \
{ \
hv = QSE_HASH_VALUE(hv, *__qse_hash_more_values_p); \
__qse_hash_more_values_p++; \
} \
} while(0) } while(0)
#define QSE_HASH_BYTES(hv, ptr, len) QSE_HASH_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_VALUES(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_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_VALUES(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_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_VALUES(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_MBS(hv, ptr) QSE_HASH_VPTR(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_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_WCS(hv, ptr) QSE_HASH_VPTR(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_MORE_WCS(hv, ptr) QSE_HASH_MORE_VPTR(hv, ptr, const qse_wchar_t)
#endif #endif

View File

@ -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 qse_wcshash32 (const qse_wchar_t* p)
{ {
qse_uint32_t hash = FNV_MAGIC_INIT; qse_uint32_t hash = FNV_MAGIC_INIT;
while (*p) while (*p)