65a03ec3cc51c9ddd8bb1bd5b81cc4bd435c6808
[IRC.git] / Robust / src / Runtime / bamboo / 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 #define NUMMGCLIST 250
31 typedef struct mgclist {
32   struct mgchashlistnode array[NUMMGCLIST];
33   int num;
34   struct mgclist *next;
35 } mgcliststruct_t;
36
37 typedef struct mgchashtable {
38   mgchashlistnode_t * table;       // points to beginning of hash table
39   mgcliststruct_t * structs;
40   unsigned int size;
41   unsigned int mask;
42   unsigned int numelements;
43   unsigned int threshold;
44   double loadfactor;
45 } mgchashtable_t;
46
47 mgchashtable_t * mgchashCreate(unsigned int size, double loadfactor);
48 void mgchashInsert(mgchashtable_t * tbl, void * key, void *val);
49 void * mgchashSearch(mgchashtable_t * tbl, void * key);
50 unsigned int mgchashResize(mgchashtable_t * tbl, unsigned int newsize);
51 #ifdef MULTICORE_GC
52 mgchashtable_t * mgchashCreate_I(unsigned int size, double loadfactor);
53 void mgchashInsert_I(mgchashtable_t * tbl, void * key, void *val);
54 unsigned int mgchashResize_I(mgchashtable_t * tbl, unsigned int newsize);
55 #endif
56 void mgchashDelete(mgchashtable_t * tbl);
57 void mgchashreset(mgchashtable_t * tbl);
58
59
60 /** MGCHash *******************************************************************/
61 struct MGCHash * allocateMGCHash(int size, int conflicts);
62 void freeMGCHash(struct MGCHash *);
63
64 int MGCHashadd(struct MGCHash *, int data);
65 #ifdef MULTICORE
66 struct MGCHash * allocateMGCHash_I(int size, int conflicts);
67 int MGCHashadd_I(struct MGCHash *, int data);
68 #endif
69 int MGCHashcontains(struct MGCHash *,int data);
70
71 struct MGCHash {
72   int num4conflicts;
73   int size;
74   struct MGCNode *bucket;
75 };
76
77 /* MGCHashException  *************************************************/
78
79 struct MGCNode {
80   struct MGCNode * next;
81   int data;
82 };
83
84 #endif