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