diff --git a/engine/qclib/hash.c b/engine/qclib/hash.c index 7fc6e440e..9d129d703 100644 --- a/engine/qclib/hash.c +++ b/engine/qclib/hash.c @@ -13,6 +13,19 @@ int Hash_Key(char *name, int modulus) return (int)(key%modulus); } +int Hash_KeyInsensative(char *name, int modulus) +{ //fixme: optimize. + unsigned int key; + for (key=0;*name; name++) + { + if (*name >= 'A' && *name <= 'Z') + key += ((key<<3) + (key>>28) + (*name-'A'+'a')); + else + key += ((key<<3) + (key>>28) + *name); + } + + return (int)(key%modulus); +} void *Hash_Get(hashtable_t *table, char *name) { @@ -30,6 +43,22 @@ void *Hash_Get(hashtable_t *table, char *name) } return NULL; } +void *Hash_GetInsensative(hashtable_t *table, char *name) +{ + int bucknum = Hash_Key(name, table->numbuckets); + bucket_t *buck; + + buck = table->bucket[bucknum]; + + while(buck) + { + if (!stricmp(name, buck->keystring)) + return buck->data; + + buck = buck->next; + } + return NULL; +} void *Hash_GetKey(hashtable_t *table, int key) { int bucknum = key%table->numbuckets; @@ -104,6 +133,17 @@ void *Hash_Add2(hashtable_t *table, char *name, void *data, bucket_t *buck) return buck; } +void *Hash_AddInsensative(hashtable_t *table, char *name, void *data, bucket_t *buck) +{ + int bucknum = Hash_KeyInsensative(name, table->numbuckets); + + buck->data = data; + buck->keystring = name; + buck->next = table->bucket[bucknum]; + table->bucket[bucknum] = buck; + + return buck; +} #ifndef MINIMAL void *Hash_AddKey(hashtable_t *table, int key, void *data) { diff --git a/engine/qclib/hash.h b/engine/qclib/hash.h index d5d8fb125..ee488197a 100644 --- a/engine/qclib/hash.h +++ b/engine/qclib/hash.h @@ -18,10 +18,12 @@ typedef struct hashtable_s { void Hash_InitTable(hashtable_t *table, int numbucks, void *mem); //mem must be 0 filled. (memset(mem, 0, size)) int Hash_Key(char *name, int modulus); void *Hash_Get(hashtable_t *table, char *name); +void *Hash_GetInsensative(hashtable_t *table, char *name); void *Hash_GetKey(hashtable_t *table, int key); void *Hash_GetNext(hashtable_t *table, char *name, void *old); void *Hash_Add(hashtable_t *table, char *name, void *data); void *Hash_Add2(hashtable_t *table, char *name, void *data, bucket_t *buck); +void *Hash_AddInsensative(hashtable_t *table, char *name, void *data, bucket_t *buck); void *Hash_AddKey(hashtable_t *table, int key, void *data); void Hash_Remove(hashtable_t *table, char *name); void Hash_RemoveData(hashtable_t *table, char *name, void *data);