Bug fixes and add some code for easy debugging
[IRC.git] / Robust / src / Runtime / bamboo / GCSharedHash.h
1 #ifdef MULTICORE_GC
2
3 #ifndef GCSHAREDHASH_H
4 #define GCSHAREDHASH_H
5
6 #ifndef bool
7 #define bool int
8 #endif
9
10 #ifndef true
11 #define true 1
12 #endif
13
14 #ifndef false
15 #define false 0
16 #endif
17
18 #include "mem.h"
19
20 /* GCSharedHash *********************************************************/
21
22 struct GCSharedHash * noargallocateGCSharedHash();
23 struct GCSharedHash * allocateGCSharedHash(int size);
24 void freeGCSharedHash(struct GCSharedHash *);
25
26 bool GCSharedHashrehash(struct GCSharedHash * thisvar);
27 int GCSharedHashadd(struct GCSharedHash *, int key, int data);
28 #ifdef MULTICORE
29 struct GCSharedHash * allocateGCSharedHash_I(int size);
30 int GCSharedHashadd_I(struct GCSharedHash *, int key, int data);
31 #endif
32 int GCSharedHashget(struct GCSharedHash *,int key, int* data);
33
34 struct GCSharedHash {
35   int numelements;
36   int size;
37   struct GCSharedNode **bucket;
38   struct GCSharedNode *listhead;
39   struct GCSharedNode *listtail;
40 };
41
42 inline int GCSharedHashcountset(struct GCSharedHash * thisvar);
43
44 /* RuntimeHashException  *************************************************/
45
46
47 /* RuntimeIterator *****************************************************/
48 struct GCSharedNode {
49   struct GCSharedNode *next;
50   struct GCSharedNode *lnext;
51   struct GCSharedNode *lprev;
52   int data;
53   int key;
54 };
55
56 /* MGCSharedHash *********************************************************/
57 typedef struct mgcsharedhashlistnode {
58   void * key;
59   void * val; //this can be cast to another type or used to point to a
60               //larger structure
61   struct mgcsharedhashlistnode * next;
62 } mgcsharedhashlistnode_t;
63
64 #define NUMMGCSHAREDLIST 250
65 typedef struct mgcsharedlist {
66   struct mgcsharedhashlistnode array[NUMMGCSHAREDLIST];
67   int num;
68   struct mgcsharedlist *next;
69 } mgcsharedliststruct_t;
70
71 typedef struct mgcsharedhashtbl {
72   mgcsharedhashlistnode_t * table;       // points to beginning of hash table
73   mgcsharedhashlistnode_t * list;
74   mgcsharedliststruct_t * structs;
75   unsigned int size;
76   unsigned int mask;
77   unsigned int numelements;
78   unsigned int threshold;
79   double loadfactor;
80 } mgcsharedhashtbl_t;
81
82 mgcsharedhashtbl_t * mgcsharedhashCreate(unsigned int size, double loadfactor);
83 mgcsharedhashtbl_t * mgcsharedhashCreate_I(unsigned int size,double loadfactor);
84 int mgcsharedhashInsert(mgcsharedhashtbl_t * tbl, void * key, void * val);
85 void * mgcsharedhashSearch(mgcsharedhashtbl_t * tbl, void * key);
86 int mgcsharedhashInsert_I(mgcsharedhashtbl_t * tbl, void * key, void * val);
87 void mgcsharedhashReset(mgcsharedhashtbl_t * tbl);
88
89 #endif
90
91 #endif