1) tweak hash tables
[IRC.git] / Robust / src / Runtime / DSTM / interface / clookup.h
1 #ifndef _CLOOKUP_H_
2 #define _CLOOKUP_H_
3
4 #include <stdlib.h>
5 #include <stdio.h>
6
7 #define CLOADFACTOR 0.25
8 #define CHASH_SIZE 1024
9
10 typedef struct chashlistnode {
11   unsigned int key;
12   void *val;       //this can be cast to another type or used to point to a larger structure
13   struct chashlistnode *next;
14 } chashlistnode_t;
15
16 typedef struct chashtable {
17   chashlistnode_t *table;       // points to beginning of hash table
18   unsigned int size;
19   unsigned int mask;
20   unsigned int numelements;
21   unsigned int threshold;
22   double loadfactor;
23 } chashtable_t;
24
25 /* Prototypes for hash*/
26 chashtable_t *chashCreate(unsigned int size, double loadfactor);
27 static unsigned int chashFunction(chashtable_t *table, unsigned int key);
28 unsigned int chashInsert(chashtable_t *table, unsigned int key, void *val);
29 void *chashSearch(chashtable_t *table, unsigned int key); //returns val, NULL if not found
30 unsigned int chashRemove(chashtable_t *table, unsigned int key); //returns -1 if not found
31 void * chashRemove2(chashtable_t *table, unsigned int key); //returns -1 if not found
32 unsigned int chashResize(chashtable_t *table, unsigned int newsize);
33 void chashDelete(chashtable_t *table);
34 /* end hash */
35
36 #endif
37