Skip to content
Permalink
Browse files
Added string hash/compare functions.
  • Loading branch information
icculus committed Apr 5, 2009
1 parent 0161f62 commit a6d2ae04aa937a0bb708be74009ce497d576666b
Showing with 18 additions and 0 deletions.
  1. +16 −0 mojoshader_common.c
  2. +2 −0 mojoshader_internal.h
@@ -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 ...

@@ -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'

0 comments on commit a6d2ae0

Please sign in to comment.