1 |
/* |
2 |
* Routines to Process Set Instance Values |
3 |
* by Tom Epperly |
4 |
* 11/16/89 |
5 |
* Version: $Revision: 1.7 $ |
6 |
* Version control file: $RCSfile: setinstval.h,v $ |
7 |
* Date last modified: $Date: 1998/02/05 16:37:52 $ |
8 |
* Last modified by: $Author: ballan $ |
9 |
* |
10 |
* This file is part of the Ascend Language Interpreter. |
11 |
* |
12 |
* Copyright (C) 1990, 1993, 1994 Thomas Guthrie Epperly |
13 |
* |
14 |
* The Ascend Language Interpreter is free software; you can redistribute |
15 |
* it and/or modify it under the terms of the GNU General Public License as |
16 |
* published by the Free Software Foundation; either version 2 of the |
17 |
* License, or (at your option) any later version. |
18 |
* |
19 |
* The Ascend Language Interpreter is distributed in hope that it will be |
20 |
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of |
21 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
22 |
* General Public License for more details. |
23 |
* |
24 |
* You should have received a copy of the GNU General Public License along |
25 |
* with the program; if not, write to the Free Software Foundation, Inc., 675 |
26 |
* Mass Ave, Cambridge, MA 02139 USA. Check the file named COPYING. |
27 |
*/ |
28 |
|
29 |
/** @file |
30 |
* Routines to Process Set Instance Values. |
31 |
* |
32 |
* This group of routines is used to process the value fields of set |
33 |
* instances. |
34 |
* <pre> |
35 |
* When #including setinstval.h, make sure these files are #included first: |
36 |
* #include <stdio.h> |
37 |
* #include "utilities/ascConfig.h" |
38 |
* #include "compiler.h" |
39 |
* #include "list.h" |
40 |
* </pre> |
41 |
*/ |
42 |
|
43 |
#ifndef __SETINSTVAL_H_SEEN__ |
44 |
#define __SETINSTVAL_H_SEEN__ |
45 |
|
46 |
enum set_kind { |
47 |
integer_set, /**< set of integer values */ |
48 |
string_set, /**< set of string values */ |
49 |
empty_set /**< set with nothing in it */ |
50 |
}; |
51 |
|
52 |
/** Do not confuse this set with the struct Set in types.h */ |
53 |
struct set_t { |
54 |
enum set_kind kind; |
55 |
struct gl_list_t *list; |
56 |
}; |
57 |
|
58 |
extern void InitSetManager(void); |
59 |
/**< |
60 |
* This function initializes the pool. |
61 |
* We pool the set stubs for reuse, since there are so many used in |
62 |
* most ASCEND models of any complexity. |
63 |
* The pool grows as needed. It does not shrink until destroyed. |
64 |
* It is a fatal error to call this a second time unless |
65 |
* DestroySetManager has been called first. |
66 |
* In the pooling operation we only keep the set stubs, not the |
67 |
* gl_lists associated.<br><br> |
68 |
* |
69 |
* This exits if it cannot init the pool because of insufficient |
70 |
* memory. |
71 |
*/ |
72 |
|
73 |
extern void DestroySetManager(void); |
74 |
/**< |
75 |
* Destroys the set pool. Bombs if no pool exists. |
76 |
*/ |
77 |
|
78 |
extern void ReportSetManager(FILE*f); |
79 |
/**< |
80 |
* <!-- ReportSetManager(f); --> |
81 |
* <!-- FILE *f; --> |
82 |
* Reports on the set pool to f. |
83 |
*/ |
84 |
|
85 |
extern struct set_t *CreateEmptySet(void); |
86 |
/**< |
87 |
* <!-- struct set_t *CreateEmptySet() --> |
88 |
* Creates an empty set. |
89 |
*/ |
90 |
|
91 |
extern void InsertInteger(struct set_t *set, long i); |
92 |
/**< |
93 |
* <!-- void InsertInteger(set,i) --> |
94 |
* <!-- struct set_t *set; --> |
95 |
* <!-- long i; --> |
96 |
* Insert i into set. You can insert i multiple times without causing |
97 |
* problems. Set must be non-NULL. This will coerce an empty set type |
98 |
* into an integer set type; after that no symbols can be inserted into |
99 |
* the set. |
100 |
*/ |
101 |
|
102 |
extern void InsertIntegerRange(struct set_t *set, long lower, long upper); |
103 |
/**< |
104 |
* <!-- struct InsertIntegerRange(set,lower,upper) --> |
105 |
* <!-- struct set_t *set; --> |
106 |
* <!-- long lower, upper; --> |
107 |
* Insert the elements i such that i >= lower and i <= upper. Note if |
108 |
* lower > upper, no elements are inserted. This will coerce an empty |
109 |
* set type into an integer set type. |
110 |
*/ |
111 |
|
112 |
extern void InsertString(struct set_t *set, symchar *str); |
113 |
/**< |
114 |
* <!-- struct InsertString(set,str) --> |
115 |
* <!-- struct set_t *set; --> |
116 |
* <!-- symchar *str; --> |
117 |
* Insert str into set. This will coerce an empty set type into |
118 |
* a string set type; after which no integers can be inserted. |
119 |
*/ |
120 |
|
121 |
extern struct set_t *SetUnion(CONST struct set_t *s1, CONST struct set_t *s2); |
122 |
/**< |
123 |
* <!-- struct set_t *SetUnion(s1,s2) --> |
124 |
* <!-- const struct set_t *s1,*s2; --> |
125 |
* Create a set which is the union of s1 and s2. s1 and s2 are uneffected. |
126 |
* Union with empty set is always okay. |
127 |
*/ |
128 |
|
129 |
extern struct set_t *SetIntersection(CONST struct set_t *s1, |
130 |
CONST struct set_t *s2); |
131 |
/**< |
132 |
* <!-- struct set_t *SetIntersection(s1,s2); --> |
133 |
* <!-- const struct set_t *s1,*s2; --> |
134 |
* Create a set which is the intersection of s1 and s2. s1 and s2 are |
135 |
* uneffected. Intersection with empty set is okay. |
136 |
*/ |
137 |
|
138 |
extern struct set_t *SetDifference(CONST struct set_t *s1, CONST struct set_t *s2); |
139 |
/**< |
140 |
* <!-- struct set_t *SetDifference(s1,s2) --> |
141 |
* <!-- const struct set_t *s1,*s2; --> |
142 |
* Create a set which is define as follows: |
143 |
* return set := { i | (i IN s1) and (NOT (i IN s2))} |
144 |
*/ |
145 |
|
146 |
extern struct set_t *CopySet(CONST struct set_t *set); |
147 |
/**< |
148 |
* <!-- struct set_t *CopySet(set) --> |
149 |
* <!-- const struct set_t *set; --> |
150 |
* Copy a set. |
151 |
*/ |
152 |
|
153 |
extern int IntMember(long i, CONST struct set_t *set); |
154 |
/**< |
155 |
* <!-- int IntMember(i,set) --> |
156 |
* <!-- long i; --> |
157 |
* <!-- const struct set_t *set; --> |
158 |
* Return a TRUE value if i is a member of set; otherwise, return a false |
159 |
* value. |
160 |
*/ |
161 |
|
162 |
extern int StrMember(symchar *str, CONST struct set_t *set); |
163 |
/**< |
164 |
* <!-- int StrMember(str,set) --> |
165 |
* <!-- symchar *str; --> |
166 |
* <!-- const struct set_t *set; --> |
167 |
* Return a TRUE value if str is a member of set; otherwise, return a false |
168 |
* value. |
169 |
*/ |
170 |
|
171 |
extern void DestroySet(struct set_t *set); |
172 |
/**< "Free up" set pointer. Actually returns it to the pool of set stubs. */ |
173 |
|
174 |
extern int NullSet(CONST struct set_t *set); |
175 |
/**< Testing if the set is empty. TRUE if set is empty. */ |
176 |
|
177 |
extern unsigned long Cardinality(CONST struct set_t *set); |
178 |
/**< Return the number of members. */ |
179 |
|
180 |
extern symchar *FetchStrMember(CONST struct set_t *set, unsigned long n); |
181 |
/**< Returns the nth (internal sort order ) member symbol. */ |
182 |
|
183 |
extern long FetchIntMember(CONST struct set_t *set, unsigned long n); |
184 |
/**< Returns the nth (internal sort order ) member number. */ |
185 |
|
186 |
extern void SetIterate(struct set_t *set, void (*func)()); |
187 |
/**< Calls func for every element in set. */ |
188 |
|
189 |
extern enum set_kind SetKind(CONST struct set_t *set); |
190 |
/**< Returns the type of the set. */ |
191 |
|
192 |
extern int SetsEqual(CONST struct set_t *s1, CONST struct set_t *s2); |
193 |
/**< |
194 |
* <!-- int SetsEqual(s1,s2) --> |
195 |
* <!-- const struct set_t *s1,*s2; --> |
196 |
* Returns a true value if the two sets are equal. Set equality is |
197 |
* defined as: |
198 |
* (i IN s1) <==> (i IN s2) |
199 |
* This always returns FALSE if the sets are of different type. |
200 |
*/ |
201 |
|
202 |
extern int Subset(CONST struct set_t *s1, CONST struct set_t *s2); |
203 |
/**< |
204 |
* <!-- int Subset(s1,s2); --> |
205 |
* <!-- struct set_t *s1,*s2; --> |
206 |
* Returns a true value if s1 is contained in s2. It always returns FALSE |
207 |
* if the sets are of different type(even if they are empty sets). |
208 |
* |
209 |
* - TRUE if (i IN s1) ==> (i IN s2) |
210 |
* - FALSE otherwise |
211 |
*/ |
212 |
|
213 |
extern int CmpSetInstVal(CONST struct set_t *s1, CONST struct set_t *s2); |
214 |
/**< |
215 |
* <!-- int CmpSetInstVal(s1,s2) --> |
216 |
* <!-- struct set_t *s1,*s2; --> |
217 |
* Returns -1, 0, 1 from comparing s1,s2. |
218 |
*/ |
219 |
|
220 |
/* |
221 |
* Some ordered set processing. The elements of the below sets are |
222 |
* not necessarily unique and not necessarily ordered. In this way they |
223 |
* behave more like lists. For TRUE sets use the InsertInteger and |
224 |
* InsertString functions above. |
225 |
*/ |
226 |
|
227 |
extern void AppendIntegerElement(struct set_t *set, long int i ); |
228 |
/**< |
229 |
* <!-- void AppendIntegerElement(set,i); --> |
230 |
* <!-- struct set_t *set; --> |
231 |
* <!-- long int i; --> |
232 |
* This function will append an integer to a set. In so doing it will NOT |
233 |
* attempt to sort the elements of the set or to make the elements of the |
234 |
* set unique. In this way the set is treated as a list. |
235 |
*/ |
236 |
|
237 |
extern void AppendStringElement(struct set_t *set, symchar *str); |
238 |
/**< |
239 |
* <!-- struct set_t *set; --> |
240 |
* <!-- symchar *str; --> |
241 |
* This function will append an string to a set. In so doing it will NOT |
242 |
* attempt to sort the elements of the set or to make the elements of the |
243 |
* set unique. In this way the set is treated as a list. |
244 |
*/ |
245 |
|
246 |
#endif /* __SETINSTVAL_H_SEEN__ */ |
247 |
|