mirror of
https://github.com/nzp-team/fteqw.git
synced 2024-11-10 14:42:13 +00:00
Hash tables now have a case insensative option. (it acts as lowercase - don't mix them)
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@575 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
parent
eac52dedf2
commit
a82e237add
2 changed files with 42 additions and 0 deletions
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue