Skip to content

Commit

Permalink
Added string hash/compare functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Apr 5, 2009
1 parent 0161f62 commit a6d2ae0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
16 changes: 16 additions & 0 deletions mojoshader_common.c
Expand Up @@ -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 ...

2 changes: 2 additions & 0 deletions mojoshader_internal.h
Expand Up @@ -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'
Expand Down

0 comments on commit a6d2ae0

Please sign in to comment.