-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjoveisc.h
97 lines (79 loc) · 2.95 KB
/
joveisc.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
/*
* JOVEIScs (searchable collections) are things that map
* jekyll op vector elements onto integers.
* Operations create, destroy, insert, lookup, size, and print
*/
#ifndef _EMERALD_JOVEISC_H
#define _EMERALD_JOVEISC_H
/*
* Before using this, one must define the following:
* JOVEISCDomainType - a typedef for the domain
* JOVEISCRangeType - a typedef for the range
* HASH - a macro that computes an integer from a given
* element of the domain
* COMPARE - a macro that compares two elements of the domain,
* evaluating to 1 if they are the same
*/
#include "types.h"
#include "array.h"
#include "storage.h"
typedef OpVectorElement JOVEISCDomainType;
typedef int JOVEISCRangeType;
#define JOVEHASH(key, obA) oveintHash((OpVectorElement)key, obA)
/*
* Hidden, private type declarations. The only thing
* that applications of this package are to see is JOVEISc,
* 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 JOVEIScTE {
JOVEISCDomainType key; /* the key for this entry */
JOVEISCRangeType value; /* what we want */
} JOVEIScTE, *JOVEIScTEPtr;
typedef struct JOVEIScRecord {
JOVEIScTEPtr table;
int size, maxCount, count;
} JOVEIScRecord, *JOVEISc;
/* OPERATIONS */
/* Return a new, empty Searchable Collection */
extern JOVEISc JOVEIScCreate(void);
/* Destroy a collection */
extern void JOVEIScDestroy(register JOVEISc sc);
/* Insert the pair <key, value> into collection JOVEISc */
void JOVEIScInsert(register JOVEISc sc, register JOVEISCDomainType key,
JOVEISCRangeType value, array obA);
/* Delete the pair with key key from the collection JOVEISc */
extern void JOVEIScDelete(register JOVEISc sc, register JOVEISCDomainType key,
array obA);
/* Return the value associated with key in collection
* JOVEISc, or 0 if no such pair exists */
extern JOVEISCRangeType JOVEIScLookup(register JOVEISc sc,
register JOVEISCDomainType key,
array obA);
/* DEBUGGING: Print the collection JOVEISc */
extern void JOVEIScPrint(register JOVEISc sc);
/* Iterate over the elements of the collection JOVEISc.
* At each iteration, JOVEISckey and JOVEIScvalue are set to the next
* <key, value> pair in the collection.
* Usage:
* JOVEIScForEach(someSc, key, value) {
* / * whatever you want to do with key, value * /
* } JOVEIScNext();
*/
#define JOVEIScForEach(JOVEISc, JOVEISckey, JOVEIScvalue) \
{ \
int JOVEIScxx_index; \
for (JOVEIScxx_index = 0; JOVEIScxx_index < (JOVEISc)->size; JOVEIScxx_index++) { \
if ((JOVEISc)->table[JOVEIScxx_index].key != NULL) { \
(JOVEISckey) = JOVEISc->table[JOVEIScxx_index].key; \
*(JOVEISCRangeType *)(&(JOVEIScvalue)) = JOVEISc->table[JOVEIScxx_index].value; \
{
#define JOVEIScNext() \
} \
} \
} \
}
/* Return the number of elements in JOVEISc */
#define JOVEIScSize(JOVEISc) ((JOVEISc)->count)
#endif /* _EMERALD_JOVEISC_H */