From a6d2ae04aa937a0bb708be74009ce497d576666b Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Sun, 5 Apr 2009 03:32:33 -0400 Subject: [PATCH] Added string hash/compare functions. --- mojoshader_common.c | 16 ++++++++++++++++ mojoshader_internal.h | 2 ++ 2 files changed, 18 insertions(+) diff --git a/mojoshader_common.c b/mojoshader_common.c index 07b580e6..a877bdb9 100644 --- a/mojoshader_common.c +++ b/mojoshader_common.c @@ -134,5 +134,21 @@ int hash_remove(HashTable *table, const void *key) return 0; } // hash_remove + +// this is djb's xor hashing function. +uint32 hash_hash_string(const void *_sym) +{ + register const char *sym = (const char *) _sym; + register uint32 hash = 5381; + while (*sym) + hash = ((hash << 5) + hash) ^ *(sym++); + return hash; +} // hash_hash_string + +int hash_keymatch_string(const void *a, const void *b) +{ + return (strcmp((const char *) a, (const char *) b) == 0); +} // hash_keymatch_string + // end of mojoshader_common.c ... diff --git a/mojoshader_internal.h b/mojoshader_internal.h index 1c9491e8..c478dee8 100644 --- a/mojoshader_internal.h +++ b/mojoshader_internal.h @@ -143,6 +143,8 @@ int hash_insert(HashTable *table, const void *key, const void *value); int hash_remove(HashTable *table, const void *key); int hash_find(const HashTable *table, const void *key, const void **_value); +uint32 hash_hash_string(const void *sym); +int hash_keymatch_string(const void *a, const void *b); // This is the ID for a D3DXSHADER_CONSTANTTABLE in the bytecode comments. #define CTAB_ID 0x42415443 // 0x42415443 == 'CTAB'