d85fbd03871f2bab218bf5ca7e8be9df26ab9e85
[IRC.git] / Robust / src / Runtime / chash.h
1 #ifndef _CHASH_H_
2 #define _CHASH_H_
3
4 #include <stdlib.h>
5 #include <stdio.h>
6
7 typedef struct cnode {
8   unsigned int key;
9   void *val;       //this can be cast to another type or used to point to a larger structure
10   struct cnode *next;
11   struct cnode *lnext;
12 } cnode_t;
13
14 typedef struct ctable {
15   cnode_t *table;       // points to beginning of hash table
16   unsigned int size;
17   unsigned int mask;
18   unsigned int numelements;
19   float loadfactor;
20   struct cnode *listhead;  
21 } ctable_t;
22
23 /* Prototypes for hash*/
24 ctable_t *cCreate(unsigned int size, float loadfactor);
25 unsigned int cInsert(ctable_t *table, unsigned int key, void * val);
26 void * cSearch(ctable_t *table, unsigned int key); //returns val, NULL if not found
27 unsigned int cRemove(ctable_t *table, unsigned int key); //returns -1 if not found
28 unsigned int cResize(ctable_t *table, unsigned int newsize);
29 void cDelete(ctable_t *table);
30 void crehash(ctable_t *table);
31 /* end hash */
32
33 #endif
34