From 022eb02c5ee70f33f8cd0245fc8de796b1aa6afb Mon Sep 17 00:00:00 2001 From: terminx Date: Sun, 18 Nov 2018 18:12:28 +0000 Subject: [PATCH] Move hash_getcode() and inthash_getcode() to hash.h so they can be used in places other than hash.cpp git-svn-id: https://svn.eduke32.com/eduke32@7213 1a8010ca-5511-0410-912e-c29ae57300e0 --- source/build/include/hash.h | 23 +++++++++++++++++++++++ source/build/src/hash.cpp | 23 ----------------------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/source/build/include/hash.h b/source/build/include/hash.h index e36e61f0b..a5e23b4f3 100644 --- a/source/build/include/hash.h +++ b/source/build/include/hash.h @@ -23,6 +23,18 @@ typedef struct hashitem_t **items; } hashtable_t; +// djb3 algorithm +static inline uint32_t hash_getcode(const char *s) +{ + uint32_t h = 5381; + int32_t ch; + + while ((ch = *s++) != '\0') + h = ((h << 5) + h) ^ ch; + + return h; +} + void hash_init(hashtable_t *t); void hash_loop(hashtable_t *t, void(*func)(const char *, intptr_t)); void hash_free(hashtable_t *t); @@ -48,6 +60,17 @@ typedef struct uint32_t count; } inthashtable_t; +// djb3 algorithm +static inline uint32_t inthash_getcode(intptr_t key) +{ + uint32_t h = 5381; + + for (uint8_t const * keybuf = (uint8_t *) &key, *const keybuf_end = keybuf + sizeof(intptr_t); keybuf < keybuf_end; ++keybuf) + h = ((h << 5) + h) ^ (uint32_t) *keybuf; + + return h; +} + void inthash_init(inthashtable_t *t); void inthash_loop(inthashtable_t const *t, void(*func)(intptr_t, intptr_t)); void inthash_free(inthashtable_t *t); diff --git a/source/build/src/hash.cpp b/source/build/src/hash.cpp index 023cd0769..5cd2eccaa 100644 --- a/source/build/src/hash.cpp +++ b/source/build/src/hash.cpp @@ -43,18 +43,6 @@ void hash_free(hashtable_t *t) DO_FREE_AND_NULL(t->items); } -// djb3 algorithm -static inline uint32_t hash_getcode(const char *s) -{ - uint32_t h = 5381; - int32_t ch; - - while ((ch = *s++) != '\0') - h = ((h << 5) + h) ^ ch; - - return h; -} - void hash_add(hashtable_t *t, const char *s, intptr_t key, int32_t replace) { #ifdef DEBUGGINGAIDS @@ -224,17 +212,6 @@ void inthash_free(inthashtable_t *t) DO_FREE_AND_NULL(t->items); } -// djb3 algorithm -static inline uint32_t inthash_getcode(intptr_t key) -{ - uint32_t h = 5381; - - for (uint8_t const * keybuf = (uint8_t *) &key, *const keybuf_end = keybuf + sizeof(intptr_t); keybuf < keybuf_end; ++keybuf) - h = ((h << 5) + h) ^ (uint32_t) *keybuf; - - return h; -} - void inthash_add(inthashtable_t *t, intptr_t key, intptr_t value, int32_t replace) { #ifdef DEBUGGINGAIDS