File: hash.h

package info (click to toggle)
fteqcc 3343-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 988 kB
  • ctags: 2,030
  • sloc: ansic: 22,826; makefile: 57
file content (33 lines) | stat: -rwxr-xr-x 1,332 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
//=============================
//David's hash tables
//string based.

#define Hash_BytesForBuckets(b) (sizeof(bucket_t)*b)

#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;
	union {
		char *string;
		int value;
	} key;
	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))
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_GetNextInsensative(hashtable_t *table, char *name, void *old);
void *Hash_Add(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_Remove(hashtable_t *table, char *name);
void Hash_RemoveData(hashtable_t *table, char *name, void *data);
void Hash_RemoveKey(hashtable_t *table, int key);
void *Hash_AddKey(hashtable_t *table, int key, void *data, bucket_t *buck);