mirror of
https://github.com/DrBeef/Raze.git
synced 2024-11-15 08:52:00 +00:00
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
This commit is contained in:
parent
073987fa42
commit
022eb02c5e
2 changed files with 23 additions and 23 deletions
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue