]> git.xonotic.org Git - voretournament/voretournament.git/blob - misc/mediasource/fteqcc-src/hash.h
Move all other sources in a separate subfolder
[voretournament/voretournament.git] / misc / mediasource / fteqcc-src / hash.h
1 //=============================
2 //David's hash tables
3 //string based.
4
5 #ifndef HASH_H__
6 #define HASH_H__
7
8 #define Hash_BytesForBuckets(b) (sizeof(bucket_t)*b)
9
10 #define STRCMP(s1,s2) (((*s1)!=(*s2)) || strcmp(s1+1,s2+1))     //saves about 2-6 out of 120 - expansion of idea from fastqcc
11 typedef struct bucket_s {
12         void *data;
13         union {
14                 const char *string;
15                 int value;
16         } key;
17         struct bucket_s *next;
18 } bucket_t;
19 typedef struct hashtable_s {
20         int numbuckets;
21         bucket_t **bucket;
22 } hashtable_t;
23
24 void Hash_InitTable(hashtable_t *table, int numbucks, void *mem);       //mem must be 0 filled. (memset(mem, 0, size))
25 int Hash_Key(const char *name, int modulus);
26 void *Hash_Get(hashtable_t *table, const char *name);
27 void *Hash_GetInsensative(hashtable_t *table, const char *name);
28 void *Hash_GetKey(hashtable_t *table, int key);
29 void *Hash_GetNext(hashtable_t *table, char *name, void *old);
30 void *Hash_GetNextInsensative(hashtable_t *table, char *name, void *old);
31 void *Hash_Add(hashtable_t *table, char *name, void *data, bucket_t *buck);
32 void *Hash_AddInsensative(hashtable_t *table, char *name, void *data, bucket_t *buck);
33 void Hash_Remove(hashtable_t *table, char *name);
34 void Hash_RemoveData(hashtable_t *table, char *name, void *data);
35 void Hash_RemoveKey(hashtable_t *table, int key);
36 void *Hash_AddKey(hashtable_t *table, int key, void *data, bucket_t *buck);
37
38 #endif