Code clean
[IRC.git] / Robust / src / Runtime / bamboo / MGCHash.h
1 #ifndef MGCHASH_H
2 #define MGCHASH_H
3
4 #include "multicore.h"
5 #include "mem.h"
6
7 /* mgchash *********************************************************/
8 typedef struct mgchashlistnode {
9   void * key;
10   void * val; //this can be cast to another type or used to point to a
11               //larger structure
12   struct mgchashlistnode *next;
13 } mgchashlistnode_t;
14
15 #define NUMMGCLIST 250
16 typedef struct mgclist {
17   struct mgchashlistnode array[NUMMGCLIST];
18   int num;
19   struct mgclist *next;
20 } mgcliststruct_t;
21
22 typedef struct mgchashtable {
23   mgchashlistnode_t * table;       // points to beginning of hash table
24   mgcliststruct_t * structs;
25   unsigned int size;
26   unsigned int mask;
27   unsigned int numelements;
28   unsigned int threshold;
29   double loadfactor;
30 } mgchashtable_t;
31
32 mgchashtable_t * mgchashCreate(unsigned int size, double loadfactor);
33 void mgchashInsert(mgchashtable_t * tbl, void * key, void *val);
34 void * mgchashSearch(mgchashtable_t * tbl, void * key);
35 unsigned int mgchashResize(mgchashtable_t * tbl, unsigned int newsize);
36 #ifdef MULTICORE_GC
37 mgchashtable_t * mgchashCreate_I(unsigned int size, double loadfactor);
38 void mgchashInsert_I(mgchashtable_t * tbl, void * key, void *val);
39 unsigned int mgchashResize_I(mgchashtable_t * tbl, unsigned int newsize);
40 #endif
41 void mgchashDelete(mgchashtable_t * tbl);
42 void mgchashreset(mgchashtable_t * tbl);
43
44
45 /** MGCHash *******************************************************************/
46 struct MGCHash * allocateMGCHash(int size, int conflicts);
47 void freeMGCHash(struct MGCHash *);
48
49 int MGCHashadd(struct MGCHash *, int data);
50 #ifdef MULTICORE
51 struct MGCHash * allocateMGCHash_I(int size, int conflicts);
52 int MGCHashadd_I(struct MGCHash *, int data);
53 #endif
54 int MGCHashcontains(struct MGCHash *,int data);
55
56 struct MGCHash {
57   int num4conflicts;
58   int size;
59   struct MGCNode *bucket;
60 };
61
62 /* MGCHashException  *************************************************/
63
64 struct MGCNode {
65   struct MGCNode * next;
66   int data;
67 };
68
69 #endif