2004-08-23 01:38:21 +00:00
|
|
|
//=============================
|
|
|
|
//David's hash tables
|
|
|
|
//string based.
|
|
|
|
|
2009-04-01 22:03:56 +00:00
|
|
|
#ifndef HASH_H__
|
|
|
|
#define HASH_H__
|
|
|
|
|
2010-07-11 02:22:39 +00:00
|
|
|
#define Hash_BytesForBuckets(b) (sizeof(bucket_t*)*b)
|
2004-08-23 01:38:21 +00:00
|
|
|
|
|
|
|
#define STRCMP(s1,s2) (((*s1)!=(*s2)) || strcmp(s1+1,s2+1)) //saves about 2-6 out of 120 - expansion of idea from fastqcc
|
|
|
|
typedef struct bucket_s {
|
|
|
|
void *data;
|
2007-09-17 20:35:39 +00:00
|
|
|
union {
|
2009-04-01 22:03:56 +00:00
|
|
|
const char *string;
|
2007-09-17 20:35:39 +00:00
|
|
|
int value;
|
|
|
|
} key;
|
2004-08-23 01:38:21 +00:00
|
|
|
struct bucket_s *next;
|
|
|
|
} bucket_t;
|
|
|
|
typedef struct hashtable_s {
|
|
|
|
int numbuckets;
|
|
|
|
bucket_t **bucket;
|
|
|
|
} hashtable_t;
|
|
|
|
|
|
|
|
void Hash_InitTable(hashtable_t *table, int numbucks, void *mem); //mem must be 0 filled. (memset(mem, 0, size))
|
2009-04-01 22:03:56 +00:00
|
|
|
int Hash_Key(const char *name, int modulus);
|
|
|
|
void *Hash_Get(hashtable_t *table, const char *name);
|
|
|
|
void *Hash_GetInsensative(hashtable_t *table, const char *name);
|
2004-08-23 01:38:21 +00:00
|
|
|
void *Hash_GetKey(hashtable_t *table, int key);
|
|
|
|
void *Hash_GetNext(hashtable_t *table, char *name, void *old);
|
2005-02-09 19:32:30 +00:00
|
|
|
void *Hash_GetNextInsensative(hashtable_t *table, char *name, void *old);
|
|
|
|
void *Hash_Add(hashtable_t *table, char *name, void *data, bucket_t *buck);
|
2004-12-05 16:32:44 +00:00
|
|
|
void *Hash_AddInsensative(hashtable_t *table, char *name, void *data, bucket_t *buck);
|
2004-08-23 01:38:21 +00:00
|
|
|
void Hash_Remove(hashtable_t *table, char *name);
|
|
|
|
void Hash_RemoveData(hashtable_t *table, char *name, void *data);
|
2005-03-01 15:36:23 +00:00
|
|
|
void Hash_RemoveKey(hashtable_t *table, int key);
|
|
|
|
void *Hash_AddKey(hashtable_t *table, int key, void *data, bucket_t *buck);
|
2009-04-01 22:03:56 +00:00
|
|
|
|
|
|
|
#endif
|