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