-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoisc.h
112 lines (94 loc) · 3.2 KB
/
oisc.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
* OIScs (searchable collections) are things that map
* pairs of oids onto ints. Operations:
* create, destroy, insert, lookup, size, and print
*/
#ifndef __EMERALD_OISC_H
#define __EMERALD_OISC_H
#include "storage.h"
#include "types.h"
typedef OID OIScDomainType;
#define OIScRangeType int
#define OIScHASH(X) ((unsigned) (((X).ipaddress) ^ (((X).Seq) << 0)))
#define OIScCOMPARE(K,X) (sameOID((K), (X)))
#define OIScNIL (JNIL)
#define OIScIsNIL(X) ((int)(X) == OIScNIL)
#define OIScTSize(sc) ((sc)->size + (sc)->ofsize)
/*
* Hidden, private type declarations. The only thing
* that applications of this package are to see is OISc,
* and they are to treat it as opaque: that is, they may
* assign it, and pass it as arguments, but not manipulate
* what it points to directly.
*/
typedef struct OIScTE {
OIScDomainType key; /* the key for this entry */
OIScRangeType value; /* what we want */
int chain; /* overflow chain */
} OIScTE, *OIScTEPtr;
typedef struct OIScRecord {
OIScTEPtr table;
int size, maxCount, count, ofsize, ofcount, of;
} OIScRecord, *OISc;
/* OPERATIONS */
/* Return a new, empty Searchable Collection */
OISc OIScCreate(void);
OISc OIScCreateN(int);
OISc OIScClone(OISc original);
/* Destroy a collection */
void OIScDestroy(OISc sc);
/* Insert the pair <key, value> into collection OISc */
void OIScInsert(OISc sc, OID a, OIScRangeType value);
/* Delete the pair with key key from the collection OISc */
void OIScDelete(OISc sc, OID a);
/* Return the value associated with key in collection
* OISc, or OIScNIL if no such pair exists */
int OIScLookup(OISc sc, OID a);
/* DEBUGGING: Print the collection OISc */
void OIScPrint(OISc sc);
void OIScPrintF(OISc sc);
/* Iterate over the elements of the collection OISc.
* At each iteration, OISckey and OIScvalue are set to the next
* <key, value> pair in the collection.
* Usage:
* OIScForEach(sc, key_a, value) {
* / * whatever you want to do with key_a, key_b, value * /
* } OIScNext();
*/
#define OIScForEach(OISc, OISckey, OIScvalue) \
{ \
int OIScxx_index; \
for (OIScxx_index = 0; OIScxx_index < OIScTSize(OISc); OIScxx_index++) { \
if (!OIScIsNIL((OISc)->table[OIScxx_index].value)) { \
*(OID*)(&(OISckey)) = (OISc)->table[OIScxx_index].key; \
*(OIScRangeType *)(&(OIScvalue)) = (OISc)->table[OIScxx_index].value; \
{
#define OIScNext() \
} \
} \
} \
}
/* Iterate over the elements of the collection OISc backwards.
* At each iteration, OISckey and OIScvalue are set to the next
* <key, value> pair in the collection.
* Usage:
* OIScForEachBackwards(sc, key_a, value) {
* / * whatever you want to do with key_a, key_b, value * /
* } OIScNext();
*/
#define OIScForEachBackwards(OISc, OISckey, OIScvalue) \
{ \
int OIScxx_index; \
for (OIScxx_index = OIScTSize(OISc) - 1; OIScxx_index >= 0; OIScxx_index--) { \
if (!OIScIsNIL((OISc)->table[OIScxx_index].value)) { \
*(OID*)(&(OISckey)) = (OISc)->table[OIScxx_index].key; \
*(OIScRangeType *)(&(OIScvalue)) = (OISc)->table[OIScxx_index].value; \
{
#define OIScNext() \
} \
} \
} \
}
/* Return the number of elements in OISc */
#define OIScSize(OISc) ((OISc)->count)
#endif /* _EMERALD_OISC_H */