autoc 1.3 → 1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES +4 -0
  3. data/doc/AutoC.html +55 -55
  4. data/doc/AutoC/Code.html +60 -57
  5. data/doc/AutoC/Collection.html +134 -124
  6. data/doc/AutoC/HashMap.html +147 -185
  7. data/doc/AutoC/HashSet.html +114 -325
  8. data/doc/AutoC/Iterators.html +126 -0
  9. data/doc/AutoC/Iterators/Bidirectional.html +204 -0
  10. data/doc/AutoC/Iterators/Unidirectional.html +200 -0
  11. data/doc/AutoC/List.html +81 -76
  12. data/doc/AutoC/Maps.html +290 -0
  13. data/doc/AutoC/Module.html +72 -69
  14. data/doc/AutoC/Module/File.html +55 -52
  15. data/doc/AutoC/Module/Header.html +55 -52
  16. data/doc/AutoC/Module/Source.html +63 -60
  17. data/doc/AutoC/Priority.html +57 -57
  18. data/doc/AutoC/Queue.html +75 -74
  19. data/doc/AutoC/Reference.html +92 -91
  20. data/doc/AutoC/Sets.html +520 -0
  21. data/doc/AutoC/String.html +70 -69
  22. data/doc/AutoC/TreeMap.html +1565 -0
  23. data/doc/AutoC/TreeSet.html +1447 -0
  24. data/doc/AutoC/Type.html +184 -110
  25. data/doc/AutoC/UserDefinedType.html +102 -102
  26. data/doc/AutoC/Vector.html +100 -91
  27. data/doc/_index.html +97 -33
  28. data/doc/class_list.html +24 -31
  29. data/doc/css/full_list.css +32 -31
  30. data/doc/css/style.css +220 -78
  31. data/doc/file.CHANGES.html +37 -30
  32. data/doc/file.README.html +29 -30
  33. data/doc/file_list.html +29 -31
  34. data/doc/frames.html +7 -16
  35. data/doc/index.html +29 -30
  36. data/doc/js/app.js +100 -76
  37. data/doc/js/full_list.js +170 -135
  38. data/doc/method_list.html +877 -431
  39. data/doc/top-level-namespace.html +35 -35
  40. data/lib/autoc.rb +4 -2
  41. data/lib/autoc/collection.rb +10 -4
  42. data/lib/autoc/collection/hash_map.rb +22 -41
  43. data/lib/autoc/collection/hash_set.rb +13 -120
  44. data/lib/autoc/collection/iterator.rb +39 -0
  45. data/lib/autoc/collection/list.rb +7 -5
  46. data/lib/autoc/collection/map.rb +41 -0
  47. data/lib/autoc/collection/queue.rb +8 -8
  48. data/lib/autoc/collection/set.rb +134 -0
  49. data/lib/autoc/collection/tree_map.rb +464 -0
  50. data/lib/autoc/collection/tree_set.rb +611 -0
  51. data/lib/autoc/collection/vector.rb +8 -4
  52. data/lib/autoc/string.rb +1 -1
  53. data/lib/autoc/type.rb +3 -0
  54. data/test/test.rb +2 -2
  55. data/test/test_auto.c +7141 -0
  56. data/test/test_auto.h +753 -0
  57. data/test/test_int_tree_set.rb +111 -0
  58. data/test/test_value_hash_map.rb +1 -1
  59. data/test/test_value_hash_set.rb +1 -1
  60. data/test/test_value_tree_map.rb +176 -0
  61. data/test/test_value_tree_set.rb +173 -0
  62. metadata +21 -5
@@ -0,0 +1,753 @@
1
+ /* AUTOMATICALLY GENERATED HEADER FILE. DO NOT MODIFY. */
2
+ #ifndef TEST_AUTO_H
3
+ #define TEST_AUTO_H
4
+ #ifndef AUTOC_INLINE
5
+ #if defined(_MSC_VER) || defined(__DMC__)
6
+ #define AUTOC_INLINE AUTOC_STATIC __inline
7
+ #elif defined(__LCC__)
8
+ #define AUTOC_INLINE AUTOC_STATIC /* LCC rejects static __inline */
9
+ #elif __STDC_VERSION__ >= 199901L
10
+ #define AUTOC_INLINE AUTOC_STATIC inline
11
+ #else
12
+ #define AUTOC_INLINE AUTOC_STATIC
13
+ #endif
14
+ #endif
15
+ #ifndef AUTOC_EXTERN
16
+ #ifdef __cplusplus
17
+ #define AUTOC_EXTERN extern "C"
18
+ #else
19
+ #define AUTOC_EXTERN extern
20
+ #endif
21
+ #endif
22
+ #ifndef AUTOC_STATIC
23
+ #if defined(_MSC_VER)
24
+ #define AUTOC_STATIC __pragma(warning(suppress:4100)) static
25
+ #elif defined(__GNUC__)
26
+ #define AUTOC_STATIC __attribute__((__used__)) static
27
+ #else
28
+ #define AUTOC_STATIC static
29
+ #endif
30
+ #endif
31
+ #include <stddef.h>
32
+ #include <stdlib.h>
33
+ #include <assert.h>
34
+ /***
35
+ **** CharString<char>
36
+ ***/
37
+ typedef struct CharStringListNode CharStringListNode;
38
+ typedef struct CharStringList CharStringList;
39
+ typedef struct CharStringListIt CharStringListIt;
40
+ struct CharStringList {
41
+ CharStringListNode* head_node;
42
+ size_t node_count;
43
+ };
44
+ struct CharStringListIt {
45
+ int start;
46
+ CharStringList* list;
47
+ CharStringListNode* this_node;
48
+ };
49
+ struct CharStringListNode {
50
+ char* element;
51
+ CharStringListNode* next_node;
52
+ };
53
+ typedef struct CharString CharString;
54
+ typedef struct CharStringIt CharStringIt;
55
+ struct CharString {
56
+ size_t size;
57
+ union data {
58
+ char* string;
59
+ CharStringList list;
60
+ } data;
61
+ int is_list;
62
+ };
63
+ struct CharStringIt {
64
+ CharString* string;
65
+ int index, forward;
66
+ };
67
+ #define _CharStringCtor(self,chars) CharStringCtor(&self,chars)
68
+ #define _CharStringDtor(self) CharStringDtor(&self)
69
+ #define _CharStringIdentify(self) CharStringIdentify(&self)
70
+ #define _CharStringCopy(dst,src) CharStringCopy(&dst,&src)
71
+ #define _CharStringEqual(lt,rt) CharStringEqual(&lt,&rt)
72
+ #define _CharStringLess(lt,rt) CharStringLess(&lt,&rt)
73
+ #include <string.h>
74
+ #ifdef AUTOC_BUFFER_SIZE
75
+ #define _CharStringBufferSize AUTOC_BUFFER_SIZE
76
+ #else
77
+ #define _CharStringBufferSize 4096 /* Stay in sync with the documentation! */
78
+ #endif
79
+ #define CharStringJoin(self) if(self->is_list) _CharStringJoin(self);
80
+ #define CharStringSplit(self) if(!self->is_list) _CharStringSplit(self);
81
+ AUTOC_EXTERN void _CharStringJoin(CharString*);
82
+ AUTOC_EXTERN void _CharStringSplit(CharString*);
83
+ AUTOC_EXTERN void CharStringCtor(CharString*,const char*);
84
+ AUTOC_EXTERN void CharStringDtor(CharString*);
85
+ AUTOC_EXTERN void CharStringCopy(CharString*,CharString*);
86
+ AUTOC_EXTERN void CharStringCopyRange(CharString*, CharString*, size_t, size_t);
87
+ AUTOC_EXTERN int CharStringEqual(CharString*,CharString*);
88
+ AUTOC_EXTERN size_t CharStringIdentify(CharString*);
89
+ #define CharStringEmpty(self) (CharStringSize(self) == 0)
90
+ AUTOC_INLINE size_t CharStringSize(CharString* self) {
91
+ assert(self);
92
+ /* CharStringJoin(self); assuming the changes to the contents are reflected in the size */
93
+ #ifndef NDEBUG
94
+ /* Type invariants which must hold true */
95
+ if(!self->is_list) assert(self->size == strlen(self->data.string));
96
+ /* TODO self->is_list case */
97
+ #endif
98
+ return self->size;
99
+ }
100
+ AUTOC_INLINE int CharStringWithin(CharString* self, size_t index) {
101
+ assert(self);
102
+ /* Omitting excessive call to CharStringJoin() */
103
+ return index < CharStringSize(self);
104
+ }
105
+ AUTOC_INLINE char CharStringGet(CharString* self, size_t index) {
106
+ assert(self);
107
+ assert(CharStringWithin(self, index));
108
+ CharStringJoin(self);
109
+ return self->data.string[index];
110
+ }
111
+ AUTOC_INLINE void CharStringSet(CharString* self, size_t index, char value) {
112
+ assert(self);
113
+ assert(CharStringWithin(self, index));
114
+ CharStringJoin(self);
115
+ self->data.string[index] = value;
116
+ }
117
+ AUTOC_INLINE const char* CharStringChars(CharString* self) {
118
+ assert(self);
119
+ CharStringJoin(self);
120
+ return self->data.string;
121
+ }
122
+ AUTOC_EXTERN int CharStringPushFormat(CharString*, const char*, ...);
123
+ AUTOC_EXTERN void CharStringPushChars(CharString*, const char*);
124
+ AUTOC_EXTERN void CharStringPushString(CharString*, CharString*);
125
+ #define CharStringPushChar(self, c) CharStringPushFormat(self, "%c", (char)(c))
126
+ #define CharStringPushInt(self, i) CharStringPushFormat(self, "%d", (int)(i))
127
+ #define CharStringPushFloat(self, f) CharStringPushFormat(self, "%e", (double)(f))
128
+ #define CharStringPushPtr(self, p) CharStringPushFormat(self, "%p", (void*)(p))
129
+ #define CharStringItCtor(self, type) CharStringItCtorEx(self, type, 1)
130
+ AUTOC_INLINE void CharStringItCtorEx(CharStringIt* self, CharString* string, int forward) {
131
+ assert(self);
132
+ assert(string);
133
+ self->string = string;
134
+ self->forward = forward;
135
+ self->index = forward ? -1 : CharStringSize(string);
136
+ }
137
+ AUTOC_INLINE int CharStringItMove(CharStringIt* self) {
138
+ assert(self);
139
+ if(self->forward) ++self->index;
140
+ else --self->index;
141
+ return CharStringWithin(self->string, self->index);
142
+ }
143
+ AUTOC_INLINE char CharStringItGet(CharStringIt* self) {
144
+ assert(self);
145
+ return CharStringGet(self->string, self->index);
146
+ }
147
+ typedef struct {
148
+ int* value;
149
+ } Value;
150
+ #define ValueCtor(self) _ValueCtor(&self)
151
+ #define ValueCtorEx(self, v) _ValueCtorEx(&self, v)
152
+ #define ValueDtor(self) _ValueDtor(&self)
153
+ #define ValueCopy(dst, src) _ValueCopy(&dst, &src)
154
+ #define ValueEqual(lt, rt) _ValueEqual(&lt, &rt)
155
+ #define ValueLess(lt, rt) _ValueLess(&lt, &rt)
156
+ #define ValueIdentify(self) _ValueIdentify(&self)
157
+ #define ValueGet(self) *(self).value
158
+ #define ValueSet(self, x) *(self).value = (x)
159
+ void _ValueCtor(Value*);
160
+ void _ValueCtorEx(Value*, int);
161
+ void _ValueDtor(Value*);
162
+ void _ValueCopy(Value*, Value*);
163
+ int _ValueEqual(Value*, Value*);
164
+ int _ValueLess(Value*, Value*);
165
+ size_t _ValueIdentify(Value*);
166
+ /***
167
+ **** IntList<int>
168
+ ***/
169
+ typedef struct IntListNode IntListNode;
170
+ typedef struct IntList IntList;
171
+ typedef struct IntListIt IntListIt;
172
+ struct IntList {
173
+ IntListNode* head_node;
174
+ size_t node_count;
175
+ };
176
+ struct IntListIt {
177
+ int start;
178
+ IntList* list;
179
+ IntListNode* this_node;
180
+ };
181
+ struct IntListNode {
182
+ int element;
183
+ IntListNode* next_node;
184
+ };
185
+ #define _IntListCtor(self) IntListCtor(&self)
186
+ #define _IntListDtor(self) IntListDtor(&self)
187
+ #define _IntListIdentify(self) IntListIdentify(&self)
188
+ #define _IntListCopy(dst,src) IntListCopy(&dst,&src)
189
+ #define _IntListEqual(lt,rt) IntListEqual(&lt,&rt)
190
+ #define _IntListLess(lt,rt) IntListLess(&lt,&rt)
191
+ AUTOC_EXTERN void IntListItCtor(IntListIt*, IntList*);
192
+ AUTOC_EXTERN int IntListItMove(IntListIt*);
193
+ AUTOC_EXTERN int IntListItGet(IntListIt*);
194
+ AUTOC_EXTERN void IntListCtor(IntList*);
195
+ AUTOC_EXTERN void IntListDtor(IntList*);
196
+ AUTOC_EXTERN void IntListCopy(IntList*,IntList*);
197
+ AUTOC_EXTERN int IntListEqual(IntList*,IntList*);
198
+ AUTOC_EXTERN size_t IntListIdentify(IntList*);
199
+ AUTOC_EXTERN void IntListPurge(IntList*);
200
+ AUTOC_EXTERN int IntListPeek(IntList*);
201
+ AUTOC_EXTERN int IntListPop(IntList*);
202
+ AUTOC_EXTERN void IntListPush(IntList*, int);
203
+ AUTOC_EXTERN int IntListContains(IntList*, int);
204
+ AUTOC_EXTERN int IntListFind(IntList*, int);
205
+ #define IntListReplace(self, with) IntListReplaceEx(self, with, 1)
206
+ #define IntListReplaceAll(self, with) IntListReplaceEx(self, with, -1)
207
+ AUTOC_EXTERN int IntListReplaceEx(IntList*, int, int);
208
+ #define IntListRemove(self, what) IntListRemoveEx(self, what, 1)
209
+ #define IntListRemoveAll(self, what) IntListRemoveEx(self, what, -1)
210
+ AUTOC_EXTERN int IntListRemoveEx(IntList*, int, int);
211
+ AUTOC_EXTERN size_t IntListSize(IntList*);
212
+ #define IntListEmpty(self) (IntListSize(self) == 0)
213
+ /***
214
+ **** IntTreeSet<int>
215
+ ***/
216
+ typedef struct IntTreeSet IntTreeSet;
217
+ typedef struct IntTreeSetNode IntTreeSetNode;
218
+ typedef struct IntTreeSetIt IntTreeSetIt;
219
+ struct IntTreeSet {
220
+ IntTreeSetNode* root;
221
+ size_t size;
222
+ };
223
+ struct IntTreeSetIt {
224
+ int start, ascending;
225
+ IntTreeSetNode* node;
226
+ };
227
+ struct IntTreeSetNode {
228
+ int color;
229
+ IntTreeSetNode* left;
230
+ IntTreeSetNode* right;
231
+ IntTreeSetNode* parent;
232
+ int element;
233
+ };
234
+ #define _IntTreeSetCtor(self) IntTreeSetCtor(&self)
235
+ #define _IntTreeSetDtor(self) IntTreeSetDtor(&self)
236
+ #define _IntTreeSetIdentify(self) IntTreeSetIdentify(&self)
237
+ #define _IntTreeSetCopy(dst,src) IntTreeSetCopy(&dst,&src)
238
+ #define _IntTreeSetEqual(lt,rt) IntTreeSetEqual(&lt,&rt)
239
+ #define _IntTreeSetLess(lt,rt) IntTreeSetLess(&lt,&rt)
240
+ AUTOC_EXTERN void IntTreeSetCtor(IntTreeSet*);
241
+ AUTOC_EXTERN void IntTreeSetDtor(IntTreeSet*);
242
+ AUTOC_EXTERN void IntTreeSetCopy(IntTreeSet*,IntTreeSet*);
243
+ AUTOC_EXTERN int IntTreeSetEqual(IntTreeSet*,IntTreeSet*);
244
+ AUTOC_EXTERN size_t IntTreeSetIdentify(IntTreeSet*);
245
+ AUTOC_EXTERN void IntTreeSetPurge(IntTreeSet*);
246
+ AUTOC_EXTERN int IntTreeSetContains(IntTreeSet*, int);
247
+ AUTOC_EXTERN int IntTreeSetGet(IntTreeSet*, int);
248
+ AUTOC_EXTERN size_t IntTreeSetSize(IntTreeSet*);
249
+ #define IntTreeSetEmpty(self) (IntTreeSetSize(self) == 0)
250
+ AUTOC_EXTERN int IntTreeSetPut(IntTreeSet*, int);
251
+ AUTOC_EXTERN int IntTreeSetReplace(IntTreeSet*, int);
252
+ AUTOC_EXTERN int IntTreeSetRemove(IntTreeSet*, int);
253
+ AUTOC_EXTERN void IntTreeSetExclude(IntTreeSet*, IntTreeSet*);
254
+ AUTOC_EXTERN void IntTreeSetRetain(IntTreeSet*, IntTreeSet*);
255
+ AUTOC_EXTERN void IntTreeSetInclude(IntTreeSet*, IntTreeSet*);
256
+ AUTOC_EXTERN void IntTreeSetInvert(IntTreeSet*, IntTreeSet*);
257
+ AUTOC_EXTERN void IntTreeSetItCtor(IntTreeSetIt*, IntTreeSet*);
258
+ #define IntTreeSetItCtor(self, type) IntTreeSetItCtorEx(self, type, 1)
259
+ AUTOC_EXTERN void IntTreeSetItCtorEx(IntTreeSetIt*, IntTreeSet*, int);
260
+ AUTOC_EXTERN int IntTreeSetItMove(IntTreeSetIt*);
261
+ AUTOC_EXTERN int IntTreeSetItGet(IntTreeSetIt*);
262
+ AUTOC_EXTERN int IntTreeSetPeekLowest(IntTreeSet*);
263
+ AUTOC_EXTERN int IntTreeSetPeekHighest(IntTreeSet*);
264
+ /***
265
+ **** ValueHashSet<Value>
266
+ ***/
267
+ typedef struct ValueHashSetListNode ValueHashSetListNode;
268
+ typedef struct ValueHashSetList ValueHashSetList;
269
+ typedef struct ValueHashSetListIt ValueHashSetListIt;
270
+ struct ValueHashSetList {
271
+ ValueHashSetListNode* head_node;
272
+ size_t node_count;
273
+ };
274
+ struct ValueHashSetListIt {
275
+ int start;
276
+ ValueHashSetList* list;
277
+ ValueHashSetListNode* this_node;
278
+ };
279
+ struct ValueHashSetListNode {
280
+ Value element;
281
+ ValueHashSetListNode* next_node;
282
+ };
283
+ typedef struct ValueHashSet ValueHashSet;
284
+ typedef struct ValueHashSetIt ValueHashSetIt;
285
+ struct ValueHashSet {
286
+ ValueHashSetList* buckets;
287
+ size_t bucket_count, min_bucket_count;
288
+ size_t size, min_size, max_size;
289
+ unsigned min_fill, max_fill, capacity_multiplier; /* ?*1e-2 */
290
+ };
291
+ struct ValueHashSetIt {
292
+ ValueHashSet* set;
293
+ size_t bucket_index;
294
+ ValueHashSetListIt it;
295
+ };
296
+ #define _ValueHashSetCtor(self) ValueHashSetCtor(&self)
297
+ #define _ValueHashSetDtor(self) ValueHashSetDtor(&self)
298
+ #define _ValueHashSetIdentify(self) ValueHashSetIdentify(&self)
299
+ #define _ValueHashSetCopy(dst,src) ValueHashSetCopy(&dst,&src)
300
+ #define _ValueHashSetEqual(lt,rt) ValueHashSetEqual(&lt,&rt)
301
+ #define _ValueHashSetLess(lt,rt) ValueHashSetLess(&lt,&rt)
302
+ AUTOC_EXTERN void ValueHashSetCtor(ValueHashSet*);
303
+ AUTOC_EXTERN void ValueHashSetDtor(ValueHashSet*);
304
+ AUTOC_EXTERN void ValueHashSetCopy(ValueHashSet*,ValueHashSet*);
305
+ AUTOC_EXTERN int ValueHashSetEqual(ValueHashSet*,ValueHashSet*);
306
+ AUTOC_EXTERN size_t ValueHashSetIdentify(ValueHashSet*);
307
+ AUTOC_EXTERN void ValueHashSetPurge(ValueHashSet*);
308
+ AUTOC_EXTERN int ValueHashSetContains(ValueHashSet*, Value);
309
+ AUTOC_EXTERN Value ValueHashSetGet(ValueHashSet*, Value);
310
+ AUTOC_EXTERN size_t ValueHashSetSize(ValueHashSet*);
311
+ #define ValueHashSetEmpty(self) (ValueHashSetSize(self) == 0)
312
+ AUTOC_EXTERN int ValueHashSetPut(ValueHashSet*, Value);
313
+ AUTOC_EXTERN int ValueHashSetReplace(ValueHashSet*, Value);
314
+ AUTOC_EXTERN int ValueHashSetRemove(ValueHashSet*, Value);
315
+ AUTOC_EXTERN void ValueHashSetExclude(ValueHashSet*, ValueHashSet*);
316
+ AUTOC_EXTERN void ValueHashSetRetain(ValueHashSet*, ValueHashSet*);
317
+ AUTOC_EXTERN void ValueHashSetInclude(ValueHashSet*, ValueHashSet*);
318
+ AUTOC_EXTERN void ValueHashSetInvert(ValueHashSet*, ValueHashSet*);
319
+ AUTOC_EXTERN void ValueHashSetItCtor(ValueHashSetIt*, ValueHashSet*);
320
+ AUTOC_EXTERN int ValueHashSetItMove(ValueHashSetIt*);
321
+ AUTOC_EXTERN Value ValueHashSetItGet(ValueHashSetIt*);
322
+ /***
323
+ **** ValueVector<Value>
324
+ ***/
325
+ typedef struct ValueVector ValueVector;
326
+ typedef struct ValueVectorIt ValueVectorIt;
327
+ struct ValueVector {
328
+ Value* values;
329
+ size_t element_count;
330
+ };
331
+ struct ValueVectorIt {
332
+ ValueVector* vector;
333
+ int index, forward;
334
+ };
335
+ #define _ValueVectorCtor(self,element_count) ValueVectorCtor(&self,element_count)
336
+ #define _ValueVectorDtor(self) ValueVectorDtor(&self)
337
+ #define _ValueVectorIdentify(self) ValueVectorIdentify(&self)
338
+ #define _ValueVectorCopy(dst,src) ValueVectorCopy(&dst,&src)
339
+ #define _ValueVectorEqual(lt,rt) ValueVectorEqual(&lt,&rt)
340
+ #define _ValueVectorLess(lt,rt) ValueVectorLess(&lt,&rt)
341
+ AUTOC_INLINE void ValueVectorItCtor(ValueVectorIt*, ValueVector*);
342
+ #define ValueVectorItCtor(self, type) ValueVectorItCtorEx(self, type, 1)
343
+ AUTOC_INLINE void ValueVectorItCtorEx(ValueVectorIt*, ValueVector*, int);
344
+ AUTOC_INLINE int ValueVectorItMove(ValueVectorIt*);
345
+ AUTOC_INLINE Value ValueVectorItGet(ValueVectorIt*);
346
+ AUTOC_EXTERN void ValueVectorCtor(ValueVector*,size_t);
347
+ AUTOC_EXTERN void ValueVectorDtor(ValueVector*);
348
+ AUTOC_EXTERN void ValueVectorCopy(ValueVector*,ValueVector*);
349
+ /* TODO ValueVectorCopyRange() */
350
+ AUTOC_EXTERN int ValueVectorEqual(ValueVector*,ValueVector*);
351
+ AUTOC_EXTERN size_t ValueVectorIdentify(ValueVector*);
352
+ AUTOC_EXTERN void ValueVectorResize(ValueVector*, size_t);
353
+ AUTOC_INLINE size_t ValueVectorSize(ValueVector* self) {
354
+ assert(self);
355
+ return self->element_count;
356
+ }
357
+ AUTOC_INLINE int ValueVectorWithin(ValueVector* self, size_t index) {
358
+ assert(self);
359
+ return index < ValueVectorSize(self);
360
+ }
361
+ AUTOC_INLINE Value ValueVectorGet(ValueVector* self, size_t index) {
362
+ Value result;
363
+ assert(self);
364
+ assert(ValueVectorWithin(self, index));
365
+ ValueCopy(result,self->values[index]);
366
+ return result;
367
+ }
368
+ AUTOC_INLINE void ValueVectorSet(ValueVector* self, size_t index, Value value) {
369
+ assert(self);
370
+ assert(ValueVectorWithin(self, index));
371
+ ValueDtor(self->values[index]);
372
+ ValueCopy(self->values[index],value);
373
+ }
374
+ AUTOC_INLINE void ValueVectorItCtorEx(ValueVectorIt* self, ValueVector* vector, int forward) {
375
+ assert(self);
376
+ assert(vector);
377
+ self->vector = vector;
378
+ self->forward = forward;
379
+ self->index = forward ? -1 : ValueVectorSize(vector);
380
+ }
381
+ AUTOC_INLINE int ValueVectorItMove(ValueVectorIt* self) {
382
+ assert(self);
383
+ if(self->forward) ++self->index;
384
+ else --self->index;
385
+ return ValueVectorWithin(self->vector, self->index);
386
+ }
387
+ AUTOC_INLINE Value ValueVectorItGet(ValueVectorIt* self) {
388
+ assert(self);
389
+ return ValueVectorGet(self->vector, self->index);
390
+ }
391
+ #define ValueVectorSort(self) ValueVectorSortEx(self, 1)
392
+ AUTOC_EXTERN void ValueVectorSortEx(ValueVector*, int);
393
+ /***
394
+ **** ValueList<Value>
395
+ ***/
396
+ typedef struct ValueListNode ValueListNode;
397
+ typedef struct ValueList ValueList;
398
+ typedef struct ValueListIt ValueListIt;
399
+ struct ValueList {
400
+ ValueListNode* head_node;
401
+ size_t node_count;
402
+ };
403
+ struct ValueListIt {
404
+ int start;
405
+ ValueList* list;
406
+ ValueListNode* this_node;
407
+ };
408
+ struct ValueListNode {
409
+ Value element;
410
+ ValueListNode* next_node;
411
+ };
412
+ #define _ValueListCtor(self) ValueListCtor(&self)
413
+ #define _ValueListDtor(self) ValueListDtor(&self)
414
+ #define _ValueListIdentify(self) ValueListIdentify(&self)
415
+ #define _ValueListCopy(dst,src) ValueListCopy(&dst,&src)
416
+ #define _ValueListEqual(lt,rt) ValueListEqual(&lt,&rt)
417
+ #define _ValueListLess(lt,rt) ValueListLess(&lt,&rt)
418
+ AUTOC_EXTERN void ValueListItCtor(ValueListIt*, ValueList*);
419
+ AUTOC_EXTERN int ValueListItMove(ValueListIt*);
420
+ AUTOC_EXTERN Value ValueListItGet(ValueListIt*);
421
+ AUTOC_EXTERN void ValueListCtor(ValueList*);
422
+ AUTOC_EXTERN void ValueListDtor(ValueList*);
423
+ AUTOC_EXTERN void ValueListCopy(ValueList*,ValueList*);
424
+ AUTOC_EXTERN int ValueListEqual(ValueList*,ValueList*);
425
+ AUTOC_EXTERN size_t ValueListIdentify(ValueList*);
426
+ AUTOC_EXTERN void ValueListPurge(ValueList*);
427
+ AUTOC_EXTERN Value ValueListPeek(ValueList*);
428
+ AUTOC_EXTERN Value ValueListPop(ValueList*);
429
+ AUTOC_EXTERN void ValueListPush(ValueList*, Value);
430
+ AUTOC_EXTERN int ValueListContains(ValueList*, Value);
431
+ AUTOC_EXTERN Value ValueListFind(ValueList*, Value);
432
+ #define ValueListReplace(self, with) ValueListReplaceEx(self, with, 1)
433
+ #define ValueListReplaceAll(self, with) ValueListReplaceEx(self, with, -1)
434
+ AUTOC_EXTERN int ValueListReplaceEx(ValueList*, Value, int);
435
+ #define ValueListRemove(self, what) ValueListRemoveEx(self, what, 1)
436
+ #define ValueListRemoveAll(self, what) ValueListRemoveEx(self, what, -1)
437
+ AUTOC_EXTERN int ValueListRemoveEx(ValueList*, Value, int);
438
+ AUTOC_EXTERN size_t ValueListSize(ValueList*);
439
+ #define ValueListEmpty(self) (ValueListSize(self) == 0)
440
+ /***
441
+ **** IntVector<int>
442
+ ***/
443
+ typedef struct IntVector IntVector;
444
+ typedef struct IntVectorIt IntVectorIt;
445
+ struct IntVector {
446
+ int* values;
447
+ size_t element_count;
448
+ };
449
+ struct IntVectorIt {
450
+ IntVector* vector;
451
+ int index, forward;
452
+ };
453
+ #define _IntVectorCtor(self,element_count) IntVectorCtor(&self,element_count)
454
+ #define _IntVectorDtor(self) IntVectorDtor(&self)
455
+ #define _IntVectorIdentify(self) IntVectorIdentify(&self)
456
+ #define _IntVectorCopy(dst,src) IntVectorCopy(&dst,&src)
457
+ #define _IntVectorEqual(lt,rt) IntVectorEqual(&lt,&rt)
458
+ #define _IntVectorLess(lt,rt) IntVectorLess(&lt,&rt)
459
+ AUTOC_INLINE void IntVectorItCtor(IntVectorIt*, IntVector*);
460
+ #define IntVectorItCtor(self, type) IntVectorItCtorEx(self, type, 1)
461
+ AUTOC_INLINE void IntVectorItCtorEx(IntVectorIt*, IntVector*, int);
462
+ AUTOC_INLINE int IntVectorItMove(IntVectorIt*);
463
+ AUTOC_INLINE int IntVectorItGet(IntVectorIt*);
464
+ AUTOC_EXTERN void IntVectorCtor(IntVector*,size_t);
465
+ AUTOC_EXTERN void IntVectorDtor(IntVector*);
466
+ AUTOC_EXTERN void IntVectorCopy(IntVector*,IntVector*);
467
+ /* TODO IntVectorCopyRange() */
468
+ AUTOC_EXTERN int IntVectorEqual(IntVector*,IntVector*);
469
+ AUTOC_EXTERN size_t IntVectorIdentify(IntVector*);
470
+ AUTOC_EXTERN void IntVectorResize(IntVector*, size_t);
471
+ AUTOC_INLINE size_t IntVectorSize(IntVector* self) {
472
+ assert(self);
473
+ return self->element_count;
474
+ }
475
+ AUTOC_INLINE int IntVectorWithin(IntVector* self, size_t index) {
476
+ assert(self);
477
+ return index < IntVectorSize(self);
478
+ }
479
+ AUTOC_INLINE int IntVectorGet(IntVector* self, size_t index) {
480
+ int result;
481
+ assert(self);
482
+ assert(IntVectorWithin(self, index));
483
+ ((result) = (self->values[index]));
484
+ return result;
485
+ }
486
+ AUTOC_INLINE void IntVectorSet(IntVector* self, size_t index, int value) {
487
+ assert(self);
488
+ assert(IntVectorWithin(self, index));
489
+ ;
490
+ ((self->values[index]) = (value));
491
+ }
492
+ AUTOC_INLINE void IntVectorItCtorEx(IntVectorIt* self, IntVector* vector, int forward) {
493
+ assert(self);
494
+ assert(vector);
495
+ self->vector = vector;
496
+ self->forward = forward;
497
+ self->index = forward ? -1 : IntVectorSize(vector);
498
+ }
499
+ AUTOC_INLINE int IntVectorItMove(IntVectorIt* self) {
500
+ assert(self);
501
+ if(self->forward) ++self->index;
502
+ else --self->index;
503
+ return IntVectorWithin(self->vector, self->index);
504
+ }
505
+ AUTOC_INLINE int IntVectorItGet(IntVectorIt* self) {
506
+ assert(self);
507
+ return IntVectorGet(self->vector, self->index);
508
+ }
509
+ #define IntVectorSort(self) IntVectorSortEx(self, 1)
510
+ AUTOC_EXTERN void IntVectorSortEx(IntVector*, int);
511
+ /***
512
+ **** ValueQueue<Value>
513
+ ***/
514
+ typedef struct ValueQueueNode ValueQueueNode;
515
+ typedef struct ValueQueue ValueQueue;
516
+ typedef struct ValueQueueIt ValueQueueIt;
517
+ struct ValueQueue {
518
+ ValueQueueNode* head_node;
519
+ ValueQueueNode* tail_node;
520
+ size_t node_count;
521
+ };
522
+ struct ValueQueueIt {
523
+ int start, forward;
524
+ ValueQueue* queue;
525
+ ValueQueueNode* this_node;
526
+ };
527
+ struct ValueQueueNode {
528
+ Value element;
529
+ ValueQueueNode* prev_node;
530
+ ValueQueueNode* next_node;
531
+ };
532
+ #define _ValueQueueCtor(self) ValueQueueCtor(&self)
533
+ #define _ValueQueueDtor(self) ValueQueueDtor(&self)
534
+ #define _ValueQueueIdentify(self) ValueQueueIdentify(&self)
535
+ #define _ValueQueueCopy(dst,src) ValueQueueCopy(&dst,&src)
536
+ #define _ValueQueueEqual(lt,rt) ValueQueueEqual(&lt,&rt)
537
+ #define _ValueQueueLess(lt,rt) ValueQueueLess(&lt,&rt)
538
+ AUTOC_EXTERN void ValueQueueItCtor(ValueQueueIt*, ValueQueue*);
539
+ #define ValueQueueItCtor(self, type) ValueQueueItCtorEx(self, type, 1)
540
+ AUTOC_EXTERN void ValueQueueItCtorEx(ValueQueueIt*, ValueQueue*, int);
541
+ AUTOC_EXTERN int ValueQueueItMove(ValueQueueIt*);
542
+ AUTOC_EXTERN Value ValueQueueItGet(ValueQueueIt*);
543
+ AUTOC_EXTERN void ValueQueueCtor(ValueQueue*);
544
+ AUTOC_EXTERN void ValueQueueDtor(ValueQueue*);
545
+ AUTOC_EXTERN void ValueQueueCopy(ValueQueue*,ValueQueue*);
546
+ AUTOC_EXTERN int ValueQueueEqual(ValueQueue*,ValueQueue*);
547
+ AUTOC_EXTERN size_t ValueQueueIdentify(ValueQueue*);
548
+ AUTOC_EXTERN void ValueQueuePurge(ValueQueue*);
549
+ #define ValueQueuePeek(self) ValueQueuePeekHead(self)
550
+ AUTOC_EXTERN Value ValueQueuePeekHead(ValueQueue*);
551
+ AUTOC_EXTERN Value ValueQueuePeekTail(ValueQueue*);
552
+ #define ValueQueuePush(self, element) ValueQueuePushTail(self, element)
553
+ AUTOC_EXTERN void ValueQueuePushTail(ValueQueue*, Value);
554
+ AUTOC_EXTERN void ValueQueuePushHead(ValueQueue*, Value);
555
+ #define ValueQueuePop(self) ValueQueuePopHead(self)
556
+ AUTOC_EXTERN Value ValueQueuePopHead(ValueQueue*);
557
+ AUTOC_EXTERN Value ValueQueuePopTail(ValueQueue*);
558
+ AUTOC_EXTERN int ValueQueueContains(ValueQueue*, Value);
559
+ AUTOC_EXTERN Value ValueQueueFind(ValueQueue*, Value);
560
+ #define ValueQueueReplace(self, with) ValueQueueReplaceEx(self, with, 1)
561
+ #define ValueQueueReplaceAll(self, with) ValueQueueReplaceEx(self, with, -1)
562
+ AUTOC_EXTERN int ValueQueueReplaceEx(ValueQueue*, Value, int);
563
+ #define ValueQueueRemove(self, what) ValueQueueRemoveEx(self, what, 1)
564
+ #define ValueQueueRemoveAll(self, what) ValueQueueRemoveEx(self, what, -1)
565
+ AUTOC_EXTERN int ValueQueueRemoveEx(ValueQueue*, Value, int);
566
+ AUTOC_EXTERN size_t ValueQueueSize(ValueQueue*);
567
+ #define ValueQueueEmpty(self) (ValueQueueSize(self) == 0)
568
+ /***
569
+ **** ValueTreeMap<Value -> Value>
570
+ ***/
571
+ typedef struct ValueTreeMapEntry ValueTreeMapEntry;
572
+ struct ValueTreeMapEntry {
573
+ Value key;
574
+ Value value;
575
+ unsigned flags;
576
+ };
577
+ typedef struct ValueTreeMapSet ValueTreeMapSet;
578
+ typedef struct ValueTreeMapSetNode ValueTreeMapSetNode;
579
+ typedef struct ValueTreeMapSetIt ValueTreeMapSetIt;
580
+ struct ValueTreeMapSet {
581
+ ValueTreeMapSetNode* root;
582
+ size_t size;
583
+ };
584
+ struct ValueTreeMapSetIt {
585
+ int start, ascending;
586
+ ValueTreeMapSetNode* node;
587
+ };
588
+ struct ValueTreeMapSetNode {
589
+ int color;
590
+ ValueTreeMapSetNode* left;
591
+ ValueTreeMapSetNode* right;
592
+ ValueTreeMapSetNode* parent;
593
+ ValueTreeMapEntry element;
594
+ };
595
+ typedef struct ValueTreeMap ValueTreeMap;
596
+ typedef struct ValueTreeMapIt ValueTreeMapIt;
597
+ struct ValueTreeMap {
598
+ ValueTreeMapSet entries;
599
+ };
600
+ struct ValueTreeMapIt {
601
+ ValueTreeMapSetIt it;
602
+ };
603
+ #define _ValueTreeMapCtor(self) ValueTreeMapCtor(&self)
604
+ #define _ValueTreeMapDtor(self) ValueTreeMapDtor(&self)
605
+ #define _ValueTreeMapIdentify(self) ValueTreeMapIdentify(&self)
606
+ #define _ValueTreeMapCopy(dst,src) ValueTreeMapCopy(&dst,&src)
607
+ #define _ValueTreeMapEqual(lt,rt) ValueTreeMapEqual(&lt,&rt)
608
+ #define _ValueTreeMapLess(lt,rt) ValueTreeMapLess(&lt,&rt)
609
+ AUTOC_EXTERN void ValueTreeMapCtor(ValueTreeMap*);
610
+ AUTOC_EXTERN void ValueTreeMapDtor(ValueTreeMap*);
611
+ AUTOC_EXTERN void ValueTreeMapCopy(ValueTreeMap*,ValueTreeMap*);
612
+ AUTOC_EXTERN int ValueTreeMapEqual(ValueTreeMap*,ValueTreeMap*);
613
+ AUTOC_EXTERN size_t ValueTreeMapIdentify(ValueTreeMap*);
614
+ AUTOC_EXTERN void ValueTreeMapPurge(ValueTreeMap*);
615
+ AUTOC_EXTERN size_t ValueTreeMapSize(ValueTreeMap*);
616
+ #define ValueTreeMapEmpty(self) (ValueTreeMapSize(self) == 0)
617
+ AUTOC_EXTERN int ValueTreeMapContainsKey(ValueTreeMap*, Value);
618
+ AUTOC_EXTERN Value ValueTreeMapGet(ValueTreeMap*, Value);
619
+ AUTOC_EXTERN int ValueTreeMapPut(ValueTreeMap*, Value, Value);
620
+ AUTOC_EXTERN int ValueTreeMapReplace(ValueTreeMap*, Value, Value);
621
+ AUTOC_EXTERN int ValueTreeMapRemove(ValueTreeMap*, Value);
622
+ AUTOC_EXTERN int ValueTreeMapItMove(ValueTreeMapIt*);
623
+ AUTOC_EXTERN Value ValueTreeMapItGetKey(ValueTreeMapIt*);
624
+ AUTOC_EXTERN Value ValueTreeMapItGetElement(ValueTreeMapIt*);
625
+ #define ValueTreeMapItGet(it) ValueTreeMapItGetElement(it)
626
+ AUTOC_EXTERN Value ValueTreeMapPeekLowestKey(ValueTreeMap*);
627
+ AUTOC_EXTERN Value ValueTreeMapPeekLowestElement(ValueTreeMap*);
628
+ AUTOC_EXTERN Value ValueTreeMapPeekHighestKey(ValueTreeMap*);
629
+ AUTOC_EXTERN Value ValueTreeMapPeekHighestElement(ValueTreeMap*);
630
+ #define ValueTreeMapItCtor(self, type) ValueTreeMapItCtorEx(self, type, 1)
631
+ AUTOC_EXTERN void ValueTreeMapItCtorEx(ValueTreeMapIt*, ValueTreeMap*, int);
632
+ /***
633
+ **** ValueHashMap<Value -> Value>
634
+ ***/
635
+ typedef struct ValueHashMapEntry ValueHashMapEntry;
636
+ struct ValueHashMapEntry {
637
+ Value key;
638
+ Value value;
639
+ unsigned flags;
640
+ };
641
+ typedef struct ValueHashMapSetListNode ValueHashMapSetListNode;
642
+ typedef struct ValueHashMapSetList ValueHashMapSetList;
643
+ typedef struct ValueHashMapSetListIt ValueHashMapSetListIt;
644
+ struct ValueHashMapSetList {
645
+ ValueHashMapSetListNode* head_node;
646
+ size_t node_count;
647
+ };
648
+ struct ValueHashMapSetListIt {
649
+ int start;
650
+ ValueHashMapSetList* list;
651
+ ValueHashMapSetListNode* this_node;
652
+ };
653
+ struct ValueHashMapSetListNode {
654
+ ValueHashMapEntry element;
655
+ ValueHashMapSetListNode* next_node;
656
+ };
657
+ typedef struct ValueHashMapSet ValueHashMapSet;
658
+ typedef struct ValueHashMapSetIt ValueHashMapSetIt;
659
+ struct ValueHashMapSet {
660
+ ValueHashMapSetList* buckets;
661
+ size_t bucket_count, min_bucket_count;
662
+ size_t size, min_size, max_size;
663
+ unsigned min_fill, max_fill, capacity_multiplier; /* ?*1e-2 */
664
+ };
665
+ struct ValueHashMapSetIt {
666
+ ValueHashMapSet* set;
667
+ size_t bucket_index;
668
+ ValueHashMapSetListIt it;
669
+ };
670
+ typedef struct ValueHashMap ValueHashMap;
671
+ typedef struct ValueHashMapIt ValueHashMapIt;
672
+ struct ValueHashMap {
673
+ ValueHashMapSet entries;
674
+ };
675
+ struct ValueHashMapIt {
676
+ ValueHashMapSetIt it;
677
+ };
678
+ #define _ValueHashMapCtor(self) ValueHashMapCtor(&self)
679
+ #define _ValueHashMapDtor(self) ValueHashMapDtor(&self)
680
+ #define _ValueHashMapIdentify(self) ValueHashMapIdentify(&self)
681
+ #define _ValueHashMapCopy(dst,src) ValueHashMapCopy(&dst,&src)
682
+ #define _ValueHashMapEqual(lt,rt) ValueHashMapEqual(&lt,&rt)
683
+ #define _ValueHashMapLess(lt,rt) ValueHashMapLess(&lt,&rt)
684
+ AUTOC_EXTERN void ValueHashMapCtor(ValueHashMap*);
685
+ AUTOC_EXTERN void ValueHashMapDtor(ValueHashMap*);
686
+ AUTOC_EXTERN void ValueHashMapCopy(ValueHashMap*,ValueHashMap*);
687
+ AUTOC_EXTERN int ValueHashMapEqual(ValueHashMap*,ValueHashMap*);
688
+ AUTOC_EXTERN size_t ValueHashMapIdentify(ValueHashMap*);
689
+ AUTOC_EXTERN void ValueHashMapPurge(ValueHashMap*);
690
+ AUTOC_EXTERN size_t ValueHashMapSize(ValueHashMap*);
691
+ #define ValueHashMapEmpty(self) (ValueHashMapSize(self) == 0)
692
+ AUTOC_EXTERN int ValueHashMapContainsKey(ValueHashMap*, Value);
693
+ AUTOC_EXTERN Value ValueHashMapGet(ValueHashMap*, Value);
694
+ AUTOC_EXTERN int ValueHashMapPut(ValueHashMap*, Value, Value);
695
+ AUTOC_EXTERN int ValueHashMapReplace(ValueHashMap*, Value, Value);
696
+ AUTOC_EXTERN int ValueHashMapRemove(ValueHashMap*, Value);
697
+ AUTOC_EXTERN int ValueHashMapItMove(ValueHashMapIt*);
698
+ AUTOC_EXTERN Value ValueHashMapItGetKey(ValueHashMapIt*);
699
+ AUTOC_EXTERN Value ValueHashMapItGetElement(ValueHashMapIt*);
700
+ #define ValueHashMapItGet(it) ValueHashMapItGetElement(it)
701
+ AUTOC_EXTERN void ValueHashMapItCtor(ValueHashMapIt*, ValueHashMap*);
702
+ /***
703
+ **** ValueTreeSet<Value>
704
+ ***/
705
+ typedef struct ValueTreeSet ValueTreeSet;
706
+ typedef struct ValueTreeSetNode ValueTreeSetNode;
707
+ typedef struct ValueTreeSetIt ValueTreeSetIt;
708
+ struct ValueTreeSet {
709
+ ValueTreeSetNode* root;
710
+ size_t size;
711
+ };
712
+ struct ValueTreeSetIt {
713
+ int start, ascending;
714
+ ValueTreeSetNode* node;
715
+ };
716
+ struct ValueTreeSetNode {
717
+ int color;
718
+ ValueTreeSetNode* left;
719
+ ValueTreeSetNode* right;
720
+ ValueTreeSetNode* parent;
721
+ Value element;
722
+ };
723
+ #define _ValueTreeSetCtor(self) ValueTreeSetCtor(&self)
724
+ #define _ValueTreeSetDtor(self) ValueTreeSetDtor(&self)
725
+ #define _ValueTreeSetIdentify(self) ValueTreeSetIdentify(&self)
726
+ #define _ValueTreeSetCopy(dst,src) ValueTreeSetCopy(&dst,&src)
727
+ #define _ValueTreeSetEqual(lt,rt) ValueTreeSetEqual(&lt,&rt)
728
+ #define _ValueTreeSetLess(lt,rt) ValueTreeSetLess(&lt,&rt)
729
+ AUTOC_EXTERN void ValueTreeSetCtor(ValueTreeSet*);
730
+ AUTOC_EXTERN void ValueTreeSetDtor(ValueTreeSet*);
731
+ AUTOC_EXTERN void ValueTreeSetCopy(ValueTreeSet*,ValueTreeSet*);
732
+ AUTOC_EXTERN int ValueTreeSetEqual(ValueTreeSet*,ValueTreeSet*);
733
+ AUTOC_EXTERN size_t ValueTreeSetIdentify(ValueTreeSet*);
734
+ AUTOC_EXTERN void ValueTreeSetPurge(ValueTreeSet*);
735
+ AUTOC_EXTERN int ValueTreeSetContains(ValueTreeSet*, Value);
736
+ AUTOC_EXTERN Value ValueTreeSetGet(ValueTreeSet*, Value);
737
+ AUTOC_EXTERN size_t ValueTreeSetSize(ValueTreeSet*);
738
+ #define ValueTreeSetEmpty(self) (ValueTreeSetSize(self) == 0)
739
+ AUTOC_EXTERN int ValueTreeSetPut(ValueTreeSet*, Value);
740
+ AUTOC_EXTERN int ValueTreeSetReplace(ValueTreeSet*, Value);
741
+ AUTOC_EXTERN int ValueTreeSetRemove(ValueTreeSet*, Value);
742
+ AUTOC_EXTERN void ValueTreeSetExclude(ValueTreeSet*, ValueTreeSet*);
743
+ AUTOC_EXTERN void ValueTreeSetRetain(ValueTreeSet*, ValueTreeSet*);
744
+ AUTOC_EXTERN void ValueTreeSetInclude(ValueTreeSet*, ValueTreeSet*);
745
+ AUTOC_EXTERN void ValueTreeSetInvert(ValueTreeSet*, ValueTreeSet*);
746
+ AUTOC_EXTERN void ValueTreeSetItCtor(ValueTreeSetIt*, ValueTreeSet*);
747
+ #define ValueTreeSetItCtor(self, type) ValueTreeSetItCtorEx(self, type, 1)
748
+ AUTOC_EXTERN void ValueTreeSetItCtorEx(ValueTreeSetIt*, ValueTreeSet*, int);
749
+ AUTOC_EXTERN int ValueTreeSetItMove(ValueTreeSetIt*);
750
+ AUTOC_EXTERN Value ValueTreeSetItGet(ValueTreeSetIt*);
751
+ AUTOC_EXTERN Value ValueTreeSetPeekLowest(ValueTreeSet*);
752
+ AUTOC_EXTERN Value ValueTreeSetPeekHighest(ValueTreeSet*);
753
+ #endif