more files
[IRC.git] / Robust / src / Runtime / SimpleHash.h
1 #ifndef SIMPLEHASH_H
2 #define SIMPLEHASH_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 #include "mem.h"
17
18 /* SimpleHash *********************************************************/
19
20 struct SimpleHash * noargallocateSimpleHash();
21 struct SimpleHash * allocateSimpleHash(int size);
22 void SimpleHashaddChild(struct SimpleHash *thisvar, struct SimpleHash * child);
23 void freeSimpleHash(struct SimpleHash *);
24
25
26 int SimpleHashadd(struct SimpleHash *, int key, int data);
27 int SimpleHashremove(struct SimpleHash *,int key, int data);
28 bool SimpleHashcontainskey(struct SimpleHash *,int key);
29 bool SimpleHashcontainskeydata(struct SimpleHash *,int key, int data);
30 int SimpleHashget(struct SimpleHash *,int key, int* data);
31 int SimpleHashcountdata(struct SimpleHash *,int data);
32 void SimpleHashaddParent(struct SimpleHash *,struct SimpleHash* parent);
33 int SimpleHashfirstkey(struct SimpleHash *);
34 struct SimpleIterator* SimpleHashcreateiterator(struct SimpleHash *);
35 void SimpleHashiterator(struct SimpleHash *, struct SimpleIterator * it);
36 int SimpleHashcount(struct SimpleHash *, int key);
37 void SimpleHashaddAll(struct SimpleHash *, struct SimpleHash * set);
38 struct SimpleHash * SimpleHashimageSet(struct SimpleHash *, int key);
39
40 struct SimpleHash {
41     int numelements;
42     int size;
43     struct SimpleNode **bucket;
44     struct ArraySimple *listhead;
45     struct ArraySimple *listtail;
46     int tailindex;
47 };
48
49 inline int SimpleHashcountset(struct SimpleHash * thisvar);
50
51 /* SimpleHashException  *************************************************/
52
53
54 /* SimpleIterator *****************************************************/
55 #define ARRAYSIZE 100
56
57 struct SimpleNode {
58   struct SimpleNode *next;
59   int data;
60   int key;
61   int inuse;
62 };
63
64 struct ArraySimple {
65   struct SimpleNode nodes[ARRAYSIZE];
66   struct ArraySimple * nextarray;
67 };
68
69
70 struct SimpleIterator {
71   struct ArraySimple *cur, *tail;
72   int index,tailindex;
73 };
74
75 inline struct SimpleIterator * noargallocateSimpleIterator();
76
77 inline struct SimpleIterator * allocateSimpleIterator(struct ArraySimple *start, struct ArraySimple *tl, int tlindex);
78
79 inline int hasNext(struct SimpleIterator *thisvar);
80
81 inline int next(struct SimpleIterator *thisvar);
82
83 inline int key(struct SimpleIterator *thisvar);
84
85 #endif