autoc 1.1 → 1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.yardopts +3 -1
- data/CHANGES +15 -0
- data/README +2 -0
- data/doc/AutoC.html +84 -14
- data/doc/AutoC/Code.html +31 -31
- data/doc/AutoC/Collection.html +250 -182
- data/doc/AutoC/HashMap.html +565 -245
- data/doc/AutoC/HashSet.html +266 -264
- data/doc/AutoC/List.html +317 -249
- data/doc/AutoC/Module.html +66 -72
- data/doc/AutoC/Module/File.html +25 -25
- data/doc/AutoC/Module/Header.html +25 -25
- data/doc/AutoC/Module/Source.html +43 -43
- data/doc/AutoC/Priority.html +3 -3
- data/doc/AutoC/Queue.html +352 -286
- data/doc/AutoC/Reference.html +578 -0
- data/doc/AutoC/Type.html +941 -131
- data/doc/AutoC/UserDefinedType.html +64 -313
- data/doc/AutoC/Vector.html +336 -306
- data/doc/_index.html +22 -4
- data/doc/class_list.html +6 -2
- data/doc/file.CHANGES.html +102 -0
- data/doc/file.README.html +7 -4
- data/doc/file_list.html +8 -1
- data/doc/frames.html +1 -1
- data/doc/index.html +7 -4
- data/doc/js/full_list.js +4 -1
- data/doc/method_list.html +236 -118
- data/doc/top-level-namespace.html +3 -3
- data/lib/autoc.rb +3 -3
- data/lib/autoc/code.rb +11 -5
- data/lib/autoc/collection.rb +62 -56
- data/lib/autoc/collection/hash_map.rb +83 -63
- data/lib/autoc/collection/hash_set.rb +74 -64
- data/lib/autoc/collection/list.rb +48 -41
- data/lib/autoc/collection/queue.rb +53 -47
- data/lib/autoc/collection/vector.rb +63 -42
- data/lib/autoc/type.rb +326 -61
- data/test/test.c +120 -0
- data/test/test.rb +16 -2
- data/test/test_auto.c +1683 -987
- data/test/test_auto.h +491 -176
- metadata +22 -19
data/test/test.c
CHANGED
@@ -905,6 +905,122 @@ static void type(Test)() {
|
|
905
905
|
}
|
906
906
|
|
907
907
|
|
908
|
+
#undef Type
|
909
|
+
#define Type ListIntSet
|
910
|
+
#undef TypeIt
|
911
|
+
#define TypeIt ListIntSetIt
|
912
|
+
#undef type
|
913
|
+
#define type(x) ListIntSet##x
|
914
|
+
#undef it
|
915
|
+
#define it(x) ListIntSetIt##x
|
916
|
+
#undef Element
|
917
|
+
#define Element IntSet
|
918
|
+
#undef element
|
919
|
+
#define element(x) IntSet##x
|
920
|
+
|
921
|
+
|
922
|
+
static void type(Test)() {
|
923
|
+
Type c1, c2;
|
924
|
+
Element e;
|
925
|
+
|
926
|
+
type(Ctor)(&c1);
|
927
|
+
type(Ctor)(&c2);
|
928
|
+
|
929
|
+
element(Ctor)(&e);
|
930
|
+
type(Push)(&c1, e);
|
931
|
+
element(Put)(&e, 3);
|
932
|
+
element(Put)(&e, 2);
|
933
|
+
element(Put)(&e, 1);
|
934
|
+
type(Push)(&c2, e);
|
935
|
+
element(Dtor)(&e);
|
936
|
+
|
937
|
+
type(Dtor)(&c1);
|
938
|
+
type(Dtor)(&c2);
|
939
|
+
}
|
940
|
+
|
941
|
+
|
942
|
+
#undef Type
|
943
|
+
#define Type Int
|
944
|
+
#undef type
|
945
|
+
#define type(x) Int##x
|
946
|
+
|
947
|
+
|
948
|
+
static void PIntTest() {
|
949
|
+
int *c1, *c2;
|
950
|
+
c1 = type(New)(); *c1 = 1;
|
951
|
+
c2 = type(New)(); *c2 = 2;
|
952
|
+
assert(*c1 != *c2);
|
953
|
+
type(Free)(c2);
|
954
|
+
c2 = type(Ref)(c1);
|
955
|
+
assert(*c1 == *c2);
|
956
|
+
type(Free)(c1);
|
957
|
+
type(Free)(c2);
|
958
|
+
}
|
959
|
+
|
960
|
+
|
961
|
+
#undef Type
|
962
|
+
#define Type ValueType
|
963
|
+
#undef type
|
964
|
+
#define type(x) ValueType##x
|
965
|
+
|
966
|
+
|
967
|
+
static void PValueTypeTest() {
|
968
|
+
ValueType *c1, *c2;
|
969
|
+
c1 = type(New)();
|
970
|
+
c2 = type(New)();
|
971
|
+
type(Free)(c2);
|
972
|
+
c2 = type(Ref)(c1);
|
973
|
+
type(Free)(c1);
|
974
|
+
type(Free)(c2);
|
975
|
+
}
|
976
|
+
|
977
|
+
|
978
|
+
/* List<Vector<ValueType*>*> */
|
979
|
+
#undef Type
|
980
|
+
#define Type ListPVectorValue
|
981
|
+
#undef TypeIt
|
982
|
+
#define TypeIt ListPVectorValueIt
|
983
|
+
#undef type
|
984
|
+
#define type(x) ListPVectorValue##x
|
985
|
+
#undef it
|
986
|
+
#define it(x) ListPVectorValueIt##x
|
987
|
+
#undef Element
|
988
|
+
#define Element PVectorValue
|
989
|
+
#undef element
|
990
|
+
#define element(x) PVectorValue##x
|
991
|
+
|
992
|
+
|
993
|
+
static void type(Test)() {
|
994
|
+
Type c1, c2;
|
995
|
+
Element *e1, *e2;
|
996
|
+
ValueType *v1, *v2;
|
997
|
+
|
998
|
+
type(Ctor)(&c1);
|
999
|
+
type(Ctor)(&c2);
|
1000
|
+
|
1001
|
+
e1 = element(New)(3);
|
1002
|
+
|
1003
|
+
element(Set)(e1, 1, v1 = ValueTypeNew());
|
1004
|
+
|
1005
|
+
e2 = element(Ref)(e1);
|
1006
|
+
|
1007
|
+
assert(element(Equal)(e1, e2));
|
1008
|
+
|
1009
|
+
element(Set)(e2, 0, v2 = ValueTypeRef(v1));
|
1010
|
+
|
1011
|
+
type(Push)(&c1, e1);
|
1012
|
+
|
1013
|
+
element(Free)(e1);
|
1014
|
+
element(Free)(e2);
|
1015
|
+
|
1016
|
+
type(Dtor)(&c1);
|
1017
|
+
type(Dtor)(&c2);
|
1018
|
+
|
1019
|
+
ValueTypeFree(v1);
|
1020
|
+
ValueTypeFree(v2);
|
1021
|
+
}
|
1022
|
+
|
1023
|
+
|
908
1024
|
int main(int argc, char** argv) {
|
909
1025
|
ValueTypeVectorTest();
|
910
1026
|
ValueTypeListTest();
|
@@ -917,5 +1033,9 @@ int main(int argc, char** argv) {
|
|
917
1033
|
IntSetTestNot1();
|
918
1034
|
IntSetTestNot2();
|
919
1035
|
IntStrMapTest();
|
1036
|
+
ListIntSetTest();
|
1037
|
+
PIntTest();
|
1038
|
+
PValueTypeTest();
|
1039
|
+
ListPVectorValueTest();
|
920
1040
|
return 0;
|
921
1041
|
}
|
data/test/test.rb
CHANGED
@@ -11,12 +11,26 @@ ValueType = {
|
|
11
11
|
:forward => %$#include "test.h"$,
|
12
12
|
}
|
13
13
|
|
14
|
+
PInt = AutoC::Reference.new(:type => "int", :prefix => "Int")
|
15
|
+
|
16
|
+
PValueType = AutoC::Reference.new(ValueType)
|
17
|
+
|
18
|
+
IntVector = AutoC::Vector.new(:IntVector, :int)
|
19
|
+
|
20
|
+
IntSet = AutoC::HashSet.new(:IntSet, :int)
|
21
|
+
|
22
|
+
ListIntSet = AutoC::List.new(:ListIntSet, IntSet)
|
23
|
+
|
14
24
|
AutoC::Module.generate!(:Test) do |c|
|
15
25
|
c << AutoC::Vector.new(:ValueTypeVector, ValueType)
|
16
26
|
c << AutoC::List.new(:ValueTypeList, ValueType)
|
17
27
|
c << AutoC::Queue.new(:ValueTypeQueue, ValueType)
|
18
28
|
c << AutoC::HashSet.new(:ValueTypeSet, ValueType)
|
19
29
|
c << AutoC::HashMap.new(:ValueTypeMap, ValueType, ValueType)
|
20
|
-
c << AutoC::
|
21
|
-
c <<
|
30
|
+
c << AutoC::HashMap.new(:IntStrMap, "int", "const char *")
|
31
|
+
c << ListIntSet
|
32
|
+
c << IntSet
|
33
|
+
c << AutoC::Vector.new(:PIntVector, PInt)
|
34
|
+
c << PInt << PValueType
|
35
|
+
c << AutoC::List.new(:ListPVectorValue, AutoC::Reference.new(AutoC::Vector.new(:PVectorValue, PValueType)))
|
22
36
|
end
|
data/test/test_auto.c
CHANGED
@@ -7,6 +7,28 @@
|
|
7
7
|
#define AUTOC_MAX(a,b) ((a) > (b) ? (a) : (b))
|
8
8
|
#define AUTOC_RCYCLE(x) (((x) << 1) | ((x) >> (sizeof(x)*CHAR_BIT - 1))) /* NOTE : valid for unsigned types only */
|
9
9
|
|
10
|
+
#define AUTOC_COUNTER(p) (*(size_t*)((char*)(p) + sizeof(int)))
|
11
|
+
int* IntNew() {
|
12
|
+
int* self = (int*)malloc(sizeof(int) + sizeof(size_t));
|
13
|
+
assert(self);
|
14
|
+
((*self) = 0);
|
15
|
+
AUTOC_COUNTER(self) = 1;
|
16
|
+
return self;
|
17
|
+
}
|
18
|
+
int* IntRef(int* self) {
|
19
|
+
assert(self);
|
20
|
+
++AUTOC_COUNTER(self);
|
21
|
+
return self;
|
22
|
+
}
|
23
|
+
void IntFree(int* self) {
|
24
|
+
assert(self);
|
25
|
+
if(--AUTOC_COUNTER(self) == 0) {
|
26
|
+
;
|
27
|
+
free(self);
|
28
|
+
}
|
29
|
+
}
|
30
|
+
#undef AUTOC_COUNTER
|
31
|
+
|
10
32
|
#define AUTOC_VALID_VALUE 1
|
11
33
|
#define AUTOC_VALID_KEY 2
|
12
34
|
#define AUTOC_OWNED_VALUE 4
|
@@ -17,7 +39,7 @@ static IntStrMapEntry IntStrMapEntryKeyOnlyRef(int* key) {
|
|
17
39
|
entry.flags = AUTOC_VALID_KEY;
|
18
40
|
return entry;
|
19
41
|
}
|
20
|
-
static IntStrMapEntry IntStrMapEntryKeyValueRef(int* key, const char** value) {
|
42
|
+
static IntStrMapEntry IntStrMapEntryKeyValueRef(int* key, const char ** value) {
|
21
43
|
IntStrMapEntry entry;
|
22
44
|
entry.key = *key;
|
23
45
|
entry.value = *value;
|
@@ -26,20 +48,20 @@ static IntStrMapEntry IntStrMapEntryKeyValueRef(int* key, const char** value) {
|
|
26
48
|
}
|
27
49
|
#define IntStrMapEntryIdentify(obj) IntStrMapEntryIdentifyRef(&obj)
|
28
50
|
static size_t IntStrMapEntryIdentifyRef(IntStrMapEntry* entry) {
|
29
|
-
return (size_t)(entry->key);
|
51
|
+
return ((size_t)(entry->key));
|
30
52
|
}
|
31
53
|
#define IntStrMapEntryEqual(lt, rt) IntStrMapEntryEqualRef(<, &rt)
|
32
54
|
static int IntStrMapEntryEqualRef(IntStrMapEntry* lt, IntStrMapEntry* rt) {
|
33
|
-
return (lt->key == rt->key);
|
55
|
+
return ((lt->key) == (rt->key));
|
34
56
|
}
|
35
57
|
#define IntStrMapEntryCopy(dst, src) IntStrMapEntryCopyRef(&dst, &src)
|
36
58
|
static void IntStrMapEntryCopyRef(IntStrMapEntry* dst, IntStrMapEntry* src) {
|
37
59
|
assert(src->flags & AUTOC_VALID_KEY);
|
38
60
|
dst->flags = (AUTOC_VALID_KEY | AUTOC_OWNED_KEY);
|
39
|
-
(dst->key = src->key);
|
61
|
+
((dst->key) = (src->key));
|
40
62
|
if(src->flags & AUTOC_VALID_VALUE) {
|
41
63
|
dst->flags |= (AUTOC_VALID_VALUE | AUTOC_OWNED_VALUE);
|
42
|
-
(dst->value = src->value);
|
64
|
+
((dst->value) = (src->value));
|
43
65
|
}
|
44
66
|
}
|
45
67
|
#define IntStrMapEntryDtor(obj) IntStrMapEntryDtorRef(&obj)
|
@@ -48,11 +70,34 @@ static void IntStrMapEntryDtorRef(IntStrMapEntry* entry) {
|
|
48
70
|
if(entry->flags & AUTOC_OWNED_KEY) ;
|
49
71
|
if(entry->flags & AUTOC_VALID_VALUE && entry->flags & AUTOC_OWNED_VALUE) ;
|
50
72
|
}
|
73
|
+
static IntStrMapEntry* IntStrMapItGetEntryRef(IntStrMapIt*);
|
74
|
+
static int IntStrMapContainsAllOf(IntStrMap* self, IntStrMap* other) {
|
75
|
+
IntStrMapIt it;
|
76
|
+
IntStrMapItCtor(&it, self);
|
77
|
+
while(IntStrMapItMove(&it)) {
|
78
|
+
int found = 0;
|
79
|
+
IntStrMapEntry* e = IntStrMapItGetEntryRef(&it);
|
80
|
+
if(IntStrMapContainsKey(other, e->key)) {
|
81
|
+
const char * other_value = IntStrMapGet(other, e->key);
|
82
|
+
found = ((e->value) == (other_value));
|
83
|
+
;
|
84
|
+
}
|
85
|
+
if(!found) return 0;
|
86
|
+
}
|
87
|
+
return 1;
|
88
|
+
}
|
89
|
+
|
90
|
+
#define _IntStrMapSetCtor(self) IntStrMapSetCtor(&self)
|
91
|
+
#define _IntStrMapSetDtor(self) IntStrMapSetDtor(&self)
|
92
|
+
#define _IntStrMapSetIdentify(self) IntStrMapSetIdentify(&self)
|
93
|
+
#define _IntStrMapSetCopy(dst,src) IntStrMapSetCopy(&dst,&src)
|
94
|
+
#define _IntStrMapSetEqual(lt,rt) IntStrMapSetEqual(<,&rt)
|
95
|
+
#define _IntStrMapSetLess(lt,rt) IntStrMapSetLess(<,&rt)
|
51
96
|
|
52
97
|
AUTOC_STATIC void IntStrMapSetCtor(IntStrMapSet*);
|
53
98
|
AUTOC_STATIC void IntStrMapSetDtor(IntStrMapSet*);
|
54
|
-
AUTOC_STATIC void IntStrMapSetCopy(IntStrMapSet*,
|
55
|
-
AUTOC_STATIC int IntStrMapSetEqual(IntStrMapSet*,
|
99
|
+
AUTOC_STATIC void IntStrMapSetCopy(IntStrMapSet*,IntStrMapSet*);
|
100
|
+
AUTOC_STATIC int IntStrMapSetEqual(IntStrMapSet*,IntStrMapSet*);
|
56
101
|
AUTOC_STATIC size_t IntStrMapSetIdentify(IntStrMapSet*);
|
57
102
|
AUTOC_STATIC void IntStrMapSetPurge(IntStrMapSet*);
|
58
103
|
AUTOC_STATIC int IntStrMapSetContains(IntStrMapSet*, IntStrMapEntry);
|
@@ -70,10 +115,17 @@ AUTOC_STATIC void IntStrMapSetItCtor(IntStrMapSetIt*, IntStrMapSet*);
|
|
70
115
|
AUTOC_STATIC int IntStrMapSetItMove(IntStrMapSetIt*);
|
71
116
|
AUTOC_STATIC IntStrMapEntry IntStrMapSetItGet(IntStrMapSetIt*);
|
72
117
|
|
118
|
+
#define _IntStrMapSetListCtor(self) IntStrMapSetListCtor(&self)
|
119
|
+
#define _IntStrMapSetListDtor(self) IntStrMapSetListDtor(&self)
|
120
|
+
#define _IntStrMapSetListIdentify(self) IntStrMapSetListIdentify(&self)
|
121
|
+
#define _IntStrMapSetListCopy(dst,src) IntStrMapSetListCopy(&dst,&src)
|
122
|
+
#define _IntStrMapSetListEqual(lt,rt) IntStrMapSetListEqual(<,&rt)
|
123
|
+
#define _IntStrMapSetListLess(lt,rt) IntStrMapSetListLess(<,&rt)
|
124
|
+
|
73
125
|
AUTOC_STATIC void IntStrMapSetListCtor(IntStrMapSetList*);
|
74
126
|
AUTOC_STATIC void IntStrMapSetListDtor(IntStrMapSetList*);
|
75
|
-
AUTOC_STATIC void IntStrMapSetListCopy(IntStrMapSetList*,
|
76
|
-
AUTOC_STATIC int IntStrMapSetListEqual(IntStrMapSetList*,
|
127
|
+
AUTOC_STATIC void IntStrMapSetListCopy(IntStrMapSetList*,IntStrMapSetList*);
|
128
|
+
AUTOC_STATIC int IntStrMapSetListEqual(IntStrMapSetList*,IntStrMapSetList*);
|
77
129
|
AUTOC_STATIC size_t IntStrMapSetListIdentify(IntStrMapSetList*);
|
78
130
|
AUTOC_STATIC void IntStrMapSetListPurge(IntStrMapSetList*);
|
79
131
|
AUTOC_STATIC IntStrMapEntry IntStrMapSetListPeek(IntStrMapSetList*);
|
@@ -110,7 +162,7 @@ AUTOC_STATIC void IntStrMapSetListDtor(IntStrMapSetList* self) {
|
|
110
162
|
free(this_node);
|
111
163
|
}
|
112
164
|
}
|
113
|
-
AUTOC_STATIC void IntStrMapSetListCopy(IntStrMapSetList* dst,
|
165
|
+
AUTOC_STATIC void IntStrMapSetListCopy(IntStrMapSetList* dst,IntStrMapSetList* src) {
|
114
166
|
IntStrMapSetListIt it;
|
115
167
|
assert(src);
|
116
168
|
assert(dst);
|
@@ -120,17 +172,18 @@ AUTOC_STATIC void IntStrMapSetListCopy(IntStrMapSetList* dst, IntStrMapSetList*
|
|
120
172
|
IntStrMapSetListPush(dst, *IntStrMapSetListItGetRef(&it));
|
121
173
|
}
|
122
174
|
}
|
123
|
-
AUTOC_STATIC int IntStrMapSetListEqual(IntStrMapSetList* lt,
|
175
|
+
AUTOC_STATIC int IntStrMapSetListEqual(IntStrMapSetList* lt,IntStrMapSetList* rt) {
|
124
176
|
if(IntStrMapSetListSize(lt) == IntStrMapSetListSize(rt)) {
|
125
177
|
IntStrMapSetListIt lit, rit;
|
126
178
|
IntStrMapSetListItCtor(&lit, lt);
|
127
179
|
IntStrMapSetListItCtor(&rit, rt);
|
128
180
|
while(IntStrMapSetListItMove(&lit) && IntStrMapSetListItMove(&rit)) {
|
129
181
|
int equal;
|
130
|
-
IntStrMapEntry
|
182
|
+
IntStrMapEntry* le;
|
183
|
+
IntStrMapEntry* re;
|
131
184
|
le = IntStrMapSetListItGetRef(&lit);
|
132
185
|
re = IntStrMapSetListItGetRef(&rit);
|
133
|
-
equal = IntStrMapEntryEqual(*le
|
186
|
+
equal = IntStrMapEntryEqual(*le,*re);
|
134
187
|
if(!equal) return 0;
|
135
188
|
}
|
136
189
|
return 1;
|
@@ -155,7 +208,7 @@ AUTOC_STATIC IntStrMapEntry IntStrMapSetListPeek(IntStrMapSetList* self) {
|
|
155
208
|
IntStrMapEntry result;
|
156
209
|
assert(self);
|
157
210
|
assert(!IntStrMapSetListEmpty(self));
|
158
|
-
IntStrMapEntryCopy(result,
|
211
|
+
IntStrMapEntryCopy(result,self->head_node->element);
|
159
212
|
return result;
|
160
213
|
}
|
161
214
|
AUTOC_STATIC IntStrMapEntry IntStrMapSetListPop(IntStrMapSetList* self) {
|
@@ -175,7 +228,7 @@ AUTOC_STATIC void IntStrMapSetListPush(IntStrMapSetList* self, IntStrMapEntry el
|
|
175
228
|
assert(self);
|
176
229
|
node = (IntStrMapSetListNode*)malloc(sizeof(IntStrMapSetListNode));
|
177
230
|
assert(node);
|
178
|
-
IntStrMapEntryCopy(node->element,
|
231
|
+
IntStrMapEntryCopy(node->element,element);
|
179
232
|
node->next_node = self->head_node;
|
180
233
|
self->head_node = node;
|
181
234
|
++self->node_count;
|
@@ -186,7 +239,7 @@ AUTOC_STATIC int IntStrMapSetListContains(IntStrMapSetList* self, IntStrMapEntry
|
|
186
239
|
assert(self);
|
187
240
|
node = self->head_node;
|
188
241
|
while(node) {
|
189
|
-
if(IntStrMapEntryEqual(node->element,
|
242
|
+
if(IntStrMapEntryEqual(node->element,what)) {
|
190
243
|
found = 1;
|
191
244
|
break;
|
192
245
|
}
|
@@ -200,9 +253,9 @@ AUTOC_STATIC IntStrMapEntry IntStrMapSetListFind(IntStrMapSetList* self, IntStrM
|
|
200
253
|
assert(IntStrMapSetListContains(self, what));
|
201
254
|
node = self->head_node;
|
202
255
|
while(node) {
|
203
|
-
if(IntStrMapEntryEqual(node->element,
|
256
|
+
if(IntStrMapEntryEqual(node->element,what)) {
|
204
257
|
IntStrMapEntry result;
|
205
|
-
IntStrMapEntryCopy(result,
|
258
|
+
IntStrMapEntryCopy(result,node->element);
|
206
259
|
return result;
|
207
260
|
}
|
208
261
|
node = node->next_node;
|
@@ -216,9 +269,9 @@ AUTOC_STATIC int IntStrMapSetListReplaceEx(IntStrMapSetList* self, IntStrMapEntr
|
|
216
269
|
if(count == 0) return 0;
|
217
270
|
node = self->head_node;
|
218
271
|
while(node) {
|
219
|
-
if(IntStrMapEntryEqual(node->element,
|
272
|
+
if(IntStrMapEntryEqual(node->element,with)) {
|
220
273
|
IntStrMapEntryDtor(node->element);
|
221
|
-
IntStrMapEntryCopy(node->element,
|
274
|
+
IntStrMapEntryCopy(node->element,with);
|
222
275
|
++replaced;
|
223
276
|
if(count > 0 && replaced >= count) break;
|
224
277
|
}
|
@@ -234,7 +287,7 @@ AUTOC_STATIC int IntStrMapSetListRemoveEx(IntStrMapSetList* self, IntStrMapEntry
|
|
234
287
|
node = self->head_node;
|
235
288
|
prev_node = NULL;
|
236
289
|
while(node) {
|
237
|
-
if(IntStrMapEntryEqual(node->element,
|
290
|
+
if(IntStrMapEntryEqual(node->element,what)) {
|
238
291
|
IntStrMapSetListNode* this_node;
|
239
292
|
if(prev_node) {
|
240
293
|
this_node = prev_node->next_node = node->next_node;
|
@@ -278,7 +331,7 @@ AUTOC_STATIC IntStrMapEntry IntStrMapSetListItGet(IntStrMapSetListIt* self) {
|
|
278
331
|
IntStrMapEntry result;
|
279
332
|
assert(self);
|
280
333
|
assert(self->this_node);
|
281
|
-
IntStrMapEntryCopy(result,
|
334
|
+
IntStrMapEntryCopy(result,self->this_node->element);
|
282
335
|
return result;
|
283
336
|
}
|
284
337
|
AUTOC_STATIC IntStrMapEntry* IntStrMapSetListItGetRef(IntStrMapSetListIt* self) {
|
@@ -334,6 +387,16 @@ static void IntStrMapSetRehash(IntStrMapSet* self) {
|
|
334
387
|
self->bucket_count = bucket_count;
|
335
388
|
self->size = size;
|
336
389
|
}
|
390
|
+
static int IntStrMapSetContainsAllOf(IntStrMapSet* self, IntStrMapSet* other) {
|
391
|
+
IntStrMapSetIt it;
|
392
|
+
IntStrMapSetItCtor(&it, self);
|
393
|
+
while(IntStrMapSetItMove(&it)) {
|
394
|
+
int found = 0;
|
395
|
+
if(IntStrMapSetContains(other, *IntStrMapSetItGetRef(&it))) found = 1;
|
396
|
+
if(!found) return 0;
|
397
|
+
}
|
398
|
+
return 1;
|
399
|
+
}
|
337
400
|
AUTOC_STATIC void IntStrMapSetCtor(IntStrMapSet* self) {
|
338
401
|
assert(self);
|
339
402
|
self->min_bucket_count = 16;
|
@@ -353,7 +416,7 @@ AUTOC_STATIC void IntStrMapSetDtor(IntStrMapSet* self) {
|
|
353
416
|
}
|
354
417
|
free(self->buckets);
|
355
418
|
}
|
356
|
-
AUTOC_STATIC void IntStrMapSetCopy(IntStrMapSet* dst,
|
419
|
+
AUTOC_STATIC void IntStrMapSetCopy(IntStrMapSet* dst,IntStrMapSet* src) {
|
357
420
|
IntStrMapSetIt it;
|
358
421
|
assert(src);
|
359
422
|
assert(dst);
|
@@ -361,17 +424,7 @@ AUTOC_STATIC void IntStrMapSetCopy(IntStrMapSet* dst, IntStrMapSet* src) {
|
|
361
424
|
IntStrMapSetItCtor(&it, src);
|
362
425
|
while(IntStrMapSetItMove(&it)) IntStrMapSetPut(dst, *IntStrMapSetItGetRef(&it));
|
363
426
|
}
|
364
|
-
|
365
|
-
IntStrMapSetIt it;
|
366
|
-
IntStrMapSetItCtor(&it, self);
|
367
|
-
while(IntStrMapSetItMove(&it)) {
|
368
|
-
int found = 0;
|
369
|
-
if(IntStrMapSetContains(other, *IntStrMapSetItGetRef(&it))) found = 1;
|
370
|
-
if(!found) return 0;
|
371
|
-
}
|
372
|
-
return 1;
|
373
|
-
}
|
374
|
-
AUTOC_STATIC int IntStrMapSetEqual(IntStrMapSet* lt, IntStrMapSet* rt) {
|
427
|
+
AUTOC_STATIC int IntStrMapSetEqual(IntStrMapSet* lt,IntStrMapSet* rt) {
|
375
428
|
assert(lt);
|
376
429
|
assert(rt);
|
377
430
|
return IntStrMapSetSize(lt) == IntStrMapSetSize(rt) && IntStrMapSetContainsAllOf(lt, rt) && IntStrMapSetContainsAllOf(rt, lt);
|
@@ -509,7 +562,6 @@ AUTOC_STATIC IntStrMapEntry* IntStrMapSetItGetRef(IntStrMapSetIt* self) {
|
|
509
562
|
return IntStrMapSetListItGetRef(&self->it);
|
510
563
|
}
|
511
564
|
|
512
|
-
static IntStrMapEntry* IntStrMapItGetEntryRef(IntStrMapIt*);
|
513
565
|
void IntStrMapCtor(IntStrMap* self) {
|
514
566
|
assert(self);
|
515
567
|
IntStrMapSetCtor(&self->entries);
|
@@ -527,7 +579,7 @@ static int IntStrMapPutEntryRef(IntStrMap* self, IntStrMapEntry* entry) {
|
|
527
579
|
}
|
528
580
|
return absent;
|
529
581
|
}
|
530
|
-
void IntStrMapCopy(IntStrMap* dst,
|
582
|
+
void IntStrMapCopy(IntStrMap* dst,IntStrMap* src) {
|
531
583
|
IntStrMapIt it;
|
532
584
|
assert(src);
|
533
585
|
assert(dst);
|
@@ -538,22 +590,7 @@ void IntStrMapCopy(IntStrMap* dst, IntStrMap* src) {
|
|
538
590
|
IntStrMapPutEntryRef(dst, e);
|
539
591
|
}
|
540
592
|
}
|
541
|
-
|
542
|
-
IntStrMapIt it;
|
543
|
-
IntStrMapItCtor(&it, self);
|
544
|
-
while(IntStrMapItMove(&it)) {
|
545
|
-
int found = 0;
|
546
|
-
IntStrMapEntry* e = IntStrMapItGetEntryRef(&it);
|
547
|
-
if(IntStrMapContainsKey(other, e->key)) {
|
548
|
-
const char* other_value = IntStrMapGet(other, e->key);
|
549
|
-
found = (e->value == other_value);
|
550
|
-
;
|
551
|
-
}
|
552
|
-
if(!found) return 0;
|
553
|
-
}
|
554
|
-
return 1;
|
555
|
-
}
|
556
|
-
int IntStrMapEqual(IntStrMap* lt, IntStrMap* rt) {
|
593
|
+
int IntStrMapEqual(IntStrMap* lt,IntStrMap* rt) {
|
557
594
|
assert(lt);
|
558
595
|
assert(rt);
|
559
596
|
return IntStrMapSize(lt) == IntStrMapSize(rt) && IntStrMapContainsAllOf(lt, rt) && IntStrMapContainsAllOf(rt, lt);
|
@@ -578,18 +615,18 @@ int IntStrMapContainsKey(IntStrMap* self, int key) {
|
|
578
615
|
IntStrMapEntryDtor(entry);
|
579
616
|
return result;
|
580
617
|
}
|
581
|
-
const char* IntStrMapGet(IntStrMap* self, int key) {
|
582
|
-
const char* result;
|
618
|
+
const char * IntStrMapGet(IntStrMap* self, int key) {
|
619
|
+
const char * result;
|
583
620
|
IntStrMapEntry entry, existing_entry;
|
584
621
|
assert(self);
|
585
622
|
assert(IntStrMapContainsKey(self, key));
|
586
623
|
existing_entry = IntStrMapSetGet(&self->entries, entry = IntStrMapEntryKeyOnlyRef(&key));
|
587
|
-
(result = existing_entry.value);
|
624
|
+
((result) = (existing_entry.value));
|
588
625
|
IntStrMapEntryDtor(existing_entry);
|
589
626
|
IntStrMapEntryDtor(entry);
|
590
627
|
return result;
|
591
628
|
}
|
592
|
-
int IntStrMapPut(IntStrMap* self, int key, const char* value) {
|
629
|
+
int IntStrMapPut(IntStrMap* self, int key, const char * value) {
|
593
630
|
int result;
|
594
631
|
IntStrMapEntry entry;
|
595
632
|
assert(self);
|
@@ -598,7 +635,7 @@ int IntStrMapPut(IntStrMap* self, int key, const char* value) {
|
|
598
635
|
IntStrMapEntryDtor(entry);
|
599
636
|
return result;
|
600
637
|
}
|
601
|
-
int IntStrMapReplace(IntStrMap* self, int key, const char* value) {
|
638
|
+
int IntStrMapReplace(IntStrMap* self, int key, const char * value) {
|
602
639
|
int result;
|
603
640
|
IntStrMapEntry entry;
|
604
641
|
assert(self);
|
@@ -629,16 +666,16 @@ int IntStrMapItGetKey(IntStrMapIt* self) {
|
|
629
666
|
int key;
|
630
667
|
assert(self);
|
631
668
|
e = IntStrMapItGetEntryRef(self);
|
632
|
-
(key = e->key);
|
669
|
+
((key) = (e->key));
|
633
670
|
return key;
|
634
671
|
}
|
635
|
-
const char* IntStrMapItGetElement(IntStrMapIt* self) {
|
672
|
+
const char * IntStrMapItGetElement(IntStrMapIt* self) {
|
636
673
|
IntStrMapEntry* e;
|
637
|
-
const char* value;
|
674
|
+
const char * value;
|
638
675
|
assert(self);
|
639
676
|
e = IntStrMapItGetEntryRef(self);
|
640
677
|
assert(e->flags & AUTOC_VALID_VALUE);
|
641
|
-
(value = e->value);
|
678
|
+
((value) = (e->value));
|
642
679
|
return value;
|
643
680
|
}
|
644
681
|
static IntStrMapEntry* IntStrMapItGetEntryRef(IntStrMapIt* self) {
|
@@ -650,10 +687,17 @@ static IntStrMapEntry* IntStrMapItGetEntryRef(IntStrMapIt* self) {
|
|
650
687
|
#undef AUTOC_OWNED_VALUE
|
651
688
|
#undef AUTOC_OWNED_KEY
|
652
689
|
|
690
|
+
#define _IntSetListCtor(self) IntSetListCtor(&self)
|
691
|
+
#define _IntSetListDtor(self) IntSetListDtor(&self)
|
692
|
+
#define _IntSetListIdentify(self) IntSetListIdentify(&self)
|
693
|
+
#define _IntSetListCopy(dst,src) IntSetListCopy(&dst,&src)
|
694
|
+
#define _IntSetListEqual(lt,rt) IntSetListEqual(<,&rt)
|
695
|
+
#define _IntSetListLess(lt,rt) IntSetListLess(<,&rt)
|
696
|
+
|
653
697
|
AUTOC_STATIC void IntSetListCtor(IntSetList*);
|
654
698
|
AUTOC_STATIC void IntSetListDtor(IntSetList*);
|
655
|
-
AUTOC_STATIC void IntSetListCopy(IntSetList*,
|
656
|
-
AUTOC_STATIC int IntSetListEqual(IntSetList*,
|
699
|
+
AUTOC_STATIC void IntSetListCopy(IntSetList*,IntSetList*);
|
700
|
+
AUTOC_STATIC int IntSetListEqual(IntSetList*,IntSetList*);
|
657
701
|
AUTOC_STATIC size_t IntSetListIdentify(IntSetList*);
|
658
702
|
AUTOC_STATIC void IntSetListPurge(IntSetList*);
|
659
703
|
AUTOC_STATIC int IntSetListPeek(IntSetList*);
|
@@ -690,7 +734,7 @@ AUTOC_STATIC void IntSetListDtor(IntSetList* self) {
|
|
690
734
|
free(this_node);
|
691
735
|
}
|
692
736
|
}
|
693
|
-
AUTOC_STATIC void IntSetListCopy(IntSetList* dst,
|
737
|
+
AUTOC_STATIC void IntSetListCopy(IntSetList* dst,IntSetList* src) {
|
694
738
|
IntSetListIt it;
|
695
739
|
assert(src);
|
696
740
|
assert(dst);
|
@@ -700,17 +744,18 @@ AUTOC_STATIC void IntSetListCopy(IntSetList* dst, IntSetList* src) {
|
|
700
744
|
IntSetListPush(dst, *IntSetListItGetRef(&it));
|
701
745
|
}
|
702
746
|
}
|
703
|
-
AUTOC_STATIC int IntSetListEqual(IntSetList* lt,
|
747
|
+
AUTOC_STATIC int IntSetListEqual(IntSetList* lt,IntSetList* rt) {
|
704
748
|
if(IntSetListSize(lt) == IntSetListSize(rt)) {
|
705
749
|
IntSetListIt lit, rit;
|
706
750
|
IntSetListItCtor(&lit, lt);
|
707
751
|
IntSetListItCtor(&rit, rt);
|
708
752
|
while(IntSetListItMove(&lit) && IntSetListItMove(&rit)) {
|
709
753
|
int equal;
|
710
|
-
int
|
754
|
+
int* le;
|
755
|
+
int* re;
|
711
756
|
le = IntSetListItGetRef(&lit);
|
712
757
|
re = IntSetListItGetRef(&rit);
|
713
|
-
equal = (*le == *re);
|
758
|
+
equal = ((*le) == (*re));
|
714
759
|
if(!equal) return 0;
|
715
760
|
}
|
716
761
|
return 1;
|
@@ -722,7 +767,7 @@ AUTOC_STATIC size_t IntSetListIdentify(IntSetList* self) {
|
|
722
767
|
size_t result = 0;
|
723
768
|
assert(self);
|
724
769
|
for(node = self->head_node; node != NULL; node = node->next_node) {
|
725
|
-
result ^= (size_t)(node->element);
|
770
|
+
result ^= ((size_t)(node->element));
|
726
771
|
result = AUTOC_RCYCLE(result);
|
727
772
|
}
|
728
773
|
return result;
|
@@ -735,7 +780,7 @@ AUTOC_STATIC int IntSetListPeek(IntSetList* self) {
|
|
735
780
|
int result;
|
736
781
|
assert(self);
|
737
782
|
assert(!IntSetListEmpty(self));
|
738
|
-
(result = self->head_node->element);
|
783
|
+
((result) = (self->head_node->element));
|
739
784
|
return result;
|
740
785
|
}
|
741
786
|
AUTOC_STATIC int IntSetListPop(IntSetList* self) {
|
@@ -755,7 +800,7 @@ AUTOC_STATIC void IntSetListPush(IntSetList* self, int element) {
|
|
755
800
|
assert(self);
|
756
801
|
node = (IntSetListNode*)malloc(sizeof(IntSetListNode));
|
757
802
|
assert(node);
|
758
|
-
(node->element = element);
|
803
|
+
((node->element) = (element));
|
759
804
|
node->next_node = self->head_node;
|
760
805
|
self->head_node = node;
|
761
806
|
++self->node_count;
|
@@ -766,7 +811,7 @@ AUTOC_STATIC int IntSetListContains(IntSetList* self, int what) {
|
|
766
811
|
assert(self);
|
767
812
|
node = self->head_node;
|
768
813
|
while(node) {
|
769
|
-
if((node->element == what)) {
|
814
|
+
if(((node->element) == (what))) {
|
770
815
|
found = 1;
|
771
816
|
break;
|
772
817
|
}
|
@@ -780,9 +825,9 @@ AUTOC_STATIC int IntSetListFind(IntSetList* self, int what) {
|
|
780
825
|
assert(IntSetListContains(self, what));
|
781
826
|
node = self->head_node;
|
782
827
|
while(node) {
|
783
|
-
if((node->element == what)) {
|
828
|
+
if(((node->element) == (what))) {
|
784
829
|
int result;
|
785
|
-
(result = node->element);
|
830
|
+
((result) = (node->element));
|
786
831
|
return result;
|
787
832
|
}
|
788
833
|
node = node->next_node;
|
@@ -796,9 +841,9 @@ AUTOC_STATIC int IntSetListReplaceEx(IntSetList* self, int with, int count) {
|
|
796
841
|
if(count == 0) return 0;
|
797
842
|
node = self->head_node;
|
798
843
|
while(node) {
|
799
|
-
if((node->element == with)) {
|
844
|
+
if(((node->element) == (with))) {
|
800
845
|
;
|
801
|
-
(node->element = with);
|
846
|
+
((node->element) = (with));
|
802
847
|
++replaced;
|
803
848
|
if(count > 0 && replaced >= count) break;
|
804
849
|
}
|
@@ -814,7 +859,7 @@ AUTOC_STATIC int IntSetListRemoveEx(IntSetList* self, int what, int count) {
|
|
814
859
|
node = self->head_node;
|
815
860
|
prev_node = NULL;
|
816
861
|
while(node) {
|
817
|
-
if((node->element == what)) {
|
862
|
+
if(((node->element) == (what))) {
|
818
863
|
IntSetListNode* this_node;
|
819
864
|
if(prev_node) {
|
820
865
|
this_node = prev_node->next_node = node->next_node;
|
@@ -858,7 +903,7 @@ AUTOC_STATIC int IntSetListItGet(IntSetListIt* self) {
|
|
858
903
|
int result;
|
859
904
|
assert(self);
|
860
905
|
assert(self->this_node);
|
861
|
-
(result = self->this_node->element);
|
906
|
+
((result) = (self->this_node->element));
|
862
907
|
return result;
|
863
908
|
}
|
864
909
|
AUTOC_STATIC int* IntSetListItGetRef(IntSetListIt* self) {
|
@@ -904,7 +949,7 @@ static void IntSetRehash(IntSet* self) {
|
|
904
949
|
while(IntSetItMove(&it)) {
|
905
950
|
IntSetList* bucket;
|
906
951
|
int element = IntSetItGet(&it);
|
907
|
-
bucket = &buckets[(size_t)(element) % bucket_count];
|
952
|
+
bucket = &buckets[((size_t)(element)) % bucket_count];
|
908
953
|
IntSetListPush(bucket, element);
|
909
954
|
;
|
910
955
|
}
|
@@ -914,6 +959,16 @@ static void IntSetRehash(IntSet* self) {
|
|
914
959
|
self->bucket_count = bucket_count;
|
915
960
|
self->size = size;
|
916
961
|
}
|
962
|
+
static int IntSetContainsAllOf(IntSet* self, IntSet* other) {
|
963
|
+
IntSetIt it;
|
964
|
+
IntSetItCtor(&it, self);
|
965
|
+
while(IntSetItMove(&it)) {
|
966
|
+
int found = 0;
|
967
|
+
if(IntSetContains(other, *IntSetItGetRef(&it))) found = 1;
|
968
|
+
if(!found) return 0;
|
969
|
+
}
|
970
|
+
return 1;
|
971
|
+
}
|
917
972
|
void IntSetCtor(IntSet* self) {
|
918
973
|
assert(self);
|
919
974
|
self->min_bucket_count = 16;
|
@@ -933,7 +988,7 @@ void IntSetDtor(IntSet* self) {
|
|
933
988
|
}
|
934
989
|
free(self->buckets);
|
935
990
|
}
|
936
|
-
void IntSetCopy(IntSet* dst,
|
991
|
+
void IntSetCopy(IntSet* dst,IntSet* src) {
|
937
992
|
IntSetIt it;
|
938
993
|
assert(src);
|
939
994
|
assert(dst);
|
@@ -941,17 +996,7 @@ void IntSetCopy(IntSet* dst, IntSet* src) {
|
|
941
996
|
IntSetItCtor(&it, src);
|
942
997
|
while(IntSetItMove(&it)) IntSetPut(dst, *IntSetItGetRef(&it));
|
943
998
|
}
|
944
|
-
|
945
|
-
IntSetIt it;
|
946
|
-
IntSetItCtor(&it, self);
|
947
|
-
while(IntSetItMove(&it)) {
|
948
|
-
int found = 0;
|
949
|
-
if(IntSetContains(other, *IntSetItGetRef(&it))) found = 1;
|
950
|
-
if(!found) return 0;
|
951
|
-
}
|
952
|
-
return 1;
|
953
|
-
}
|
954
|
-
int IntSetEqual(IntSet* lt, IntSet* rt) {
|
999
|
+
int IntSetEqual(IntSet* lt,IntSet* rt) {
|
955
1000
|
assert(lt);
|
956
1001
|
assert(rt);
|
957
1002
|
return IntSetSize(lt) == IntSetSize(rt) && IntSetContainsAllOf(lt, rt) && IntSetContainsAllOf(rt, lt);
|
@@ -963,7 +1008,7 @@ size_t IntSetIdentify(IntSet* self) {
|
|
963
1008
|
IntSetItCtor(&it, self);
|
964
1009
|
while(IntSetItMove(&it)) {
|
965
1010
|
int* e = IntSetItGetRef(&it);
|
966
|
-
result ^= (size_t)(*e);
|
1011
|
+
result ^= ((size_t)(*e));
|
967
1012
|
result = AUTOC_RCYCLE(result);
|
968
1013
|
}
|
969
1014
|
return result;
|
@@ -976,13 +1021,13 @@ void IntSetPurge(IntSet* self) {
|
|
976
1021
|
}
|
977
1022
|
int IntSetContains(IntSet* self, int element) {
|
978
1023
|
assert(self);
|
979
|
-
return IntSetListContains(&self->buckets[(size_t)(element) % self->bucket_count], element);
|
1024
|
+
return IntSetListContains(&self->buckets[((size_t)(element)) % self->bucket_count], element);
|
980
1025
|
}
|
981
1026
|
int IntSetGet(IntSet* self, int element) {
|
982
1027
|
int result;
|
983
1028
|
assert(self);
|
984
1029
|
assert(IntSetContains(self, element));
|
985
|
-
result = IntSetListFind(&self->buckets[(size_t)(element) % self->bucket_count], element);
|
1030
|
+
result = IntSetListFind(&self->buckets[((size_t)(element)) % self->bucket_count], element);
|
986
1031
|
return result;
|
987
1032
|
}
|
988
1033
|
size_t IntSetSize(IntSet* self) {
|
@@ -992,7 +1037,7 @@ size_t IntSetSize(IntSet* self) {
|
|
992
1037
|
int IntSetPut(IntSet* self, int element) {
|
993
1038
|
IntSetList* bucket;
|
994
1039
|
assert(self);
|
995
|
-
bucket = &self->buckets[(size_t)(element) % self->bucket_count];
|
1040
|
+
bucket = &self->buckets[((size_t)(element)) % self->bucket_count];
|
996
1041
|
if(!IntSetListContains(bucket, element)) {
|
997
1042
|
IntSetListPush(bucket, element);
|
998
1043
|
++self->size;
|
@@ -1004,13 +1049,13 @@ int IntSetPut(IntSet* self, int element) {
|
|
1004
1049
|
int IntSetReplace(IntSet* self, int element) {
|
1005
1050
|
IntSetList* bucket;
|
1006
1051
|
assert(self);
|
1007
|
-
bucket = &self->buckets[(size_t)(element) % self->bucket_count];
|
1052
|
+
bucket = &self->buckets[((size_t)(element)) % self->bucket_count];
|
1008
1053
|
return IntSetListReplace(bucket, element);
|
1009
1054
|
}
|
1010
1055
|
int IntSetRemove(IntSet* self, int element) {
|
1011
1056
|
IntSetList* bucket;
|
1012
1057
|
assert(self);
|
1013
|
-
bucket = &self->buckets[(size_t)(element) % self->bucket_count];
|
1058
|
+
bucket = &self->buckets[((size_t)(element)) % self->bucket_count];
|
1014
1059
|
if(IntSetListRemove(bucket, element)) {
|
1015
1060
|
--self->size;
|
1016
1061
|
IntSetRehash(self);
|
@@ -1089,179 +1134,229 @@ int* IntSetItGetRef(IntSetIt* self) {
|
|
1089
1134
|
return IntSetListItGetRef(&self->it);
|
1090
1135
|
}
|
1091
1136
|
|
1092
|
-
|
1093
|
-
void ValueTypeQueueCtor(ValueTypeQueue* self) {
|
1137
|
+
static void ValueTypeVectorAllocate(ValueTypeVector* self, size_t element_count) {
|
1094
1138
|
assert(self);
|
1095
|
-
|
1139
|
+
assert(element_count > 0);
|
1140
|
+
self->element_count = element_count;
|
1141
|
+
self->values = (ValueType*)malloc(element_count*sizeof(ValueType));
|
1142
|
+
assert(self->values);
|
1143
|
+
}
|
1144
|
+
void ValueTypeVectorCtor(ValueTypeVector* self,size_t element_count) {
|
1145
|
+
size_t index;
|
1146
|
+
assert(self);
|
1147
|
+
ValueTypeVectorAllocate(self, element_count);
|
1148
|
+
for(index = 0; index < ValueTypeVectorSize(self); ++index) {
|
1149
|
+
ValueTypeCtor(self->values[index]);
|
1150
|
+
}
|
1151
|
+
}
|
1152
|
+
void ValueTypeVectorDtor(ValueTypeVector* self) {
|
1153
|
+
size_t index;
|
1154
|
+
assert(self);
|
1155
|
+
for(index = 0; index < ValueTypeVectorSize(self); ++index) {
|
1156
|
+
ValueTypeDtor(self->values[index]);
|
1157
|
+
}
|
1158
|
+
free(self->values);
|
1159
|
+
}
|
1160
|
+
void ValueTypeVectorCopy(ValueTypeVector* dst,ValueTypeVector* src) {
|
1161
|
+
size_t index, size;
|
1162
|
+
assert(src);
|
1163
|
+
assert(dst);
|
1164
|
+
ValueTypeVectorAllocate(dst, size = ValueTypeVectorSize(src));
|
1165
|
+
for(index = 0; index < size; ++index) {
|
1166
|
+
ValueTypeCopy(dst->values[index],src->values[index]);
|
1167
|
+
}
|
1168
|
+
}
|
1169
|
+
int ValueTypeVectorEqual(ValueTypeVector* lt,ValueTypeVector* rt) {
|
1170
|
+
size_t index, size;
|
1171
|
+
assert(lt);
|
1172
|
+
assert(rt);
|
1173
|
+
if(ValueTypeVectorSize(lt) == (size = ValueTypeVectorSize(rt))) {
|
1174
|
+
for(index = 0; index < size; ++index) {
|
1175
|
+
if(!ValueTypeEqual(lt->values[index],rt->values[index])) return 0;
|
1176
|
+
}
|
1177
|
+
return 1;
|
1178
|
+
} else
|
1179
|
+
return 0;
|
1180
|
+
}
|
1181
|
+
size_t ValueTypeVectorIdentify(ValueTypeVector* self) {
|
1182
|
+
size_t index, result = 0;
|
1183
|
+
assert(self);
|
1184
|
+
for(index = 0; index < self->element_count; ++index) {
|
1185
|
+
result ^= ValueTypeIdentify(self->values[index]);
|
1186
|
+
result = AUTOC_RCYCLE(result);
|
1187
|
+
}
|
1188
|
+
return result;
|
1189
|
+
}
|
1190
|
+
void ValueTypeVectorResize(ValueTypeVector* self, size_t new_element_count) {
|
1191
|
+
size_t index, element_count, from, to;
|
1192
|
+
assert(self);
|
1193
|
+
if((element_count = ValueTypeVectorSize(self)) != new_element_count) {
|
1194
|
+
ValueType* values = (ValueType*)malloc(new_element_count*sizeof(ValueType));
|
1195
|
+
assert(values);
|
1196
|
+
from = AUTOC_MIN(element_count, new_element_count);
|
1197
|
+
to = AUTOC_MAX(element_count, new_element_count);
|
1198
|
+
for(index = 0; index < from; ++index) {
|
1199
|
+
values[index] = self->values[index];
|
1200
|
+
}
|
1201
|
+
if(element_count > new_element_count) {
|
1202
|
+
for(index = from; index < to; ++index) {
|
1203
|
+
ValueTypeDtor(self->values[index]);
|
1204
|
+
}
|
1205
|
+
} else {
|
1206
|
+
for(index = from; index < to; ++index) {
|
1207
|
+
ValueTypeCtor(values[index]);
|
1208
|
+
}
|
1209
|
+
}
|
1210
|
+
free(self->values);
|
1211
|
+
self->values = values;
|
1212
|
+
self->element_count = new_element_count;
|
1213
|
+
}
|
1214
|
+
}
|
1215
|
+
|
1216
|
+
static int ValueTypeVectorComparator(void* lp_, void* rp_) {
|
1217
|
+
ValueType* lp = (ValueType*)lp_;
|
1218
|
+
ValueType* rp = (ValueType*)rp_;
|
1219
|
+
if(ValueTypeEqual(*lp,*rp)) {
|
1220
|
+
return 0;
|
1221
|
+
} else if(ValueTypeLess(*lp,*rp)) {
|
1222
|
+
return -1;
|
1223
|
+
} else {
|
1224
|
+
return +1;
|
1225
|
+
}
|
1226
|
+
}
|
1227
|
+
void ValueTypeVectorSort(ValueTypeVector* self) {
|
1228
|
+
typedef int (*F)(const void*, const void*);
|
1229
|
+
assert(self);
|
1230
|
+
qsort(self->values, ValueTypeVectorSize(self), sizeof(ValueType), (F)ValueTypeVectorComparator);
|
1231
|
+
}
|
1232
|
+
|
1233
|
+
IntSet* ListIntSetItGetRef(ListIntSetIt*);
|
1234
|
+
void ListIntSetCtor(ListIntSet* self) {
|
1235
|
+
assert(self);
|
1236
|
+
self->head_node = NULL;
|
1096
1237
|
self->node_count = 0;
|
1097
1238
|
}
|
1098
|
-
void
|
1099
|
-
|
1239
|
+
void ListIntSetDtor(ListIntSet* self) {
|
1240
|
+
ListIntSetNode* node;
|
1100
1241
|
assert(self);
|
1101
1242
|
node = self->head_node;
|
1102
1243
|
while(node) {
|
1103
|
-
|
1244
|
+
ListIntSetNode* this_node = node;
|
1104
1245
|
node = node->next_node;
|
1105
|
-
|
1246
|
+
_IntSetDtor(this_node->element);
|
1106
1247
|
free(this_node);
|
1107
1248
|
}
|
1108
1249
|
}
|
1109
|
-
void
|
1110
|
-
|
1250
|
+
void ListIntSetCopy(ListIntSet* dst,ListIntSet* src) {
|
1251
|
+
ListIntSetIt it;
|
1111
1252
|
assert(src);
|
1112
1253
|
assert(dst);
|
1113
|
-
|
1114
|
-
|
1115
|
-
while(
|
1116
|
-
|
1117
|
-
|
1118
|
-
|
1119
|
-
|
1120
|
-
|
1121
|
-
|
1122
|
-
|
1123
|
-
|
1124
|
-
|
1125
|
-
ValueTypeQueueItCtor(&rit, rt);
|
1126
|
-
while(ValueTypeQueueItMove(&lit) && ValueTypeQueueItMove(&rit)) {
|
1254
|
+
ListIntSetCtor(dst);
|
1255
|
+
ListIntSetItCtor(&it, src);
|
1256
|
+
while(ListIntSetItMove(&it)) {
|
1257
|
+
ListIntSetPush(dst, *ListIntSetItGetRef(&it));
|
1258
|
+
}
|
1259
|
+
}
|
1260
|
+
int ListIntSetEqual(ListIntSet* lt,ListIntSet* rt) {
|
1261
|
+
if(ListIntSetSize(lt) == ListIntSetSize(rt)) {
|
1262
|
+
ListIntSetIt lit, rit;
|
1263
|
+
ListIntSetItCtor(&lit, lt);
|
1264
|
+
ListIntSetItCtor(&rit, rt);
|
1265
|
+
while(ListIntSetItMove(&lit) && ListIntSetItMove(&rit)) {
|
1127
1266
|
int equal;
|
1128
|
-
|
1129
|
-
|
1130
|
-
|
1131
|
-
|
1267
|
+
IntSet* le;
|
1268
|
+
IntSet* re;
|
1269
|
+
le = ListIntSetItGetRef(&lit);
|
1270
|
+
re = ListIntSetItGetRef(&rit);
|
1271
|
+
equal = _IntSetEqual(*le,*re);
|
1132
1272
|
if(!equal) return 0;
|
1133
1273
|
}
|
1134
1274
|
return 1;
|
1135
1275
|
} else
|
1136
1276
|
return 0;
|
1137
1277
|
}
|
1138
|
-
size_t
|
1139
|
-
|
1278
|
+
size_t ListIntSetIdentify(ListIntSet* self) {
|
1279
|
+
ListIntSetNode* node;
|
1140
1280
|
size_t result = 0;
|
1141
1281
|
assert(self);
|
1142
1282
|
for(node = self->head_node; node != NULL; node = node->next_node) {
|
1143
|
-
result ^=
|
1283
|
+
result ^= _IntSetIdentify(node->element);
|
1144
1284
|
result = AUTOC_RCYCLE(result);
|
1145
1285
|
}
|
1146
1286
|
return result;
|
1147
1287
|
}
|
1148
|
-
void
|
1149
|
-
|
1150
|
-
|
1151
|
-
}
|
1152
|
-
ValueType ValueTypeQueuePeekHead(ValueTypeQueue* self) {
|
1153
|
-
ValueType result;
|
1154
|
-
assert(self);
|
1155
|
-
assert(!ValueTypeQueueEmpty(self));
|
1156
|
-
ValueTypeCopy(result, self->head_node->element);
|
1157
|
-
return result;
|
1288
|
+
void ListIntSetPurge(ListIntSet* self) {
|
1289
|
+
ListIntSetDtor(self);
|
1290
|
+
ListIntSetCtor(self);
|
1158
1291
|
}
|
1159
|
-
|
1160
|
-
|
1292
|
+
IntSet ListIntSetPeek(ListIntSet* self) {
|
1293
|
+
IntSet result;
|
1161
1294
|
assert(self);
|
1162
|
-
assert(!
|
1163
|
-
|
1295
|
+
assert(!ListIntSetEmpty(self));
|
1296
|
+
_IntSetCopy(result,self->head_node->element);
|
1164
1297
|
return result;
|
1165
1298
|
}
|
1166
|
-
|
1167
|
-
|
1168
|
-
|
1299
|
+
IntSet ListIntSetPop(ListIntSet* self) {
|
1300
|
+
ListIntSetNode* node;
|
1301
|
+
IntSet result;
|
1169
1302
|
assert(self);
|
1170
|
-
assert(!
|
1303
|
+
assert(!ListIntSetEmpty(self));
|
1171
1304
|
node = self->head_node;
|
1172
1305
|
result = node->element;
|
1173
1306
|
self->head_node = self->head_node->next_node;
|
1174
|
-
self->head_node->prev_node = NULL;
|
1175
1307
|
--self->node_count;
|
1176
1308
|
free(node);
|
1177
1309
|
return result;
|
1178
1310
|
}
|
1179
|
-
|
1180
|
-
|
1181
|
-
ValueType result;
|
1311
|
+
void ListIntSetPush(ListIntSet* self, IntSet element) {
|
1312
|
+
ListIntSetNode* node;
|
1182
1313
|
assert(self);
|
1183
|
-
|
1184
|
-
node
|
1185
|
-
|
1186
|
-
|
1187
|
-
self->
|
1188
|
-
|
1189
|
-
free(node);
|
1190
|
-
return result;
|
1314
|
+
node = (ListIntSetNode*)malloc(sizeof(ListIntSetNode));
|
1315
|
+
assert(node);
|
1316
|
+
_IntSetCopy(node->element,element);
|
1317
|
+
node->next_node = self->head_node;
|
1318
|
+
self->head_node = node;
|
1319
|
+
++self->node_count;
|
1191
1320
|
}
|
1192
|
-
|
1193
|
-
|
1321
|
+
int ListIntSetContains(ListIntSet* self, IntSet what) {
|
1322
|
+
ListIntSetNode* node;
|
1323
|
+
int found = 0;
|
1194
1324
|
assert(self);
|
1195
|
-
node =
|
1196
|
-
|
1197
|
-
|
1198
|
-
|
1199
|
-
|
1200
|
-
|
1201
|
-
|
1202
|
-
node->next_node = NULL;
|
1203
|
-
node->prev_node = self->tail_node;
|
1204
|
-
self->tail_node->next_node = node;
|
1205
|
-
self->tail_node = node;
|
1325
|
+
node = self->head_node;
|
1326
|
+
while(node) {
|
1327
|
+
if(_IntSetEqual(node->element,what)) {
|
1328
|
+
found = 1;
|
1329
|
+
break;
|
1330
|
+
}
|
1331
|
+
node = node->next_node;
|
1206
1332
|
}
|
1207
|
-
|
1333
|
+
return found;
|
1208
1334
|
}
|
1209
|
-
|
1210
|
-
|
1335
|
+
IntSet ListIntSetFind(ListIntSet* self, IntSet what) {
|
1336
|
+
ListIntSetNode* node;
|
1211
1337
|
assert(self);
|
1212
|
-
|
1213
|
-
assert(node);
|
1214
|
-
ValueTypeCopy(node->element, element);
|
1215
|
-
if(ValueTypeQueueEmpty(self)) {
|
1216
|
-
node->prev_node = node->next_node = NULL;
|
1217
|
-
self->tail_node = self->head_node = node;
|
1218
|
-
} else {
|
1219
|
-
node->prev_node = NULL;
|
1220
|
-
node->next_node = self->head_node;
|
1221
|
-
self->head_node->prev_node = node;
|
1222
|
-
self->head_node = node;
|
1223
|
-
}
|
1224
|
-
++self->node_count;
|
1225
|
-
}
|
1226
|
-
int ValueTypeQueueContains(ValueTypeQueue* self, ValueType what) {
|
1227
|
-
ValueTypeQueueNode* node;
|
1228
|
-
int found = 0;
|
1229
|
-
assert(self);
|
1230
|
-
node = self->head_node;
|
1231
|
-
while(node) {
|
1232
|
-
if(ValueTypeEqual(node->element, what)) {
|
1233
|
-
found = 1;
|
1234
|
-
break;
|
1235
|
-
}
|
1236
|
-
node = node->next_node;
|
1237
|
-
}
|
1238
|
-
return found;
|
1239
|
-
}
|
1240
|
-
ValueType ValueTypeQueueFind(ValueTypeQueue* self, ValueType what) {
|
1241
|
-
ValueTypeQueueNode* node;
|
1242
|
-
assert(self);
|
1243
|
-
assert(ValueTypeQueueContains(self, what));
|
1338
|
+
assert(ListIntSetContains(self, what));
|
1244
1339
|
node = self->head_node;
|
1245
1340
|
while(node) {
|
1246
|
-
if(
|
1247
|
-
|
1248
|
-
|
1341
|
+
if(_IntSetEqual(node->element,what)) {
|
1342
|
+
IntSet result;
|
1343
|
+
_IntSetCopy(result,node->element);
|
1249
1344
|
return result;
|
1250
1345
|
}
|
1251
1346
|
node = node->next_node;
|
1252
1347
|
}
|
1253
1348
|
abort();
|
1254
1349
|
}
|
1255
|
-
int
|
1256
|
-
|
1350
|
+
int ListIntSetReplaceEx(ListIntSet* self, IntSet with, int count) {
|
1351
|
+
ListIntSetNode* node;
|
1257
1352
|
int replaced = 0;
|
1258
1353
|
assert(self);
|
1259
1354
|
if(count == 0) return 0;
|
1260
1355
|
node = self->head_node;
|
1261
1356
|
while(node) {
|
1262
|
-
if(
|
1263
|
-
|
1264
|
-
|
1357
|
+
if(_IntSetEqual(node->element,with)) {
|
1358
|
+
_IntSetDtor(node->element);
|
1359
|
+
_IntSetCopy(node->element,with);
|
1265
1360
|
++replaced;
|
1266
1361
|
if(count > 0 && replaced >= count) break;
|
1267
1362
|
}
|
@@ -1269,363 +1364,350 @@ int ValueTypeQueueReplaceEx(ValueTypeQueue* self, ValueType with, int count) {
|
|
1269
1364
|
}
|
1270
1365
|
return replaced;
|
1271
1366
|
}
|
1272
|
-
int
|
1273
|
-
|
1367
|
+
int ListIntSetRemoveEx(ListIntSet* self, IntSet what, int count) {
|
1368
|
+
ListIntSetNode *node, *prev_node;
|
1274
1369
|
int removed = 0;
|
1275
1370
|
assert(self);
|
1276
1371
|
if(count == 0) return 0;
|
1277
1372
|
node = self->head_node;
|
1373
|
+
prev_node = NULL;
|
1278
1374
|
while(node) {
|
1279
|
-
if(
|
1280
|
-
|
1281
|
-
if(
|
1282
|
-
|
1283
|
-
this_node = self->head_node = node->next_node;
|
1284
|
-
if(self->head_node) self->head_node->prev_node = NULL;
|
1285
|
-
} else if(node == self->tail_node) {
|
1286
|
-
assert(!node->next_node);
|
1287
|
-
self->tail_node = node->prev_node;
|
1288
|
-
this_node = self->tail_node->next_node = NULL;
|
1375
|
+
if(_IntSetEqual(node->element,what)) {
|
1376
|
+
ListIntSetNode* this_node;
|
1377
|
+
if(prev_node) {
|
1378
|
+
this_node = prev_node->next_node = node->next_node;
|
1289
1379
|
} else {
|
1290
|
-
|
1291
|
-
assert(node->next_node);
|
1292
|
-
this_node = node->next_node;
|
1293
|
-
node->next_node->prev_node = node->prev_node;
|
1294
|
-
node->prev_node->next_node = node->next_node;
|
1380
|
+
this_node = self->head_node = node->next_node;
|
1295
1381
|
}
|
1296
1382
|
++removed;
|
1297
1383
|
--self->node_count;
|
1298
|
-
|
1384
|
+
_IntSetDtor(node->element);
|
1299
1385
|
free(node);
|
1300
1386
|
node = this_node;
|
1301
1387
|
if(count > 0 && removed >= count) break;
|
1302
1388
|
} else {
|
1389
|
+
prev_node = node;
|
1303
1390
|
node = node->next_node;
|
1304
1391
|
}
|
1305
1392
|
}
|
1306
1393
|
return removed;
|
1307
1394
|
}
|
1308
|
-
size_t
|
1395
|
+
size_t ListIntSetSize(ListIntSet* self) {
|
1309
1396
|
assert(self);
|
1310
1397
|
return self->node_count;
|
1311
1398
|
}
|
1312
|
-
void
|
1399
|
+
void ListIntSetItCtor(ListIntSetIt* self, ListIntSet* list) {
|
1313
1400
|
assert(self);
|
1314
|
-
assert(
|
1401
|
+
assert(list);
|
1315
1402
|
self->start = 1;
|
1316
|
-
self->
|
1317
|
-
self->forward = forward;
|
1403
|
+
self->list = list;
|
1318
1404
|
}
|
1319
|
-
int
|
1405
|
+
int ListIntSetItMove(ListIntSetIt* self) {
|
1320
1406
|
assert(self);
|
1321
1407
|
if(self->start) {
|
1322
|
-
self->this_node = self->
|
1408
|
+
self->this_node = self->list->head_node;
|
1323
1409
|
self->start = 0;
|
1324
1410
|
} else {
|
1325
|
-
self->this_node = self->
|
1411
|
+
self->this_node = self->this_node ? self->this_node->next_node : NULL;
|
1326
1412
|
}
|
1327
1413
|
return self->this_node != NULL;
|
1328
1414
|
}
|
1329
|
-
|
1330
|
-
|
1415
|
+
IntSet ListIntSetItGet(ListIntSetIt* self) {
|
1416
|
+
IntSet result;
|
1331
1417
|
assert(self);
|
1332
1418
|
assert(self->this_node);
|
1333
|
-
|
1419
|
+
_IntSetCopy(result,self->this_node->element);
|
1334
1420
|
return result;
|
1335
1421
|
}
|
1336
|
-
|
1422
|
+
IntSet* ListIntSetItGetRef(ListIntSetIt* self) {
|
1337
1423
|
assert(self);
|
1338
1424
|
assert(self->this_node);
|
1339
1425
|
return &self->this_node->element;
|
1340
1426
|
}
|
1341
1427
|
|
1342
|
-
|
1343
|
-
void ValueTypeListCtor(ValueTypeList* self) {
|
1428
|
+
static void PIntVectorAllocate(PIntVector* self, size_t element_count) {
|
1344
1429
|
assert(self);
|
1345
|
-
|
1346
|
-
self->
|
1430
|
+
assert(element_count > 0);
|
1431
|
+
self->element_count = element_count;
|
1432
|
+
self->values = (int**)malloc(element_count*sizeof(int*));
|
1433
|
+
assert(self->values);
|
1347
1434
|
}
|
1348
|
-
void
|
1349
|
-
|
1435
|
+
void PIntVectorCtor(PIntVector* self,size_t element_count) {
|
1436
|
+
size_t index;
|
1350
1437
|
assert(self);
|
1351
|
-
|
1352
|
-
|
1353
|
-
|
1354
|
-
node = node->next_node;
|
1355
|
-
ValueTypeDtor(this_node->element);
|
1356
|
-
free(this_node);
|
1438
|
+
PIntVectorAllocate(self, element_count);
|
1439
|
+
for(index = 0; index < PIntVectorSize(self); ++index) {
|
1440
|
+
((self->values[index]) = IntNew());
|
1357
1441
|
}
|
1358
1442
|
}
|
1359
|
-
void
|
1360
|
-
|
1443
|
+
void PIntVectorDtor(PIntVector* self) {
|
1444
|
+
size_t index;
|
1445
|
+
assert(self);
|
1446
|
+
for(index = 0; index < PIntVectorSize(self); ++index) {
|
1447
|
+
IntFree(self->values[index]);
|
1448
|
+
}
|
1449
|
+
free(self->values);
|
1450
|
+
}
|
1451
|
+
void PIntVectorCopy(PIntVector* dst,PIntVector* src) {
|
1452
|
+
size_t index, size;
|
1361
1453
|
assert(src);
|
1362
1454
|
assert(dst);
|
1363
|
-
|
1364
|
-
|
1365
|
-
|
1366
|
-
ValueTypeListPush(dst, *ValueTypeListItGetRef(&it));
|
1455
|
+
PIntVectorAllocate(dst, size = PIntVectorSize(src));
|
1456
|
+
for(index = 0; index < size; ++index) {
|
1457
|
+
((dst->values[index]) = IntRef(src->values[index]));
|
1367
1458
|
}
|
1368
1459
|
}
|
1369
|
-
int
|
1370
|
-
|
1371
|
-
|
1372
|
-
|
1373
|
-
|
1374
|
-
|
1375
|
-
|
1376
|
-
ValueType *le, *re;
|
1377
|
-
le = ValueTypeListItGetRef(&lit);
|
1378
|
-
re = ValueTypeListItGetRef(&rit);
|
1379
|
-
equal = ValueTypeEqual(*le, *re);
|
1380
|
-
if(!equal) return 0;
|
1460
|
+
int PIntVectorEqual(PIntVector* lt,PIntVector* rt) {
|
1461
|
+
size_t index, size;
|
1462
|
+
assert(lt);
|
1463
|
+
assert(rt);
|
1464
|
+
if(PIntVectorSize(lt) == (size = PIntVectorSize(rt))) {
|
1465
|
+
for(index = 0; index < size; ++index) {
|
1466
|
+
if(!((*lt->values[index]) == (*rt->values[index]))) return 0;
|
1381
1467
|
}
|
1382
1468
|
return 1;
|
1383
1469
|
} else
|
1384
1470
|
return 0;
|
1385
1471
|
}
|
1386
|
-
size_t
|
1387
|
-
|
1388
|
-
size_t result = 0;
|
1472
|
+
size_t PIntVectorIdentify(PIntVector* self) {
|
1473
|
+
size_t index, result = 0;
|
1389
1474
|
assert(self);
|
1390
|
-
for(
|
1391
|
-
result ^=
|
1475
|
+
for(index = 0; index < self->element_count; ++index) {
|
1476
|
+
result ^= ((size_t)(*self->values[index]));
|
1392
1477
|
result = AUTOC_RCYCLE(result);
|
1393
1478
|
}
|
1394
1479
|
return result;
|
1395
1480
|
}
|
1396
|
-
void
|
1397
|
-
|
1398
|
-
ValueTypeListCtor(self);
|
1399
|
-
}
|
1400
|
-
ValueType ValueTypeListPeek(ValueTypeList* self) {
|
1401
|
-
ValueType result;
|
1402
|
-
assert(self);
|
1403
|
-
assert(!ValueTypeListEmpty(self));
|
1404
|
-
ValueTypeCopy(result, self->head_node->element);
|
1405
|
-
return result;
|
1406
|
-
}
|
1407
|
-
ValueType ValueTypeListPop(ValueTypeList* self) {
|
1408
|
-
ValueTypeListNode* node;
|
1409
|
-
ValueType result;
|
1410
|
-
assert(self);
|
1411
|
-
assert(!ValueTypeListEmpty(self));
|
1412
|
-
node = self->head_node;
|
1413
|
-
result = node->element;
|
1414
|
-
self->head_node = self->head_node->next_node;
|
1415
|
-
--self->node_count;
|
1416
|
-
free(node);
|
1417
|
-
return result;
|
1418
|
-
}
|
1419
|
-
void ValueTypeListPush(ValueTypeList* self, ValueType element) {
|
1420
|
-
ValueTypeListNode* node;
|
1421
|
-
assert(self);
|
1422
|
-
node = (ValueTypeListNode*)malloc(sizeof(ValueTypeListNode));
|
1423
|
-
assert(node);
|
1424
|
-
ValueTypeCopy(node->element, element);
|
1425
|
-
node->next_node = self->head_node;
|
1426
|
-
self->head_node = node;
|
1427
|
-
++self->node_count;
|
1428
|
-
}
|
1429
|
-
int ValueTypeListContains(ValueTypeList* self, ValueType what) {
|
1430
|
-
ValueTypeListNode* node;
|
1431
|
-
int found = 0;
|
1432
|
-
assert(self);
|
1433
|
-
node = self->head_node;
|
1434
|
-
while(node) {
|
1435
|
-
if(ValueTypeEqual(node->element, what)) {
|
1436
|
-
found = 1;
|
1437
|
-
break;
|
1438
|
-
}
|
1439
|
-
node = node->next_node;
|
1440
|
-
}
|
1441
|
-
return found;
|
1442
|
-
}
|
1443
|
-
ValueType ValueTypeListFind(ValueTypeList* self, ValueType what) {
|
1444
|
-
ValueTypeListNode* node;
|
1445
|
-
assert(self);
|
1446
|
-
assert(ValueTypeListContains(self, what));
|
1447
|
-
node = self->head_node;
|
1448
|
-
while(node) {
|
1449
|
-
if(ValueTypeEqual(node->element, what)) {
|
1450
|
-
ValueType result;
|
1451
|
-
ValueTypeCopy(result, node->element);
|
1452
|
-
return result;
|
1453
|
-
}
|
1454
|
-
node = node->next_node;
|
1455
|
-
}
|
1456
|
-
abort();
|
1457
|
-
}
|
1458
|
-
int ValueTypeListReplaceEx(ValueTypeList* self, ValueType with, int count) {
|
1459
|
-
ValueTypeListNode* node;
|
1460
|
-
int replaced = 0;
|
1481
|
+
void PIntVectorResize(PIntVector* self, size_t new_element_count) {
|
1482
|
+
size_t index, element_count, from, to;
|
1461
1483
|
assert(self);
|
1462
|
-
if(
|
1463
|
-
|
1464
|
-
|
1465
|
-
|
1466
|
-
|
1467
|
-
|
1468
|
-
|
1469
|
-
if(count > 0 && replaced >= count) break;
|
1484
|
+
if((element_count = PIntVectorSize(self)) != new_element_count) {
|
1485
|
+
int** values = (int**)malloc(new_element_count*sizeof(int*));
|
1486
|
+
assert(values);
|
1487
|
+
from = AUTOC_MIN(element_count, new_element_count);
|
1488
|
+
to = AUTOC_MAX(element_count, new_element_count);
|
1489
|
+
for(index = 0; index < from; ++index) {
|
1490
|
+
values[index] = self->values[index];
|
1470
1491
|
}
|
1471
|
-
|
1472
|
-
|
1473
|
-
|
1474
|
-
}
|
1475
|
-
int ValueTypeListRemoveEx(ValueTypeList* self, ValueType what, int count) {
|
1476
|
-
ValueTypeListNode *node, *prev_node;
|
1477
|
-
int removed = 0;
|
1478
|
-
assert(self);
|
1479
|
-
if(count == 0) return 0;
|
1480
|
-
node = self->head_node;
|
1481
|
-
prev_node = NULL;
|
1482
|
-
while(node) {
|
1483
|
-
if(ValueTypeEqual(node->element, what)) {
|
1484
|
-
ValueTypeListNode* this_node;
|
1485
|
-
if(prev_node) {
|
1486
|
-
this_node = prev_node->next_node = node->next_node;
|
1487
|
-
} else {
|
1488
|
-
this_node = self->head_node = node->next_node;
|
1492
|
+
if(element_count > new_element_count) {
|
1493
|
+
for(index = from; index < to; ++index) {
|
1494
|
+
IntFree(self->values[index]);
|
1489
1495
|
}
|
1490
|
-
++removed;
|
1491
|
-
--self->node_count;
|
1492
|
-
ValueTypeDtor(node->element);
|
1493
|
-
free(node);
|
1494
|
-
node = this_node;
|
1495
|
-
if(count > 0 && removed >= count) break;
|
1496
1496
|
} else {
|
1497
|
-
|
1498
|
-
|
1497
|
+
for(index = from; index < to; ++index) {
|
1498
|
+
((values[index]) = IntNew());
|
1499
|
+
}
|
1499
1500
|
}
|
1501
|
+
free(self->values);
|
1502
|
+
self->values = values;
|
1503
|
+
self->element_count = new_element_count;
|
1500
1504
|
}
|
1501
|
-
return removed;
|
1502
|
-
}
|
1503
|
-
size_t ValueTypeListSize(ValueTypeList* self) {
|
1504
|
-
assert(self);
|
1505
|
-
return self->node_count;
|
1506
|
-
}
|
1507
|
-
void ValueTypeListItCtor(ValueTypeListIt* self, ValueTypeList* list) {
|
1508
|
-
assert(self);
|
1509
|
-
assert(list);
|
1510
|
-
self->start = 1;
|
1511
|
-
self->list = list;
|
1512
1505
|
}
|
1513
|
-
|
1514
|
-
|
1515
|
-
|
1516
|
-
|
1517
|
-
|
1506
|
+
|
1507
|
+
static int PIntVectorComparator(void* lp_, void* rp_) {
|
1508
|
+
int** lp = (int**)lp_;
|
1509
|
+
int** rp = (int**)rp_;
|
1510
|
+
if(((**lp) == (**rp))) {
|
1511
|
+
return 0;
|
1512
|
+
} else if(((**lp) < (**rp))) {
|
1513
|
+
return -1;
|
1518
1514
|
} else {
|
1519
|
-
|
1515
|
+
return +1;
|
1520
1516
|
}
|
1521
|
-
return self->this_node != NULL;
|
1522
|
-
}
|
1523
|
-
ValueType ValueTypeListItGet(ValueTypeListIt* self) {
|
1524
|
-
ValueType result;
|
1525
|
-
assert(self);
|
1526
|
-
assert(self->this_node);
|
1527
|
-
ValueTypeCopy(result, self->this_node->element);
|
1528
|
-
return result;
|
1529
1517
|
}
|
1530
|
-
|
1518
|
+
void PIntVectorSort(PIntVector* self) {
|
1519
|
+
typedef int (*F)(const void*, const void*);
|
1531
1520
|
assert(self);
|
1532
|
-
|
1533
|
-
return &self->this_node->element;
|
1521
|
+
qsort(self->values, PIntVectorSize(self), sizeof(int*), (F)PIntVectorComparator);
|
1534
1522
|
}
|
1535
1523
|
|
1536
|
-
|
1537
|
-
|
1538
|
-
|
1539
|
-
|
1540
|
-
|
1541
|
-
|
1542
|
-
|
1543
|
-
|
1544
|
-
|
1545
|
-
|
1546
|
-
|
1547
|
-
|
1548
|
-
|
1549
|
-
|
1550
|
-
|
1551
|
-
|
1552
|
-
|
1553
|
-
|
1554
|
-
|
1555
|
-
|
1556
|
-
|
1557
|
-
|
1524
|
+
#define AUTOC_VALID_VALUE 1
|
1525
|
+
#define AUTOC_VALID_KEY 2
|
1526
|
+
#define AUTOC_OWNED_VALUE 4
|
1527
|
+
#define AUTOC_OWNED_KEY 8
|
1528
|
+
static ValueTypeMapEntry ValueTypeMapEntryKeyOnlyRef(ValueType* key) {
|
1529
|
+
ValueTypeMapEntry entry;
|
1530
|
+
entry.key = *key;
|
1531
|
+
entry.flags = AUTOC_VALID_KEY;
|
1532
|
+
return entry;
|
1533
|
+
}
|
1534
|
+
static ValueTypeMapEntry ValueTypeMapEntryKeyValueRef(ValueType* key, ValueType* value) {
|
1535
|
+
ValueTypeMapEntry entry;
|
1536
|
+
entry.key = *key;
|
1537
|
+
entry.value = *value;
|
1538
|
+
entry.flags = (AUTOC_VALID_KEY | AUTOC_VALID_VALUE);
|
1539
|
+
return entry;
|
1540
|
+
}
|
1541
|
+
#define ValueTypeMapEntryIdentify(obj) ValueTypeMapEntryIdentifyRef(&obj)
|
1542
|
+
static size_t ValueTypeMapEntryIdentifyRef(ValueTypeMapEntry* entry) {
|
1543
|
+
return ValueTypeIdentify(entry->key);
|
1544
|
+
}
|
1545
|
+
#define ValueTypeMapEntryEqual(lt, rt) ValueTypeMapEntryEqualRef(<, &rt)
|
1546
|
+
static int ValueTypeMapEntryEqualRef(ValueTypeMapEntry* lt, ValueTypeMapEntry* rt) {
|
1547
|
+
return ValueTypeEqual(lt->key,rt->key);
|
1548
|
+
}
|
1549
|
+
#define ValueTypeMapEntryCopy(dst, src) ValueTypeMapEntryCopyRef(&dst, &src)
|
1550
|
+
static void ValueTypeMapEntryCopyRef(ValueTypeMapEntry* dst, ValueTypeMapEntry* src) {
|
1551
|
+
assert(src->flags & AUTOC_VALID_KEY);
|
1552
|
+
dst->flags = (AUTOC_VALID_KEY | AUTOC_OWNED_KEY);
|
1553
|
+
ValueTypeCopy(dst->key,src->key);
|
1554
|
+
if(src->flags & AUTOC_VALID_VALUE) {
|
1555
|
+
dst->flags |= (AUTOC_VALID_VALUE | AUTOC_OWNED_VALUE);
|
1556
|
+
ValueTypeCopy(dst->value,src->value);
|
1557
|
+
}
|
1558
|
+
}
|
1559
|
+
#define ValueTypeMapEntryDtor(obj) ValueTypeMapEntryDtorRef(&obj)
|
1560
|
+
static void ValueTypeMapEntryDtorRef(ValueTypeMapEntry* entry) {
|
1561
|
+
assert(entry->flags & AUTOC_VALID_KEY);
|
1562
|
+
if(entry->flags & AUTOC_OWNED_KEY) ValueTypeDtor(entry->key);
|
1563
|
+
if(entry->flags & AUTOC_VALID_VALUE && entry->flags & AUTOC_OWNED_VALUE) ValueTypeDtor(entry->value);
|
1564
|
+
}
|
1565
|
+
static ValueTypeMapEntry* ValueTypeMapItGetEntryRef(ValueTypeMapIt*);
|
1566
|
+
static int ValueTypeMapContainsAllOf(ValueTypeMap* self, ValueTypeMap* other) {
|
1567
|
+
ValueTypeMapIt it;
|
1568
|
+
ValueTypeMapItCtor(&it, self);
|
1569
|
+
while(ValueTypeMapItMove(&it)) {
|
1570
|
+
int found = 0;
|
1571
|
+
ValueTypeMapEntry* e = ValueTypeMapItGetEntryRef(&it);
|
1572
|
+
if(ValueTypeMapContainsKey(other, e->key)) {
|
1573
|
+
ValueType other_value = ValueTypeMapGet(other, e->key);
|
1574
|
+
found = ValueTypeEqual(e->value,other_value);
|
1575
|
+
ValueTypeDtor(other_value);
|
1576
|
+
}
|
1577
|
+
if(!found) return 0;
|
1578
|
+
}
|
1579
|
+
return 1;
|
1580
|
+
}
|
1558
1581
|
|
1559
|
-
|
1560
|
-
|
1582
|
+
#define _ValueTypeMapSetCtor(self) ValueTypeMapSetCtor(&self)
|
1583
|
+
#define _ValueTypeMapSetDtor(self) ValueTypeMapSetDtor(&self)
|
1584
|
+
#define _ValueTypeMapSetIdentify(self) ValueTypeMapSetIdentify(&self)
|
1585
|
+
#define _ValueTypeMapSetCopy(dst,src) ValueTypeMapSetCopy(&dst,&src)
|
1586
|
+
#define _ValueTypeMapSetEqual(lt,rt) ValueTypeMapSetEqual(<,&rt)
|
1587
|
+
#define _ValueTypeMapSetLess(lt,rt) ValueTypeMapSetLess(<,&rt)
|
1588
|
+
|
1589
|
+
AUTOC_STATIC void ValueTypeMapSetCtor(ValueTypeMapSet*);
|
1590
|
+
AUTOC_STATIC void ValueTypeMapSetDtor(ValueTypeMapSet*);
|
1591
|
+
AUTOC_STATIC void ValueTypeMapSetCopy(ValueTypeMapSet*,ValueTypeMapSet*);
|
1592
|
+
AUTOC_STATIC int ValueTypeMapSetEqual(ValueTypeMapSet*,ValueTypeMapSet*);
|
1593
|
+
AUTOC_STATIC size_t ValueTypeMapSetIdentify(ValueTypeMapSet*);
|
1594
|
+
AUTOC_STATIC void ValueTypeMapSetPurge(ValueTypeMapSet*);
|
1595
|
+
AUTOC_STATIC int ValueTypeMapSetContains(ValueTypeMapSet*, ValueTypeMapEntry);
|
1596
|
+
AUTOC_STATIC ValueTypeMapEntry ValueTypeMapSetGet(ValueTypeMapSet*, ValueTypeMapEntry);
|
1597
|
+
AUTOC_STATIC size_t ValueTypeMapSetSize(ValueTypeMapSet*);
|
1598
|
+
#define ValueTypeMapSetEmpty(self) (ValueTypeMapSetSize(self) == 0)
|
1599
|
+
AUTOC_STATIC int ValueTypeMapSetPut(ValueTypeMapSet*, ValueTypeMapEntry);
|
1600
|
+
AUTOC_STATIC int ValueTypeMapSetReplace(ValueTypeMapSet*, ValueTypeMapEntry);
|
1601
|
+
AUTOC_STATIC int ValueTypeMapSetRemove(ValueTypeMapSet*, ValueTypeMapEntry);
|
1602
|
+
AUTOC_STATIC void ValueTypeMapSetExclude(ValueTypeMapSet*, ValueTypeMapSet*);
|
1603
|
+
AUTOC_STATIC void ValueTypeMapSetRetain(ValueTypeMapSet*, ValueTypeMapSet*);
|
1604
|
+
AUTOC_STATIC void ValueTypeMapSetInclude(ValueTypeMapSet*, ValueTypeMapSet*);
|
1605
|
+
AUTOC_STATIC void ValueTypeMapSetInvert(ValueTypeMapSet*, ValueTypeMapSet*);
|
1606
|
+
AUTOC_STATIC void ValueTypeMapSetItCtor(ValueTypeMapSetIt*, ValueTypeMapSet*);
|
1607
|
+
AUTOC_STATIC int ValueTypeMapSetItMove(ValueTypeMapSetIt*);
|
1608
|
+
AUTOC_STATIC ValueTypeMapEntry ValueTypeMapSetItGet(ValueTypeMapSetIt*);
|
1609
|
+
|
1610
|
+
#define _ValueTypeMapSetListCtor(self) ValueTypeMapSetListCtor(&self)
|
1611
|
+
#define _ValueTypeMapSetListDtor(self) ValueTypeMapSetListDtor(&self)
|
1612
|
+
#define _ValueTypeMapSetListIdentify(self) ValueTypeMapSetListIdentify(&self)
|
1613
|
+
#define _ValueTypeMapSetListCopy(dst,src) ValueTypeMapSetListCopy(&dst,&src)
|
1614
|
+
#define _ValueTypeMapSetListEqual(lt,rt) ValueTypeMapSetListEqual(<,&rt)
|
1615
|
+
#define _ValueTypeMapSetListLess(lt,rt) ValueTypeMapSetListLess(<,&rt)
|
1616
|
+
|
1617
|
+
AUTOC_STATIC void ValueTypeMapSetListCtor(ValueTypeMapSetList*);
|
1618
|
+
AUTOC_STATIC void ValueTypeMapSetListDtor(ValueTypeMapSetList*);
|
1619
|
+
AUTOC_STATIC void ValueTypeMapSetListCopy(ValueTypeMapSetList*,ValueTypeMapSetList*);
|
1620
|
+
AUTOC_STATIC int ValueTypeMapSetListEqual(ValueTypeMapSetList*,ValueTypeMapSetList*);
|
1621
|
+
AUTOC_STATIC size_t ValueTypeMapSetListIdentify(ValueTypeMapSetList*);
|
1622
|
+
AUTOC_STATIC void ValueTypeMapSetListPurge(ValueTypeMapSetList*);
|
1623
|
+
AUTOC_STATIC ValueTypeMapEntry ValueTypeMapSetListPeek(ValueTypeMapSetList*);
|
1624
|
+
AUTOC_STATIC ValueTypeMapEntry ValueTypeMapSetListPop(ValueTypeMapSetList*);
|
1625
|
+
AUTOC_STATIC void ValueTypeMapSetListPush(ValueTypeMapSetList*, ValueTypeMapEntry);
|
1626
|
+
AUTOC_STATIC int ValueTypeMapSetListContains(ValueTypeMapSetList*, ValueTypeMapEntry);
|
1627
|
+
AUTOC_STATIC ValueTypeMapEntry ValueTypeMapSetListFind(ValueTypeMapSetList*, ValueTypeMapEntry);
|
1628
|
+
#define ValueTypeMapSetListReplace(self, with) ValueTypeMapSetListReplaceEx(self, with, 1)
|
1629
|
+
#define ValueTypeMapSetListReplaceAll(self, with) ValueTypeMapSetListReplaceEx(self, with, -1)
|
1630
|
+
AUTOC_STATIC int ValueTypeMapSetListReplaceEx(ValueTypeMapSetList*, ValueTypeMapEntry, int);
|
1631
|
+
#define ValueTypeMapSetListRemove(self, what) ValueTypeMapSetListRemoveEx(self, what, 1)
|
1632
|
+
#define ValueTypeMapSetListRemoveAll(self, what) ValueTypeMapSetListRemoveEx(self, what, -1)
|
1633
|
+
AUTOC_STATIC int ValueTypeMapSetListRemoveEx(ValueTypeMapSetList*, ValueTypeMapEntry, int);
|
1634
|
+
AUTOC_STATIC size_t ValueTypeMapSetListSize(ValueTypeMapSetList*);
|
1635
|
+
#define ValueTypeMapSetListEmpty(self) (ValueTypeMapSetListSize(self) == 0)
|
1636
|
+
AUTOC_STATIC void ValueTypeMapSetListItCtor(ValueTypeMapSetListIt*, ValueTypeMapSetList*);
|
1637
|
+
AUTOC_STATIC int ValueTypeMapSetListItMove(ValueTypeMapSetListIt*);
|
1638
|
+
AUTOC_STATIC ValueTypeMapEntry ValueTypeMapSetListItGet(ValueTypeMapSetListIt*);
|
1639
|
+
|
1640
|
+
AUTOC_STATIC ValueTypeMapEntry* ValueTypeMapSetListItGetRef(ValueTypeMapSetListIt*);
|
1641
|
+
AUTOC_STATIC void ValueTypeMapSetListCtor(ValueTypeMapSetList* self) {
|
1561
1642
|
assert(self);
|
1562
1643
|
self->head_node = NULL;
|
1563
1644
|
self->node_count = 0;
|
1564
1645
|
}
|
1565
|
-
AUTOC_STATIC void
|
1566
|
-
|
1646
|
+
AUTOC_STATIC void ValueTypeMapSetListDtor(ValueTypeMapSetList* self) {
|
1647
|
+
ValueTypeMapSetListNode* node;
|
1567
1648
|
assert(self);
|
1568
1649
|
node = self->head_node;
|
1569
1650
|
while(node) {
|
1570
|
-
|
1651
|
+
ValueTypeMapSetListNode* this_node = node;
|
1571
1652
|
node = node->next_node;
|
1572
|
-
|
1653
|
+
ValueTypeMapEntryDtor(this_node->element);
|
1573
1654
|
free(this_node);
|
1574
1655
|
}
|
1575
1656
|
}
|
1576
|
-
AUTOC_STATIC void
|
1577
|
-
|
1657
|
+
AUTOC_STATIC void ValueTypeMapSetListCopy(ValueTypeMapSetList* dst,ValueTypeMapSetList* src) {
|
1658
|
+
ValueTypeMapSetListIt it;
|
1578
1659
|
assert(src);
|
1579
1660
|
assert(dst);
|
1580
|
-
|
1581
|
-
|
1582
|
-
while(
|
1583
|
-
|
1661
|
+
ValueTypeMapSetListCtor(dst);
|
1662
|
+
ValueTypeMapSetListItCtor(&it, src);
|
1663
|
+
while(ValueTypeMapSetListItMove(&it)) {
|
1664
|
+
ValueTypeMapSetListPush(dst, *ValueTypeMapSetListItGetRef(&it));
|
1584
1665
|
}
|
1585
1666
|
}
|
1586
|
-
AUTOC_STATIC int
|
1587
|
-
if(
|
1588
|
-
|
1589
|
-
|
1590
|
-
|
1591
|
-
while(
|
1667
|
+
AUTOC_STATIC int ValueTypeMapSetListEqual(ValueTypeMapSetList* lt,ValueTypeMapSetList* rt) {
|
1668
|
+
if(ValueTypeMapSetListSize(lt) == ValueTypeMapSetListSize(rt)) {
|
1669
|
+
ValueTypeMapSetListIt lit, rit;
|
1670
|
+
ValueTypeMapSetListItCtor(&lit, lt);
|
1671
|
+
ValueTypeMapSetListItCtor(&rit, rt);
|
1672
|
+
while(ValueTypeMapSetListItMove(&lit) && ValueTypeMapSetListItMove(&rit)) {
|
1592
1673
|
int equal;
|
1593
|
-
|
1594
|
-
|
1595
|
-
|
1596
|
-
|
1674
|
+
ValueTypeMapEntry* le;
|
1675
|
+
ValueTypeMapEntry* re;
|
1676
|
+
le = ValueTypeMapSetListItGetRef(&lit);
|
1677
|
+
re = ValueTypeMapSetListItGetRef(&rit);
|
1678
|
+
equal = ValueTypeMapEntryEqual(*le,*re);
|
1597
1679
|
if(!equal) return 0;
|
1598
1680
|
}
|
1599
1681
|
return 1;
|
1600
1682
|
} else
|
1601
1683
|
return 0;
|
1602
1684
|
}
|
1603
|
-
AUTOC_STATIC size_t
|
1604
|
-
|
1685
|
+
AUTOC_STATIC size_t ValueTypeMapSetListIdentify(ValueTypeMapSetList* self) {
|
1686
|
+
ValueTypeMapSetListNode* node;
|
1605
1687
|
size_t result = 0;
|
1606
1688
|
assert(self);
|
1607
1689
|
for(node = self->head_node; node != NULL; node = node->next_node) {
|
1608
|
-
result ^=
|
1690
|
+
result ^= ValueTypeMapEntryIdentify(node->element);
|
1609
1691
|
result = AUTOC_RCYCLE(result);
|
1610
1692
|
}
|
1611
1693
|
return result;
|
1612
1694
|
}
|
1613
|
-
AUTOC_STATIC void
|
1614
|
-
|
1615
|
-
|
1695
|
+
AUTOC_STATIC void ValueTypeMapSetListPurge(ValueTypeMapSetList* self) {
|
1696
|
+
ValueTypeMapSetListDtor(self);
|
1697
|
+
ValueTypeMapSetListCtor(self);
|
1616
1698
|
}
|
1617
|
-
AUTOC_STATIC
|
1618
|
-
|
1699
|
+
AUTOC_STATIC ValueTypeMapEntry ValueTypeMapSetListPeek(ValueTypeMapSetList* self) {
|
1700
|
+
ValueTypeMapEntry result;
|
1619
1701
|
assert(self);
|
1620
|
-
assert(!
|
1621
|
-
|
1702
|
+
assert(!ValueTypeMapSetListEmpty(self));
|
1703
|
+
ValueTypeMapEntryCopy(result,self->head_node->element);
|
1622
1704
|
return result;
|
1623
1705
|
}
|
1624
|
-
AUTOC_STATIC
|
1625
|
-
|
1626
|
-
|
1706
|
+
AUTOC_STATIC ValueTypeMapEntry ValueTypeMapSetListPop(ValueTypeMapSetList* self) {
|
1707
|
+
ValueTypeMapSetListNode* node;
|
1708
|
+
ValueTypeMapEntry result;
|
1627
1709
|
assert(self);
|
1628
|
-
assert(!
|
1710
|
+
assert(!ValueTypeMapSetListEmpty(self));
|
1629
1711
|
node = self->head_node;
|
1630
1712
|
result = node->element;
|
1631
1713
|
self->head_node = self->head_node->next_node;
|
@@ -1633,23 +1715,23 @@ AUTOC_STATIC ValueType ValueTypeSetListPop(ValueTypeSetList* self) {
|
|
1633
1715
|
free(node);
|
1634
1716
|
return result;
|
1635
1717
|
}
|
1636
|
-
AUTOC_STATIC void
|
1637
|
-
|
1718
|
+
AUTOC_STATIC void ValueTypeMapSetListPush(ValueTypeMapSetList* self, ValueTypeMapEntry element) {
|
1719
|
+
ValueTypeMapSetListNode* node;
|
1638
1720
|
assert(self);
|
1639
|
-
node = (
|
1721
|
+
node = (ValueTypeMapSetListNode*)malloc(sizeof(ValueTypeMapSetListNode));
|
1640
1722
|
assert(node);
|
1641
|
-
|
1723
|
+
ValueTypeMapEntryCopy(node->element,element);
|
1642
1724
|
node->next_node = self->head_node;
|
1643
1725
|
self->head_node = node;
|
1644
1726
|
++self->node_count;
|
1645
1727
|
}
|
1646
|
-
AUTOC_STATIC int
|
1647
|
-
|
1728
|
+
AUTOC_STATIC int ValueTypeMapSetListContains(ValueTypeMapSetList* self, ValueTypeMapEntry what) {
|
1729
|
+
ValueTypeMapSetListNode* node;
|
1648
1730
|
int found = 0;
|
1649
1731
|
assert(self);
|
1650
1732
|
node = self->head_node;
|
1651
1733
|
while(node) {
|
1652
|
-
if(
|
1734
|
+
if(ValueTypeMapEntryEqual(node->element,what)) {
|
1653
1735
|
found = 1;
|
1654
1736
|
break;
|
1655
1737
|
}
|
@@ -1657,31 +1739,31 @@ AUTOC_STATIC int ValueTypeSetListContains(ValueTypeSetList* self, ValueType what
|
|
1657
1739
|
}
|
1658
1740
|
return found;
|
1659
1741
|
}
|
1660
|
-
AUTOC_STATIC
|
1661
|
-
|
1742
|
+
AUTOC_STATIC ValueTypeMapEntry ValueTypeMapSetListFind(ValueTypeMapSetList* self, ValueTypeMapEntry what) {
|
1743
|
+
ValueTypeMapSetListNode* node;
|
1662
1744
|
assert(self);
|
1663
|
-
assert(
|
1745
|
+
assert(ValueTypeMapSetListContains(self, what));
|
1664
1746
|
node = self->head_node;
|
1665
1747
|
while(node) {
|
1666
|
-
if(
|
1667
|
-
|
1668
|
-
|
1748
|
+
if(ValueTypeMapEntryEqual(node->element,what)) {
|
1749
|
+
ValueTypeMapEntry result;
|
1750
|
+
ValueTypeMapEntryCopy(result,node->element);
|
1669
1751
|
return result;
|
1670
1752
|
}
|
1671
1753
|
node = node->next_node;
|
1672
1754
|
}
|
1673
1755
|
abort();
|
1674
1756
|
}
|
1675
|
-
AUTOC_STATIC int
|
1676
|
-
|
1757
|
+
AUTOC_STATIC int ValueTypeMapSetListReplaceEx(ValueTypeMapSetList* self, ValueTypeMapEntry with, int count) {
|
1758
|
+
ValueTypeMapSetListNode* node;
|
1677
1759
|
int replaced = 0;
|
1678
1760
|
assert(self);
|
1679
1761
|
if(count == 0) return 0;
|
1680
1762
|
node = self->head_node;
|
1681
1763
|
while(node) {
|
1682
|
-
if(
|
1683
|
-
|
1684
|
-
|
1764
|
+
if(ValueTypeMapEntryEqual(node->element,with)) {
|
1765
|
+
ValueTypeMapEntryDtor(node->element);
|
1766
|
+
ValueTypeMapEntryCopy(node->element,with);
|
1685
1767
|
++replaced;
|
1686
1768
|
if(count > 0 && replaced >= count) break;
|
1687
1769
|
}
|
@@ -1689,16 +1771,16 @@ AUTOC_STATIC int ValueTypeSetListReplaceEx(ValueTypeSetList* self, ValueType wit
|
|
1689
1771
|
}
|
1690
1772
|
return replaced;
|
1691
1773
|
}
|
1692
|
-
AUTOC_STATIC int
|
1693
|
-
|
1774
|
+
AUTOC_STATIC int ValueTypeMapSetListRemoveEx(ValueTypeMapSetList* self, ValueTypeMapEntry what, int count) {
|
1775
|
+
ValueTypeMapSetListNode *node, *prev_node;
|
1694
1776
|
int removed = 0;
|
1695
1777
|
assert(self);
|
1696
1778
|
if(count == 0) return 0;
|
1697
1779
|
node = self->head_node;
|
1698
1780
|
prev_node = NULL;
|
1699
1781
|
while(node) {
|
1700
|
-
if(
|
1701
|
-
|
1782
|
+
if(ValueTypeMapEntryEqual(node->element,what)) {
|
1783
|
+
ValueTypeMapSetListNode* this_node;
|
1702
1784
|
if(prev_node) {
|
1703
1785
|
this_node = prev_node->next_node = node->next_node;
|
1704
1786
|
} else {
|
@@ -1706,7 +1788,7 @@ AUTOC_STATIC int ValueTypeSetListRemoveEx(ValueTypeSetList* self, ValueType what
|
|
1706
1788
|
}
|
1707
1789
|
++removed;
|
1708
1790
|
--self->node_count;
|
1709
|
-
|
1791
|
+
ValueTypeMapEntryDtor(node->element);
|
1710
1792
|
free(node);
|
1711
1793
|
node = this_node;
|
1712
1794
|
if(count > 0 && removed >= count) break;
|
@@ -1717,17 +1799,17 @@ AUTOC_STATIC int ValueTypeSetListRemoveEx(ValueTypeSetList* self, ValueType what
|
|
1717
1799
|
}
|
1718
1800
|
return removed;
|
1719
1801
|
}
|
1720
|
-
AUTOC_STATIC size_t
|
1802
|
+
AUTOC_STATIC size_t ValueTypeMapSetListSize(ValueTypeMapSetList* self) {
|
1721
1803
|
assert(self);
|
1722
1804
|
return self->node_count;
|
1723
1805
|
}
|
1724
|
-
AUTOC_STATIC void
|
1806
|
+
AUTOC_STATIC void ValueTypeMapSetListItCtor(ValueTypeMapSetListIt* self, ValueTypeMapSetList* list) {
|
1725
1807
|
assert(self);
|
1726
1808
|
assert(list);
|
1727
1809
|
self->start = 1;
|
1728
1810
|
self->list = list;
|
1729
1811
|
}
|
1730
|
-
AUTOC_STATIC int
|
1812
|
+
AUTOC_STATIC int ValueTypeMapSetListItMove(ValueTypeMapSetListIt* self) {
|
1731
1813
|
assert(self);
|
1732
1814
|
if(self->start) {
|
1733
1815
|
self->this_node = self->list->head_node;
|
@@ -1737,22 +1819,22 @@ AUTOC_STATIC int ValueTypeSetListItMove(ValueTypeSetListIt* self) {
|
|
1737
1819
|
}
|
1738
1820
|
return self->this_node != NULL;
|
1739
1821
|
}
|
1740
|
-
AUTOC_STATIC
|
1741
|
-
|
1822
|
+
AUTOC_STATIC ValueTypeMapEntry ValueTypeMapSetListItGet(ValueTypeMapSetListIt* self) {
|
1823
|
+
ValueTypeMapEntry result;
|
1742
1824
|
assert(self);
|
1743
1825
|
assert(self->this_node);
|
1744
|
-
|
1826
|
+
ValueTypeMapEntryCopy(result,self->this_node->element);
|
1745
1827
|
return result;
|
1746
1828
|
}
|
1747
|
-
AUTOC_STATIC
|
1829
|
+
AUTOC_STATIC ValueTypeMapEntry* ValueTypeMapSetListItGetRef(ValueTypeMapSetListIt* self) {
|
1748
1830
|
assert(self);
|
1749
1831
|
assert(self->this_node);
|
1750
1832
|
return &self->this_node->element;
|
1751
1833
|
}
|
1752
1834
|
|
1753
|
-
|
1754
|
-
static void
|
1755
|
-
|
1835
|
+
AUTOC_STATIC ValueTypeMapEntry* ValueTypeMapSetItGetRef(ValueTypeMapSetIt*);
|
1836
|
+
static void ValueTypeMapSetRehash(ValueTypeMapSet* self) {
|
1837
|
+
ValueTypeMapSetList* buckets;
|
1756
1838
|
size_t index, bucket_count, size, fill;
|
1757
1839
|
assert(self);
|
1758
1840
|
assert(self->min_fill > 0);
|
@@ -1776,358 +1858,428 @@ static void ValueTypeSetRehash(ValueTypeSet* self) {
|
|
1776
1858
|
bucket_count = self->min_bucket_count;
|
1777
1859
|
size = 0;
|
1778
1860
|
}
|
1779
|
-
buckets = (
|
1861
|
+
buckets = (ValueTypeMapSetList*)malloc(bucket_count*sizeof(ValueTypeMapSetList));
|
1780
1862
|
assert(buckets);
|
1781
1863
|
for(index = 0; index < bucket_count; ++index) {
|
1782
|
-
|
1864
|
+
ValueTypeMapSetListCtor(&buckets[index]);
|
1783
1865
|
}
|
1784
1866
|
if(self->buckets) {
|
1785
|
-
|
1786
|
-
|
1787
|
-
while(
|
1788
|
-
|
1789
|
-
|
1790
|
-
bucket = &buckets[
|
1791
|
-
|
1792
|
-
|
1867
|
+
ValueTypeMapSetIt it;
|
1868
|
+
ValueTypeMapSetItCtor(&it, self);
|
1869
|
+
while(ValueTypeMapSetItMove(&it)) {
|
1870
|
+
ValueTypeMapSetList* bucket;
|
1871
|
+
ValueTypeMapEntry element = ValueTypeMapSetItGet(&it);
|
1872
|
+
bucket = &buckets[ValueTypeMapEntryIdentify(element) % bucket_count];
|
1873
|
+
ValueTypeMapSetListPush(bucket, element);
|
1874
|
+
ValueTypeMapEntryDtor(element);
|
1793
1875
|
}
|
1794
|
-
|
1876
|
+
ValueTypeMapSetDtor(self);
|
1795
1877
|
}
|
1796
1878
|
self->buckets = buckets;
|
1797
1879
|
self->bucket_count = bucket_count;
|
1798
1880
|
self->size = size;
|
1799
1881
|
}
|
1800
|
-
|
1801
|
-
|
1802
|
-
self
|
1803
|
-
|
1804
|
-
|
1805
|
-
|
1806
|
-
|
1807
|
-
|
1808
|
-
|
1809
|
-
ValueTypeSetRehash(self);
|
1882
|
+
static int ValueTypeMapSetContainsAllOf(ValueTypeMapSet* self, ValueTypeMapSet* other) {
|
1883
|
+
ValueTypeMapSetIt it;
|
1884
|
+
ValueTypeMapSetItCtor(&it, self);
|
1885
|
+
while(ValueTypeMapSetItMove(&it)) {
|
1886
|
+
int found = 0;
|
1887
|
+
if(ValueTypeMapSetContains(other, *ValueTypeMapSetItGetRef(&it))) found = 1;
|
1888
|
+
if(!found) return 0;
|
1889
|
+
}
|
1890
|
+
return 1;
|
1810
1891
|
}
|
1811
|
-
void
|
1892
|
+
AUTOC_STATIC void ValueTypeMapSetCtor(ValueTypeMapSet* self) {
|
1893
|
+
assert(self);
|
1894
|
+
self->min_bucket_count = 16;
|
1895
|
+
self->min_fill = 20;
|
1896
|
+
self->max_fill = 80;
|
1897
|
+
self->min_size = (size_t)((float)self->min_fill/100*self->min_bucket_count);
|
1898
|
+
self->max_size = (size_t)((float)self->max_fill/100*self->min_bucket_count);
|
1899
|
+
self->capacity_multiplier = 200;
|
1900
|
+
self->buckets = NULL;
|
1901
|
+
ValueTypeMapSetRehash(self);
|
1902
|
+
}
|
1903
|
+
AUTOC_STATIC void ValueTypeMapSetDtor(ValueTypeMapSet* self) {
|
1812
1904
|
size_t i;
|
1813
1905
|
assert(self);
|
1814
1906
|
for(i = 0; i < self->bucket_count; ++i) {
|
1815
|
-
|
1907
|
+
ValueTypeMapSetListDtor(&self->buckets[i]);
|
1816
1908
|
}
|
1817
1909
|
free(self->buckets);
|
1818
1910
|
}
|
1819
|
-
void
|
1820
|
-
|
1911
|
+
AUTOC_STATIC void ValueTypeMapSetCopy(ValueTypeMapSet* dst,ValueTypeMapSet* src) {
|
1912
|
+
ValueTypeMapSetIt it;
|
1821
1913
|
assert(src);
|
1822
1914
|
assert(dst);
|
1823
|
-
|
1824
|
-
|
1825
|
-
while(
|
1826
|
-
}
|
1827
|
-
static int ValueTypeSetContainsAllOf(ValueTypeSet* self, ValueTypeSet* other) {
|
1828
|
-
ValueTypeSetIt it;
|
1829
|
-
ValueTypeSetItCtor(&it, self);
|
1830
|
-
while(ValueTypeSetItMove(&it)) {
|
1831
|
-
int found = 0;
|
1832
|
-
if(ValueTypeSetContains(other, *ValueTypeSetItGetRef(&it))) found = 1;
|
1833
|
-
if(!found) return 0;
|
1834
|
-
}
|
1835
|
-
return 1;
|
1915
|
+
ValueTypeMapSetCtor(dst);
|
1916
|
+
ValueTypeMapSetItCtor(&it, src);
|
1917
|
+
while(ValueTypeMapSetItMove(&it)) ValueTypeMapSetPut(dst, *ValueTypeMapSetItGetRef(&it));
|
1836
1918
|
}
|
1837
|
-
int
|
1919
|
+
AUTOC_STATIC int ValueTypeMapSetEqual(ValueTypeMapSet* lt,ValueTypeMapSet* rt) {
|
1838
1920
|
assert(lt);
|
1839
1921
|
assert(rt);
|
1840
|
-
return
|
1922
|
+
return ValueTypeMapSetSize(lt) == ValueTypeMapSetSize(rt) && ValueTypeMapSetContainsAllOf(lt, rt) && ValueTypeMapSetContainsAllOf(rt, lt);
|
1841
1923
|
}
|
1842
|
-
size_t
|
1843
|
-
|
1924
|
+
AUTOC_STATIC size_t ValueTypeMapSetIdentify(ValueTypeMapSet* self) {
|
1925
|
+
ValueTypeMapSetIt it;
|
1844
1926
|
size_t result = 0;
|
1845
1927
|
assert(self);
|
1846
|
-
|
1847
|
-
while(
|
1848
|
-
|
1849
|
-
result ^=
|
1928
|
+
ValueTypeMapSetItCtor(&it, self);
|
1929
|
+
while(ValueTypeMapSetItMove(&it)) {
|
1930
|
+
ValueTypeMapEntry* e = ValueTypeMapSetItGetRef(&it);
|
1931
|
+
result ^= ValueTypeMapEntryIdentify(*e);
|
1850
1932
|
result = AUTOC_RCYCLE(result);
|
1851
1933
|
}
|
1852
1934
|
return result;
|
1853
1935
|
}
|
1854
|
-
void
|
1936
|
+
AUTOC_STATIC void ValueTypeMapSetPurge(ValueTypeMapSet* self) {
|
1855
1937
|
assert(self);
|
1856
|
-
|
1938
|
+
ValueTypeMapSetDtor(self);
|
1857
1939
|
self->buckets = NULL;
|
1858
|
-
|
1940
|
+
ValueTypeMapSetRehash(self);
|
1859
1941
|
}
|
1860
|
-
int
|
1942
|
+
AUTOC_STATIC int ValueTypeMapSetContains(ValueTypeMapSet* self, ValueTypeMapEntry element) {
|
1861
1943
|
assert(self);
|
1862
|
-
return
|
1944
|
+
return ValueTypeMapSetListContains(&self->buckets[ValueTypeMapEntryIdentify(element) % self->bucket_count], element);
|
1863
1945
|
}
|
1864
|
-
|
1865
|
-
|
1946
|
+
AUTOC_STATIC ValueTypeMapEntry ValueTypeMapSetGet(ValueTypeMapSet* self, ValueTypeMapEntry element) {
|
1947
|
+
ValueTypeMapEntry result;
|
1866
1948
|
assert(self);
|
1867
|
-
assert(
|
1868
|
-
result =
|
1949
|
+
assert(ValueTypeMapSetContains(self, element));
|
1950
|
+
result = ValueTypeMapSetListFind(&self->buckets[ValueTypeMapEntryIdentify(element) % self->bucket_count], element);
|
1869
1951
|
return result;
|
1870
1952
|
}
|
1871
|
-
size_t
|
1953
|
+
AUTOC_STATIC size_t ValueTypeMapSetSize(ValueTypeMapSet* self) {
|
1872
1954
|
assert(self);
|
1873
1955
|
return self->size;
|
1874
1956
|
}
|
1875
|
-
int
|
1876
|
-
|
1957
|
+
AUTOC_STATIC int ValueTypeMapSetPut(ValueTypeMapSet* self, ValueTypeMapEntry element) {
|
1958
|
+
ValueTypeMapSetList* bucket;
|
1877
1959
|
assert(self);
|
1878
|
-
bucket = &self->buckets[
|
1879
|
-
if(!
|
1880
|
-
|
1960
|
+
bucket = &self->buckets[ValueTypeMapEntryIdentify(element) % self->bucket_count];
|
1961
|
+
if(!ValueTypeMapSetListContains(bucket, element)) {
|
1962
|
+
ValueTypeMapSetListPush(bucket, element);
|
1881
1963
|
++self->size;
|
1882
|
-
|
1964
|
+
ValueTypeMapSetRehash(self);
|
1883
1965
|
return 1;
|
1884
1966
|
}
|
1885
1967
|
return 0;
|
1886
1968
|
}
|
1887
|
-
int
|
1888
|
-
|
1969
|
+
AUTOC_STATIC int ValueTypeMapSetReplace(ValueTypeMapSet* self, ValueTypeMapEntry element) {
|
1970
|
+
ValueTypeMapSetList* bucket;
|
1889
1971
|
assert(self);
|
1890
|
-
bucket = &self->buckets[
|
1891
|
-
return
|
1972
|
+
bucket = &self->buckets[ValueTypeMapEntryIdentify(element) % self->bucket_count];
|
1973
|
+
return ValueTypeMapSetListReplace(bucket, element);
|
1892
1974
|
}
|
1893
|
-
int
|
1894
|
-
|
1975
|
+
AUTOC_STATIC int ValueTypeMapSetRemove(ValueTypeMapSet* self, ValueTypeMapEntry element) {
|
1976
|
+
ValueTypeMapSetList* bucket;
|
1895
1977
|
assert(self);
|
1896
|
-
bucket = &self->buckets[
|
1897
|
-
if(
|
1978
|
+
bucket = &self->buckets[ValueTypeMapEntryIdentify(element) % self->bucket_count];
|
1979
|
+
if(ValueTypeMapSetListRemove(bucket, element)) {
|
1898
1980
|
--self->size;
|
1899
|
-
|
1981
|
+
ValueTypeMapSetRehash(self);
|
1900
1982
|
return 1;
|
1901
1983
|
}
|
1902
1984
|
return 0;
|
1903
1985
|
}
|
1904
|
-
void
|
1905
|
-
|
1986
|
+
AUTOC_STATIC void ValueTypeMapSetExclude(ValueTypeMapSet* self, ValueTypeMapSet* other) {
|
1987
|
+
ValueTypeMapSetIt it;
|
1906
1988
|
assert(self);
|
1907
1989
|
assert(other);
|
1908
|
-
|
1909
|
-
while(
|
1990
|
+
ValueTypeMapSetItCtor(&it, other);
|
1991
|
+
while(ValueTypeMapSetItMove(&it)) ValueTypeMapSetRemove(self, *ValueTypeMapSetItGetRef(&it));
|
1910
1992
|
}
|
1911
|
-
void
|
1912
|
-
|
1993
|
+
AUTOC_STATIC void ValueTypeMapSetInclude(ValueTypeMapSet* self, ValueTypeMapSet* other) {
|
1994
|
+
ValueTypeMapSetIt it;
|
1913
1995
|
assert(self);
|
1914
1996
|
assert(other);
|
1915
|
-
|
1916
|
-
while(
|
1997
|
+
ValueTypeMapSetItCtor(&it, other);
|
1998
|
+
while(ValueTypeMapSetItMove(&it)) ValueTypeMapSetPut(self, *ValueTypeMapSetItGetRef(&it));
|
1917
1999
|
}
|
1918
|
-
void
|
1919
|
-
|
1920
|
-
|
2000
|
+
AUTOC_STATIC void ValueTypeMapSetRetain(ValueTypeMapSet* self, ValueTypeMapSet* other) {
|
2001
|
+
ValueTypeMapSetIt it;
|
2002
|
+
ValueTypeMapSet set;
|
1921
2003
|
assert(self);
|
1922
2004
|
assert(other);
|
1923
|
-
|
1924
|
-
|
1925
|
-
while(
|
1926
|
-
|
1927
|
-
if(
|
2005
|
+
ValueTypeMapSetCtor(&set);
|
2006
|
+
ValueTypeMapSetItCtor(&it, self);
|
2007
|
+
while(ValueTypeMapSetItMove(&it)) {
|
2008
|
+
ValueTypeMapEntry* e = ValueTypeMapSetItGetRef(&it);
|
2009
|
+
if(ValueTypeMapSetContains(other, *e)) ValueTypeMapSetPut(&set, *e);
|
1928
2010
|
}
|
1929
|
-
|
2011
|
+
ValueTypeMapSetDtor(self);
|
1930
2012
|
*self = set;
|
1931
2013
|
}
|
1932
|
-
void
|
1933
|
-
|
1934
|
-
|
2014
|
+
AUTOC_STATIC void ValueTypeMapSetInvert(ValueTypeMapSet* self, ValueTypeMapSet* other) {
|
2015
|
+
ValueTypeMapSetIt it;
|
2016
|
+
ValueTypeMapSet set;
|
1935
2017
|
assert(self);
|
1936
2018
|
assert(other);
|
1937
|
-
|
1938
|
-
|
1939
|
-
while(
|
1940
|
-
|
1941
|
-
if(!
|
2019
|
+
ValueTypeMapSetCtor(&set);
|
2020
|
+
ValueTypeMapSetItCtor(&it, self);
|
2021
|
+
while(ValueTypeMapSetItMove(&it)) {
|
2022
|
+
ValueTypeMapEntry* e = ValueTypeMapSetItGetRef(&it);
|
2023
|
+
if(!ValueTypeMapSetContains(other, *e)) ValueTypeMapSetPut(&set, *e);
|
1942
2024
|
}
|
1943
|
-
|
1944
|
-
while(
|
1945
|
-
|
1946
|
-
if(!
|
2025
|
+
ValueTypeMapSetItCtor(&it, other);
|
2026
|
+
while(ValueTypeMapSetItMove(&it)) {
|
2027
|
+
ValueTypeMapEntry* e = ValueTypeMapSetItGetRef(&it);
|
2028
|
+
if(!ValueTypeMapSetContains(self, *e)) ValueTypeMapSetPut(&set, *e);
|
1947
2029
|
}
|
1948
|
-
|
2030
|
+
ValueTypeMapSetDtor(self);
|
1949
2031
|
*self = set;
|
1950
2032
|
}
|
1951
|
-
void
|
2033
|
+
AUTOC_STATIC void ValueTypeMapSetItCtor(ValueTypeMapSetIt* self, ValueTypeMapSet* set) {
|
1952
2034
|
assert(self);
|
1953
2035
|
self->set = set;
|
1954
2036
|
self->bucket_index = -1;
|
1955
2037
|
}
|
1956
|
-
int
|
2038
|
+
AUTOC_STATIC int ValueTypeMapSetItMove(ValueTypeMapSetIt* self) {
|
1957
2039
|
assert(self);
|
1958
|
-
if(self->bucket_index < 0)
|
1959
|
-
if(
|
2040
|
+
if(self->bucket_index < 0) ValueTypeMapSetListItCtor(&self->it, &self->set->buckets[self->bucket_index = 0]);
|
2041
|
+
if(ValueTypeMapSetListItMove(&self->it)) return 1;
|
1960
2042
|
while(++self->bucket_index < self->set->bucket_count) {
|
1961
|
-
|
1962
|
-
if(
|
2043
|
+
ValueTypeMapSetListItCtor(&self->it, &self->set->buckets[self->bucket_index]);
|
2044
|
+
if(ValueTypeMapSetListItMove(&self->it)) return 1;
|
1963
2045
|
}
|
1964
2046
|
return 0;
|
1965
2047
|
}
|
1966
|
-
|
2048
|
+
AUTOC_STATIC ValueTypeMapEntry ValueTypeMapSetItGet(ValueTypeMapSetIt* self) {
|
1967
2049
|
assert(self);
|
1968
|
-
return
|
2050
|
+
return ValueTypeMapSetListItGet(&self->it);
|
1969
2051
|
}
|
1970
|
-
|
2052
|
+
AUTOC_STATIC ValueTypeMapEntry* ValueTypeMapSetItGetRef(ValueTypeMapSetIt* self) {
|
1971
2053
|
assert(self);
|
1972
|
-
return
|
2054
|
+
return ValueTypeMapSetListItGetRef(&self->it);
|
1973
2055
|
}
|
1974
2056
|
|
1975
|
-
|
1976
|
-
|
1977
|
-
|
1978
|
-
#define AUTOC_OWNED_KEY 8
|
1979
|
-
static ValueTypeMapEntry ValueTypeMapEntryKeyOnlyRef(ValueType* key) {
|
1980
|
-
ValueTypeMapEntry entry;
|
1981
|
-
entry.key = *key;
|
1982
|
-
entry.flags = AUTOC_VALID_KEY;
|
1983
|
-
return entry;
|
1984
|
-
}
|
1985
|
-
static ValueTypeMapEntry ValueTypeMapEntryKeyValueRef(ValueType* key, ValueType* value) {
|
1986
|
-
ValueTypeMapEntry entry;
|
1987
|
-
entry.key = *key;
|
1988
|
-
entry.value = *value;
|
1989
|
-
entry.flags = (AUTOC_VALID_KEY | AUTOC_VALID_VALUE);
|
1990
|
-
return entry;
|
2057
|
+
void ValueTypeMapCtor(ValueTypeMap* self) {
|
2058
|
+
assert(self);
|
2059
|
+
ValueTypeMapSetCtor(&self->entries);
|
1991
2060
|
}
|
1992
|
-
|
1993
|
-
|
1994
|
-
|
2061
|
+
void ValueTypeMapDtor(ValueTypeMap* self) {
|
2062
|
+
assert(self);
|
2063
|
+
ValueTypeMapSetDtor(&self->entries);
|
1995
2064
|
}
|
1996
|
-
|
1997
|
-
|
1998
|
-
|
2065
|
+
static int ValueTypeMapPutEntryRef(ValueTypeMap* self, ValueTypeMapEntry* entry) {
|
2066
|
+
int absent;
|
2067
|
+
assert(self);
|
2068
|
+
assert(entry);
|
2069
|
+
if((absent = !ValueTypeMapContainsKey(self, entry->key))) {
|
2070
|
+
ValueTypeMapSetPut(&self->entries, *entry);
|
2071
|
+
}
|
2072
|
+
return absent;
|
1999
2073
|
}
|
2000
|
-
|
2001
|
-
|
2002
|
-
assert(src
|
2003
|
-
dst
|
2004
|
-
|
2005
|
-
|
2006
|
-
|
2007
|
-
|
2074
|
+
void ValueTypeMapCopy(ValueTypeMap* dst,ValueTypeMap* src) {
|
2075
|
+
ValueTypeMapIt it;
|
2076
|
+
assert(src);
|
2077
|
+
assert(dst);
|
2078
|
+
ValueTypeMapCtor(dst);
|
2079
|
+
ValueTypeMapItCtor(&it, src);
|
2080
|
+
while(ValueTypeMapItMove(&it)) {
|
2081
|
+
ValueTypeMapEntry* e = ValueTypeMapItGetEntryRef(&it);
|
2082
|
+
ValueTypeMapPutEntryRef(dst, e);
|
2008
2083
|
}
|
2009
2084
|
}
|
2010
|
-
|
2011
|
-
|
2012
|
-
assert(
|
2013
|
-
|
2014
|
-
if(entry->flags & AUTOC_VALID_VALUE && entry->flags & AUTOC_OWNED_VALUE) ValueTypeDtor(entry->value);
|
2085
|
+
int ValueTypeMapEqual(ValueTypeMap* lt,ValueTypeMap* rt) {
|
2086
|
+
assert(lt);
|
2087
|
+
assert(rt);
|
2088
|
+
return ValueTypeMapSize(lt) == ValueTypeMapSize(rt) && ValueTypeMapContainsAllOf(lt, rt) && ValueTypeMapContainsAllOf(rt, lt);
|
2015
2089
|
}
|
2090
|
+
size_t ValueTypeMapIdentify(ValueTypeMap* self) {
|
2091
|
+
assert(self);
|
2092
|
+
return ValueTypeMapSetIdentify(&self->entries); /* TODO : make use of the values' hashes */
|
2093
|
+
}
|
2094
|
+
void ValueTypeMapPurge(ValueTypeMap* self) {
|
2095
|
+
assert(self);
|
2096
|
+
ValueTypeMapSetPurge(&self->entries);
|
2097
|
+
}
|
2098
|
+
size_t ValueTypeMapSize(ValueTypeMap* self) {
|
2099
|
+
assert(self);
|
2100
|
+
return ValueTypeMapSetSize(&self->entries);
|
2101
|
+
}
|
2102
|
+
int ValueTypeMapContainsKey(ValueTypeMap* self, ValueType key) {
|
2103
|
+
int result;
|
2104
|
+
ValueTypeMapEntry entry;
|
2105
|
+
assert(self);
|
2106
|
+
result = ValueTypeMapSetContains(&self->entries, entry = ValueTypeMapEntryKeyOnlyRef(&key));
|
2107
|
+
ValueTypeMapEntryDtor(entry);
|
2108
|
+
return result;
|
2109
|
+
}
|
2110
|
+
ValueType ValueTypeMapGet(ValueTypeMap* self, ValueType key) {
|
2111
|
+
ValueType result;
|
2112
|
+
ValueTypeMapEntry entry, existing_entry;
|
2113
|
+
assert(self);
|
2114
|
+
assert(ValueTypeMapContainsKey(self, key));
|
2115
|
+
existing_entry = ValueTypeMapSetGet(&self->entries, entry = ValueTypeMapEntryKeyOnlyRef(&key));
|
2116
|
+
ValueTypeCopy(result,existing_entry.value);
|
2117
|
+
ValueTypeMapEntryDtor(existing_entry);
|
2118
|
+
ValueTypeMapEntryDtor(entry);
|
2119
|
+
return result;
|
2120
|
+
}
|
2121
|
+
int ValueTypeMapPut(ValueTypeMap* self, ValueType key, ValueType value) {
|
2122
|
+
int result;
|
2123
|
+
ValueTypeMapEntry entry;
|
2124
|
+
assert(self);
|
2125
|
+
entry = ValueTypeMapEntryKeyValueRef(&key, &value);
|
2126
|
+
result = ValueTypeMapPutEntryRef(self, &entry);
|
2127
|
+
ValueTypeMapEntryDtor(entry);
|
2128
|
+
return result;
|
2129
|
+
}
|
2130
|
+
int ValueTypeMapReplace(ValueTypeMap* self, ValueType key, ValueType value) {
|
2131
|
+
int result;
|
2132
|
+
ValueTypeMapEntry entry;
|
2133
|
+
assert(self);
|
2134
|
+
entry = ValueTypeMapEntryKeyValueRef(&key, &value);
|
2135
|
+
result = ValueTypeMapSetReplace(&self->entries, entry);
|
2136
|
+
ValueTypeMapEntryDtor(entry);
|
2137
|
+
return result;
|
2138
|
+
}
|
2139
|
+
int ValueTypeMapRemove(ValueTypeMap* self, ValueType key) {
|
2140
|
+
int result;
|
2141
|
+
ValueTypeMapEntry entry;
|
2142
|
+
assert(self);
|
2143
|
+
result = ValueTypeMapSetRemove(&self->entries, entry = ValueTypeMapEntryKeyOnlyRef(&key));
|
2144
|
+
ValueTypeMapEntryDtor(entry);
|
2145
|
+
return result;
|
2146
|
+
}
|
2147
|
+
void ValueTypeMapItCtor(ValueTypeMapIt* self, ValueTypeMap* map) {
|
2148
|
+
assert(self);
|
2149
|
+
assert(map);
|
2150
|
+
ValueTypeMapSetItCtor(&self->it, &map->entries);
|
2151
|
+
}
|
2152
|
+
int ValueTypeMapItMove(ValueTypeMapIt* self) {
|
2153
|
+
assert(self);
|
2154
|
+
return ValueTypeMapSetItMove(&self->it);
|
2155
|
+
}
|
2156
|
+
ValueType ValueTypeMapItGetKey(ValueTypeMapIt* self) {
|
2157
|
+
ValueTypeMapEntry* e;
|
2158
|
+
ValueType key;
|
2159
|
+
assert(self);
|
2160
|
+
e = ValueTypeMapItGetEntryRef(self);
|
2161
|
+
ValueTypeCopy(key,e->key);
|
2162
|
+
return key;
|
2163
|
+
}
|
2164
|
+
ValueType ValueTypeMapItGetElement(ValueTypeMapIt* self) {
|
2165
|
+
ValueTypeMapEntry* e;
|
2166
|
+
ValueType value;
|
2167
|
+
assert(self);
|
2168
|
+
e = ValueTypeMapItGetEntryRef(self);
|
2169
|
+
assert(e->flags & AUTOC_VALID_VALUE);
|
2170
|
+
ValueTypeCopy(value,e->value);
|
2171
|
+
return value;
|
2172
|
+
}
|
2173
|
+
static ValueTypeMapEntry* ValueTypeMapItGetEntryRef(ValueTypeMapIt* self) {
|
2174
|
+
assert(self);
|
2175
|
+
return ValueTypeMapSetItGetRef(&self->it);
|
2176
|
+
}
|
2177
|
+
#undef AUTOC_VALID_VALUE
|
2178
|
+
#undef AUTOC_VALID_KEY
|
2179
|
+
#undef AUTOC_OWNED_VALUE
|
2180
|
+
#undef AUTOC_OWNED_KEY
|
2016
2181
|
|
2017
|
-
|
2018
|
-
|
2019
|
-
|
2020
|
-
|
2021
|
-
|
2022
|
-
|
2023
|
-
AUTOC_STATIC int ValueTypeMapSetContains(ValueTypeMapSet*, ValueTypeMapEntry);
|
2024
|
-
AUTOC_STATIC ValueTypeMapEntry ValueTypeMapSetGet(ValueTypeMapSet*, ValueTypeMapEntry);
|
2025
|
-
AUTOC_STATIC size_t ValueTypeMapSetSize(ValueTypeMapSet*);
|
2026
|
-
#define ValueTypeMapSetEmpty(self) (ValueTypeMapSetSize(self) == 0)
|
2027
|
-
AUTOC_STATIC int ValueTypeMapSetPut(ValueTypeMapSet*, ValueTypeMapEntry);
|
2028
|
-
AUTOC_STATIC int ValueTypeMapSetReplace(ValueTypeMapSet*, ValueTypeMapEntry);
|
2029
|
-
AUTOC_STATIC int ValueTypeMapSetRemove(ValueTypeMapSet*, ValueTypeMapEntry);
|
2030
|
-
AUTOC_STATIC void ValueTypeMapSetExclude(ValueTypeMapSet*, ValueTypeMapSet*);
|
2031
|
-
AUTOC_STATIC void ValueTypeMapSetRetain(ValueTypeMapSet*, ValueTypeMapSet*);
|
2032
|
-
AUTOC_STATIC void ValueTypeMapSetInclude(ValueTypeMapSet*, ValueTypeMapSet*);
|
2033
|
-
AUTOC_STATIC void ValueTypeMapSetInvert(ValueTypeMapSet*, ValueTypeMapSet*);
|
2034
|
-
AUTOC_STATIC void ValueTypeMapSetItCtor(ValueTypeMapSetIt*, ValueTypeMapSet*);
|
2035
|
-
AUTOC_STATIC int ValueTypeMapSetItMove(ValueTypeMapSetIt*);
|
2036
|
-
AUTOC_STATIC ValueTypeMapEntry ValueTypeMapSetItGet(ValueTypeMapSetIt*);
|
2037
|
-
|
2038
|
-
AUTOC_STATIC void ValueTypeMapSetListCtor(ValueTypeMapSetList*);
|
2039
|
-
AUTOC_STATIC void ValueTypeMapSetListDtor(ValueTypeMapSetList*);
|
2040
|
-
AUTOC_STATIC void ValueTypeMapSetListCopy(ValueTypeMapSetList*, ValueTypeMapSetList*);
|
2041
|
-
AUTOC_STATIC int ValueTypeMapSetListEqual(ValueTypeMapSetList*, ValueTypeMapSetList*);
|
2042
|
-
AUTOC_STATIC size_t ValueTypeMapSetListIdentify(ValueTypeMapSetList*);
|
2043
|
-
AUTOC_STATIC void ValueTypeMapSetListPurge(ValueTypeMapSetList*);
|
2044
|
-
AUTOC_STATIC ValueTypeMapEntry ValueTypeMapSetListPeek(ValueTypeMapSetList*);
|
2045
|
-
AUTOC_STATIC ValueTypeMapEntry ValueTypeMapSetListPop(ValueTypeMapSetList*);
|
2046
|
-
AUTOC_STATIC void ValueTypeMapSetListPush(ValueTypeMapSetList*, ValueTypeMapEntry);
|
2047
|
-
AUTOC_STATIC int ValueTypeMapSetListContains(ValueTypeMapSetList*, ValueTypeMapEntry);
|
2048
|
-
AUTOC_STATIC ValueTypeMapEntry ValueTypeMapSetListFind(ValueTypeMapSetList*, ValueTypeMapEntry);
|
2049
|
-
#define ValueTypeMapSetListReplace(self, with) ValueTypeMapSetListReplaceEx(self, with, 1)
|
2050
|
-
#define ValueTypeMapSetListReplaceAll(self, with) ValueTypeMapSetListReplaceEx(self, with, -1)
|
2051
|
-
AUTOC_STATIC int ValueTypeMapSetListReplaceEx(ValueTypeMapSetList*, ValueTypeMapEntry, int);
|
2052
|
-
#define ValueTypeMapSetListRemove(self, what) ValueTypeMapSetListRemoveEx(self, what, 1)
|
2053
|
-
#define ValueTypeMapSetListRemoveAll(self, what) ValueTypeMapSetListRemoveEx(self, what, -1)
|
2054
|
-
AUTOC_STATIC int ValueTypeMapSetListRemoveEx(ValueTypeMapSetList*, ValueTypeMapEntry, int);
|
2055
|
-
AUTOC_STATIC size_t ValueTypeMapSetListSize(ValueTypeMapSetList*);
|
2056
|
-
#define ValueTypeMapSetListEmpty(self) (ValueTypeMapSetListSize(self) == 0)
|
2057
|
-
AUTOC_STATIC void ValueTypeMapSetListItCtor(ValueTypeMapSetListIt*, ValueTypeMapSetList*);
|
2058
|
-
AUTOC_STATIC int ValueTypeMapSetListItMove(ValueTypeMapSetListIt*);
|
2059
|
-
AUTOC_STATIC ValueTypeMapEntry ValueTypeMapSetListItGet(ValueTypeMapSetListIt*);
|
2182
|
+
#define _ValueTypeSetListCtor(self) ValueTypeSetListCtor(&self)
|
2183
|
+
#define _ValueTypeSetListDtor(self) ValueTypeSetListDtor(&self)
|
2184
|
+
#define _ValueTypeSetListIdentify(self) ValueTypeSetListIdentify(&self)
|
2185
|
+
#define _ValueTypeSetListCopy(dst,src) ValueTypeSetListCopy(&dst,&src)
|
2186
|
+
#define _ValueTypeSetListEqual(lt,rt) ValueTypeSetListEqual(<,&rt)
|
2187
|
+
#define _ValueTypeSetListLess(lt,rt) ValueTypeSetListLess(<,&rt)
|
2060
2188
|
|
2061
|
-
AUTOC_STATIC
|
2062
|
-
AUTOC_STATIC void
|
2189
|
+
AUTOC_STATIC void ValueTypeSetListCtor(ValueTypeSetList*);
|
2190
|
+
AUTOC_STATIC void ValueTypeSetListDtor(ValueTypeSetList*);
|
2191
|
+
AUTOC_STATIC void ValueTypeSetListCopy(ValueTypeSetList*,ValueTypeSetList*);
|
2192
|
+
AUTOC_STATIC int ValueTypeSetListEqual(ValueTypeSetList*,ValueTypeSetList*);
|
2193
|
+
AUTOC_STATIC size_t ValueTypeSetListIdentify(ValueTypeSetList*);
|
2194
|
+
AUTOC_STATIC void ValueTypeSetListPurge(ValueTypeSetList*);
|
2195
|
+
AUTOC_STATIC ValueType ValueTypeSetListPeek(ValueTypeSetList*);
|
2196
|
+
AUTOC_STATIC ValueType ValueTypeSetListPop(ValueTypeSetList*);
|
2197
|
+
AUTOC_STATIC void ValueTypeSetListPush(ValueTypeSetList*, ValueType);
|
2198
|
+
AUTOC_STATIC int ValueTypeSetListContains(ValueTypeSetList*, ValueType);
|
2199
|
+
AUTOC_STATIC ValueType ValueTypeSetListFind(ValueTypeSetList*, ValueType);
|
2200
|
+
#define ValueTypeSetListReplace(self, with) ValueTypeSetListReplaceEx(self, with, 1)
|
2201
|
+
#define ValueTypeSetListReplaceAll(self, with) ValueTypeSetListReplaceEx(self, with, -1)
|
2202
|
+
AUTOC_STATIC int ValueTypeSetListReplaceEx(ValueTypeSetList*, ValueType, int);
|
2203
|
+
#define ValueTypeSetListRemove(self, what) ValueTypeSetListRemoveEx(self, what, 1)
|
2204
|
+
#define ValueTypeSetListRemoveAll(self, what) ValueTypeSetListRemoveEx(self, what, -1)
|
2205
|
+
AUTOC_STATIC int ValueTypeSetListRemoveEx(ValueTypeSetList*, ValueType, int);
|
2206
|
+
AUTOC_STATIC size_t ValueTypeSetListSize(ValueTypeSetList*);
|
2207
|
+
#define ValueTypeSetListEmpty(self) (ValueTypeSetListSize(self) == 0)
|
2208
|
+
AUTOC_STATIC void ValueTypeSetListItCtor(ValueTypeSetListIt*, ValueTypeSetList*);
|
2209
|
+
AUTOC_STATIC int ValueTypeSetListItMove(ValueTypeSetListIt*);
|
2210
|
+
AUTOC_STATIC ValueType ValueTypeSetListItGet(ValueTypeSetListIt*);
|
2211
|
+
|
2212
|
+
AUTOC_STATIC ValueType* ValueTypeSetListItGetRef(ValueTypeSetListIt*);
|
2213
|
+
AUTOC_STATIC void ValueTypeSetListCtor(ValueTypeSetList* self) {
|
2063
2214
|
assert(self);
|
2064
2215
|
self->head_node = NULL;
|
2065
2216
|
self->node_count = 0;
|
2066
2217
|
}
|
2067
|
-
AUTOC_STATIC void
|
2068
|
-
|
2218
|
+
AUTOC_STATIC void ValueTypeSetListDtor(ValueTypeSetList* self) {
|
2219
|
+
ValueTypeSetListNode* node;
|
2069
2220
|
assert(self);
|
2070
2221
|
node = self->head_node;
|
2071
2222
|
while(node) {
|
2072
|
-
|
2223
|
+
ValueTypeSetListNode* this_node = node;
|
2073
2224
|
node = node->next_node;
|
2074
|
-
|
2225
|
+
ValueTypeDtor(this_node->element);
|
2075
2226
|
free(this_node);
|
2076
2227
|
}
|
2077
2228
|
}
|
2078
|
-
AUTOC_STATIC void
|
2079
|
-
|
2229
|
+
AUTOC_STATIC void ValueTypeSetListCopy(ValueTypeSetList* dst,ValueTypeSetList* src) {
|
2230
|
+
ValueTypeSetListIt it;
|
2080
2231
|
assert(src);
|
2081
2232
|
assert(dst);
|
2082
|
-
|
2083
|
-
|
2084
|
-
while(
|
2085
|
-
|
2233
|
+
ValueTypeSetListCtor(dst);
|
2234
|
+
ValueTypeSetListItCtor(&it, src);
|
2235
|
+
while(ValueTypeSetListItMove(&it)) {
|
2236
|
+
ValueTypeSetListPush(dst, *ValueTypeSetListItGetRef(&it));
|
2086
2237
|
}
|
2087
2238
|
}
|
2088
|
-
AUTOC_STATIC int
|
2089
|
-
if(
|
2090
|
-
|
2091
|
-
|
2092
|
-
|
2093
|
-
while(
|
2239
|
+
AUTOC_STATIC int ValueTypeSetListEqual(ValueTypeSetList* lt,ValueTypeSetList* rt) {
|
2240
|
+
if(ValueTypeSetListSize(lt) == ValueTypeSetListSize(rt)) {
|
2241
|
+
ValueTypeSetListIt lit, rit;
|
2242
|
+
ValueTypeSetListItCtor(&lit, lt);
|
2243
|
+
ValueTypeSetListItCtor(&rit, rt);
|
2244
|
+
while(ValueTypeSetListItMove(&lit) && ValueTypeSetListItMove(&rit)) {
|
2094
2245
|
int equal;
|
2095
|
-
|
2096
|
-
|
2097
|
-
|
2098
|
-
|
2246
|
+
ValueType* le;
|
2247
|
+
ValueType* re;
|
2248
|
+
le = ValueTypeSetListItGetRef(&lit);
|
2249
|
+
re = ValueTypeSetListItGetRef(&rit);
|
2250
|
+
equal = ValueTypeEqual(*le,*re);
|
2099
2251
|
if(!equal) return 0;
|
2100
2252
|
}
|
2101
2253
|
return 1;
|
2102
2254
|
} else
|
2103
2255
|
return 0;
|
2104
2256
|
}
|
2105
|
-
AUTOC_STATIC size_t
|
2106
|
-
|
2257
|
+
AUTOC_STATIC size_t ValueTypeSetListIdentify(ValueTypeSetList* self) {
|
2258
|
+
ValueTypeSetListNode* node;
|
2107
2259
|
size_t result = 0;
|
2108
2260
|
assert(self);
|
2109
2261
|
for(node = self->head_node; node != NULL; node = node->next_node) {
|
2110
|
-
result ^=
|
2262
|
+
result ^= ValueTypeIdentify(node->element);
|
2111
2263
|
result = AUTOC_RCYCLE(result);
|
2112
2264
|
}
|
2113
2265
|
return result;
|
2114
2266
|
}
|
2115
|
-
AUTOC_STATIC void
|
2116
|
-
|
2117
|
-
|
2267
|
+
AUTOC_STATIC void ValueTypeSetListPurge(ValueTypeSetList* self) {
|
2268
|
+
ValueTypeSetListDtor(self);
|
2269
|
+
ValueTypeSetListCtor(self);
|
2118
2270
|
}
|
2119
|
-
AUTOC_STATIC
|
2120
|
-
|
2271
|
+
AUTOC_STATIC ValueType ValueTypeSetListPeek(ValueTypeSetList* self) {
|
2272
|
+
ValueType result;
|
2121
2273
|
assert(self);
|
2122
|
-
assert(!
|
2123
|
-
|
2274
|
+
assert(!ValueTypeSetListEmpty(self));
|
2275
|
+
ValueTypeCopy(result,self->head_node->element);
|
2124
2276
|
return result;
|
2125
2277
|
}
|
2126
|
-
AUTOC_STATIC
|
2127
|
-
|
2128
|
-
|
2278
|
+
AUTOC_STATIC ValueType ValueTypeSetListPop(ValueTypeSetList* self) {
|
2279
|
+
ValueTypeSetListNode* node;
|
2280
|
+
ValueType result;
|
2129
2281
|
assert(self);
|
2130
|
-
assert(!
|
2282
|
+
assert(!ValueTypeSetListEmpty(self));
|
2131
2283
|
node = self->head_node;
|
2132
2284
|
result = node->element;
|
2133
2285
|
self->head_node = self->head_node->next_node;
|
@@ -2135,23 +2287,23 @@ AUTOC_STATIC ValueTypeMapEntry ValueTypeMapSetListPop(ValueTypeMapSetList* self)
|
|
2135
2287
|
free(node);
|
2136
2288
|
return result;
|
2137
2289
|
}
|
2138
|
-
AUTOC_STATIC void
|
2139
|
-
|
2290
|
+
AUTOC_STATIC void ValueTypeSetListPush(ValueTypeSetList* self, ValueType element) {
|
2291
|
+
ValueTypeSetListNode* node;
|
2140
2292
|
assert(self);
|
2141
|
-
node = (
|
2293
|
+
node = (ValueTypeSetListNode*)malloc(sizeof(ValueTypeSetListNode));
|
2142
2294
|
assert(node);
|
2143
|
-
|
2295
|
+
ValueTypeCopy(node->element,element);
|
2144
2296
|
node->next_node = self->head_node;
|
2145
2297
|
self->head_node = node;
|
2146
2298
|
++self->node_count;
|
2147
2299
|
}
|
2148
|
-
AUTOC_STATIC int
|
2149
|
-
|
2300
|
+
AUTOC_STATIC int ValueTypeSetListContains(ValueTypeSetList* self, ValueType what) {
|
2301
|
+
ValueTypeSetListNode* node;
|
2150
2302
|
int found = 0;
|
2151
2303
|
assert(self);
|
2152
2304
|
node = self->head_node;
|
2153
2305
|
while(node) {
|
2154
|
-
if(
|
2306
|
+
if(ValueTypeEqual(node->element,what)) {
|
2155
2307
|
found = 1;
|
2156
2308
|
break;
|
2157
2309
|
}
|
@@ -2159,31 +2311,31 @@ AUTOC_STATIC int ValueTypeMapSetListContains(ValueTypeMapSetList* self, ValueTyp
|
|
2159
2311
|
}
|
2160
2312
|
return found;
|
2161
2313
|
}
|
2162
|
-
AUTOC_STATIC
|
2163
|
-
|
2314
|
+
AUTOC_STATIC ValueType ValueTypeSetListFind(ValueTypeSetList* self, ValueType what) {
|
2315
|
+
ValueTypeSetListNode* node;
|
2164
2316
|
assert(self);
|
2165
|
-
assert(
|
2317
|
+
assert(ValueTypeSetListContains(self, what));
|
2166
2318
|
node = self->head_node;
|
2167
2319
|
while(node) {
|
2168
|
-
if(
|
2169
|
-
|
2170
|
-
|
2320
|
+
if(ValueTypeEqual(node->element,what)) {
|
2321
|
+
ValueType result;
|
2322
|
+
ValueTypeCopy(result,node->element);
|
2171
2323
|
return result;
|
2172
2324
|
}
|
2173
2325
|
node = node->next_node;
|
2174
2326
|
}
|
2175
2327
|
abort();
|
2176
2328
|
}
|
2177
|
-
AUTOC_STATIC int
|
2178
|
-
|
2329
|
+
AUTOC_STATIC int ValueTypeSetListReplaceEx(ValueTypeSetList* self, ValueType with, int count) {
|
2330
|
+
ValueTypeSetListNode* node;
|
2179
2331
|
int replaced = 0;
|
2180
2332
|
assert(self);
|
2181
2333
|
if(count == 0) return 0;
|
2182
2334
|
node = self->head_node;
|
2183
2335
|
while(node) {
|
2184
|
-
if(
|
2185
|
-
|
2186
|
-
|
2336
|
+
if(ValueTypeEqual(node->element,with)) {
|
2337
|
+
ValueTypeDtor(node->element);
|
2338
|
+
ValueTypeCopy(node->element,with);
|
2187
2339
|
++replaced;
|
2188
2340
|
if(count > 0 && replaced >= count) break;
|
2189
2341
|
}
|
@@ -2191,16 +2343,16 @@ AUTOC_STATIC int ValueTypeMapSetListReplaceEx(ValueTypeMapSetList* self, ValueTy
|
|
2191
2343
|
}
|
2192
2344
|
return replaced;
|
2193
2345
|
}
|
2194
|
-
AUTOC_STATIC int
|
2195
|
-
|
2346
|
+
AUTOC_STATIC int ValueTypeSetListRemoveEx(ValueTypeSetList* self, ValueType what, int count) {
|
2347
|
+
ValueTypeSetListNode *node, *prev_node;
|
2196
2348
|
int removed = 0;
|
2197
2349
|
assert(self);
|
2198
2350
|
if(count == 0) return 0;
|
2199
2351
|
node = self->head_node;
|
2200
2352
|
prev_node = NULL;
|
2201
2353
|
while(node) {
|
2202
|
-
if(
|
2203
|
-
|
2354
|
+
if(ValueTypeEqual(node->element,what)) {
|
2355
|
+
ValueTypeSetListNode* this_node;
|
2204
2356
|
if(prev_node) {
|
2205
2357
|
this_node = prev_node->next_node = node->next_node;
|
2206
2358
|
} else {
|
@@ -2208,7 +2360,7 @@ AUTOC_STATIC int ValueTypeMapSetListRemoveEx(ValueTypeMapSetList* self, ValueTyp
|
|
2208
2360
|
}
|
2209
2361
|
++removed;
|
2210
2362
|
--self->node_count;
|
2211
|
-
|
2363
|
+
ValueTypeDtor(node->element);
|
2212
2364
|
free(node);
|
2213
2365
|
node = this_node;
|
2214
2366
|
if(count > 0 && removed >= count) break;
|
@@ -2219,17 +2371,17 @@ AUTOC_STATIC int ValueTypeMapSetListRemoveEx(ValueTypeMapSetList* self, ValueTyp
|
|
2219
2371
|
}
|
2220
2372
|
return removed;
|
2221
2373
|
}
|
2222
|
-
AUTOC_STATIC size_t
|
2374
|
+
AUTOC_STATIC size_t ValueTypeSetListSize(ValueTypeSetList* self) {
|
2223
2375
|
assert(self);
|
2224
2376
|
return self->node_count;
|
2225
2377
|
}
|
2226
|
-
AUTOC_STATIC void
|
2378
|
+
AUTOC_STATIC void ValueTypeSetListItCtor(ValueTypeSetListIt* self, ValueTypeSetList* list) {
|
2227
2379
|
assert(self);
|
2228
2380
|
assert(list);
|
2229
2381
|
self->start = 1;
|
2230
2382
|
self->list = list;
|
2231
2383
|
}
|
2232
|
-
AUTOC_STATIC int
|
2384
|
+
AUTOC_STATIC int ValueTypeSetListItMove(ValueTypeSetListIt* self) {
|
2233
2385
|
assert(self);
|
2234
2386
|
if(self->start) {
|
2235
2387
|
self->this_node = self->list->head_node;
|
@@ -2239,22 +2391,22 @@ AUTOC_STATIC int ValueTypeMapSetListItMove(ValueTypeMapSetListIt* self) {
|
|
2239
2391
|
}
|
2240
2392
|
return self->this_node != NULL;
|
2241
2393
|
}
|
2242
|
-
AUTOC_STATIC
|
2243
|
-
|
2394
|
+
AUTOC_STATIC ValueType ValueTypeSetListItGet(ValueTypeSetListIt* self) {
|
2395
|
+
ValueType result;
|
2244
2396
|
assert(self);
|
2245
2397
|
assert(self->this_node);
|
2246
|
-
|
2398
|
+
ValueTypeCopy(result,self->this_node->element);
|
2247
2399
|
return result;
|
2248
2400
|
}
|
2249
|
-
AUTOC_STATIC
|
2401
|
+
AUTOC_STATIC ValueType* ValueTypeSetListItGetRef(ValueTypeSetListIt* self) {
|
2250
2402
|
assert(self);
|
2251
2403
|
assert(self->this_node);
|
2252
2404
|
return &self->this_node->element;
|
2253
2405
|
}
|
2254
2406
|
|
2255
|
-
|
2256
|
-
static void
|
2257
|
-
|
2407
|
+
ValueType* ValueTypeSetItGetRef(ValueTypeSetIt*);
|
2408
|
+
static void ValueTypeSetRehash(ValueTypeSet* self) {
|
2409
|
+
ValueTypeSetList* buckets;
|
2258
2410
|
size_t index, bucket_count, size, fill;
|
2259
2411
|
assert(self);
|
2260
2412
|
assert(self->min_fill > 0);
|
@@ -2278,28 +2430,38 @@ static void ValueTypeMapSetRehash(ValueTypeMapSet* self) {
|
|
2278
2430
|
bucket_count = self->min_bucket_count;
|
2279
2431
|
size = 0;
|
2280
2432
|
}
|
2281
|
-
buckets = (
|
2433
|
+
buckets = (ValueTypeSetList*)malloc(bucket_count*sizeof(ValueTypeSetList));
|
2282
2434
|
assert(buckets);
|
2283
2435
|
for(index = 0; index < bucket_count; ++index) {
|
2284
|
-
|
2436
|
+
ValueTypeSetListCtor(&buckets[index]);
|
2285
2437
|
}
|
2286
2438
|
if(self->buckets) {
|
2287
|
-
|
2288
|
-
|
2289
|
-
while(
|
2290
|
-
|
2291
|
-
|
2292
|
-
bucket = &buckets[
|
2293
|
-
|
2294
|
-
|
2439
|
+
ValueTypeSetIt it;
|
2440
|
+
ValueTypeSetItCtor(&it, self);
|
2441
|
+
while(ValueTypeSetItMove(&it)) {
|
2442
|
+
ValueTypeSetList* bucket;
|
2443
|
+
ValueType element = ValueTypeSetItGet(&it);
|
2444
|
+
bucket = &buckets[ValueTypeIdentify(element) % bucket_count];
|
2445
|
+
ValueTypeSetListPush(bucket, element);
|
2446
|
+
ValueTypeDtor(element);
|
2295
2447
|
}
|
2296
|
-
|
2448
|
+
ValueTypeSetDtor(self);
|
2297
2449
|
}
|
2298
2450
|
self->buckets = buckets;
|
2299
2451
|
self->bucket_count = bucket_count;
|
2300
2452
|
self->size = size;
|
2301
2453
|
}
|
2302
|
-
|
2454
|
+
static int ValueTypeSetContainsAllOf(ValueTypeSet* self, ValueTypeSet* other) {
|
2455
|
+
ValueTypeSetIt it;
|
2456
|
+
ValueTypeSetItCtor(&it, self);
|
2457
|
+
while(ValueTypeSetItMove(&it)) {
|
2458
|
+
int found = 0;
|
2459
|
+
if(ValueTypeSetContains(other, *ValueTypeSetItGetRef(&it))) found = 1;
|
2460
|
+
if(!found) return 0;
|
2461
|
+
}
|
2462
|
+
return 1;
|
2463
|
+
}
|
2464
|
+
void ValueTypeSetCtor(ValueTypeSet* self) {
|
2303
2465
|
assert(self);
|
2304
2466
|
self->min_bucket_count = 16;
|
2305
2467
|
self->min_fill = 20;
|
@@ -2308,362 +2470,687 @@ AUTOC_STATIC void ValueTypeMapSetCtor(ValueTypeMapSet* self) {
|
|
2308
2470
|
self->max_size = (size_t)((float)self->max_fill/100*self->min_bucket_count);
|
2309
2471
|
self->capacity_multiplier = 200;
|
2310
2472
|
self->buckets = NULL;
|
2311
|
-
|
2473
|
+
ValueTypeSetRehash(self);
|
2312
2474
|
}
|
2313
|
-
|
2475
|
+
void ValueTypeSetDtor(ValueTypeSet* self) {
|
2314
2476
|
size_t i;
|
2315
2477
|
assert(self);
|
2316
2478
|
for(i = 0; i < self->bucket_count; ++i) {
|
2317
|
-
|
2479
|
+
ValueTypeSetListDtor(&self->buckets[i]);
|
2318
2480
|
}
|
2319
2481
|
free(self->buckets);
|
2320
2482
|
}
|
2321
|
-
|
2322
|
-
|
2483
|
+
void ValueTypeSetCopy(ValueTypeSet* dst,ValueTypeSet* src) {
|
2484
|
+
ValueTypeSetIt it;
|
2323
2485
|
assert(src);
|
2324
2486
|
assert(dst);
|
2325
|
-
|
2326
|
-
|
2327
|
-
while(
|
2328
|
-
}
|
2329
|
-
static int ValueTypeMapSetContainsAllOf(ValueTypeMapSet* self, ValueTypeMapSet* other) {
|
2330
|
-
ValueTypeMapSetIt it;
|
2331
|
-
ValueTypeMapSetItCtor(&it, self);
|
2332
|
-
while(ValueTypeMapSetItMove(&it)) {
|
2333
|
-
int found = 0;
|
2334
|
-
if(ValueTypeMapSetContains(other, *ValueTypeMapSetItGetRef(&it))) found = 1;
|
2335
|
-
if(!found) return 0;
|
2336
|
-
}
|
2337
|
-
return 1;
|
2487
|
+
ValueTypeSetCtor(dst);
|
2488
|
+
ValueTypeSetItCtor(&it, src);
|
2489
|
+
while(ValueTypeSetItMove(&it)) ValueTypeSetPut(dst, *ValueTypeSetItGetRef(&it));
|
2338
2490
|
}
|
2339
|
-
|
2491
|
+
int ValueTypeSetEqual(ValueTypeSet* lt,ValueTypeSet* rt) {
|
2340
2492
|
assert(lt);
|
2341
2493
|
assert(rt);
|
2342
|
-
return
|
2494
|
+
return ValueTypeSetSize(lt) == ValueTypeSetSize(rt) && ValueTypeSetContainsAllOf(lt, rt) && ValueTypeSetContainsAllOf(rt, lt);
|
2343
2495
|
}
|
2344
|
-
|
2345
|
-
|
2496
|
+
size_t ValueTypeSetIdentify(ValueTypeSet* self) {
|
2497
|
+
ValueTypeSetIt it;
|
2346
2498
|
size_t result = 0;
|
2347
2499
|
assert(self);
|
2348
|
-
|
2349
|
-
while(
|
2350
|
-
|
2351
|
-
result ^=
|
2500
|
+
ValueTypeSetItCtor(&it, self);
|
2501
|
+
while(ValueTypeSetItMove(&it)) {
|
2502
|
+
ValueType* e = ValueTypeSetItGetRef(&it);
|
2503
|
+
result ^= ValueTypeIdentify(*e);
|
2352
2504
|
result = AUTOC_RCYCLE(result);
|
2353
2505
|
}
|
2354
2506
|
return result;
|
2355
2507
|
}
|
2356
|
-
|
2508
|
+
void ValueTypeSetPurge(ValueTypeSet* self) {
|
2357
2509
|
assert(self);
|
2358
|
-
|
2510
|
+
ValueTypeSetDtor(self);
|
2359
2511
|
self->buckets = NULL;
|
2360
|
-
|
2512
|
+
ValueTypeSetRehash(self);
|
2361
2513
|
}
|
2362
|
-
|
2514
|
+
int ValueTypeSetContains(ValueTypeSet* self, ValueType element) {
|
2363
2515
|
assert(self);
|
2364
|
-
return
|
2516
|
+
return ValueTypeSetListContains(&self->buckets[ValueTypeIdentify(element) % self->bucket_count], element);
|
2365
2517
|
}
|
2366
|
-
|
2367
|
-
|
2518
|
+
ValueType ValueTypeSetGet(ValueTypeSet* self, ValueType element) {
|
2519
|
+
ValueType result;
|
2368
2520
|
assert(self);
|
2369
|
-
assert(
|
2370
|
-
result =
|
2521
|
+
assert(ValueTypeSetContains(self, element));
|
2522
|
+
result = ValueTypeSetListFind(&self->buckets[ValueTypeIdentify(element) % self->bucket_count], element);
|
2371
2523
|
return result;
|
2372
2524
|
}
|
2373
|
-
|
2525
|
+
size_t ValueTypeSetSize(ValueTypeSet* self) {
|
2374
2526
|
assert(self);
|
2375
2527
|
return self->size;
|
2376
2528
|
}
|
2377
|
-
|
2378
|
-
|
2529
|
+
int ValueTypeSetPut(ValueTypeSet* self, ValueType element) {
|
2530
|
+
ValueTypeSetList* bucket;
|
2379
2531
|
assert(self);
|
2380
|
-
bucket = &self->buckets[
|
2381
|
-
if(!
|
2382
|
-
|
2532
|
+
bucket = &self->buckets[ValueTypeIdentify(element) % self->bucket_count];
|
2533
|
+
if(!ValueTypeSetListContains(bucket, element)) {
|
2534
|
+
ValueTypeSetListPush(bucket, element);
|
2383
2535
|
++self->size;
|
2384
|
-
|
2536
|
+
ValueTypeSetRehash(self);
|
2385
2537
|
return 1;
|
2386
2538
|
}
|
2387
2539
|
return 0;
|
2388
2540
|
}
|
2389
|
-
|
2390
|
-
|
2541
|
+
int ValueTypeSetReplace(ValueTypeSet* self, ValueType element) {
|
2542
|
+
ValueTypeSetList* bucket;
|
2391
2543
|
assert(self);
|
2392
|
-
bucket = &self->buckets[
|
2393
|
-
return
|
2544
|
+
bucket = &self->buckets[ValueTypeIdentify(element) % self->bucket_count];
|
2545
|
+
return ValueTypeSetListReplace(bucket, element);
|
2394
2546
|
}
|
2395
|
-
|
2396
|
-
|
2547
|
+
int ValueTypeSetRemove(ValueTypeSet* self, ValueType element) {
|
2548
|
+
ValueTypeSetList* bucket;
|
2397
2549
|
assert(self);
|
2398
|
-
bucket = &self->buckets[
|
2399
|
-
if(
|
2550
|
+
bucket = &self->buckets[ValueTypeIdentify(element) % self->bucket_count];
|
2551
|
+
if(ValueTypeSetListRemove(bucket, element)) {
|
2400
2552
|
--self->size;
|
2401
|
-
|
2553
|
+
ValueTypeSetRehash(self);
|
2402
2554
|
return 1;
|
2403
2555
|
}
|
2404
2556
|
return 0;
|
2405
2557
|
}
|
2406
|
-
|
2407
|
-
|
2558
|
+
void ValueTypeSetExclude(ValueTypeSet* self, ValueTypeSet* other) {
|
2559
|
+
ValueTypeSetIt it;
|
2408
2560
|
assert(self);
|
2409
2561
|
assert(other);
|
2410
|
-
|
2411
|
-
while(
|
2562
|
+
ValueTypeSetItCtor(&it, other);
|
2563
|
+
while(ValueTypeSetItMove(&it)) ValueTypeSetRemove(self, *ValueTypeSetItGetRef(&it));
|
2412
2564
|
}
|
2413
|
-
|
2414
|
-
|
2565
|
+
void ValueTypeSetInclude(ValueTypeSet* self, ValueTypeSet* other) {
|
2566
|
+
ValueTypeSetIt it;
|
2415
2567
|
assert(self);
|
2416
2568
|
assert(other);
|
2417
|
-
|
2418
|
-
while(
|
2569
|
+
ValueTypeSetItCtor(&it, other);
|
2570
|
+
while(ValueTypeSetItMove(&it)) ValueTypeSetPut(self, *ValueTypeSetItGetRef(&it));
|
2419
2571
|
}
|
2420
|
-
|
2421
|
-
|
2422
|
-
|
2572
|
+
void ValueTypeSetRetain(ValueTypeSet* self, ValueTypeSet* other) {
|
2573
|
+
ValueTypeSetIt it;
|
2574
|
+
ValueTypeSet set;
|
2423
2575
|
assert(self);
|
2424
2576
|
assert(other);
|
2425
|
-
|
2426
|
-
|
2427
|
-
while(
|
2428
|
-
|
2429
|
-
if(
|
2577
|
+
ValueTypeSetCtor(&set);
|
2578
|
+
ValueTypeSetItCtor(&it, self);
|
2579
|
+
while(ValueTypeSetItMove(&it)) {
|
2580
|
+
ValueType* e = ValueTypeSetItGetRef(&it);
|
2581
|
+
if(ValueTypeSetContains(other, *e)) ValueTypeSetPut(&set, *e);
|
2430
2582
|
}
|
2431
|
-
|
2583
|
+
ValueTypeSetDtor(self);
|
2432
2584
|
*self = set;
|
2433
2585
|
}
|
2434
|
-
|
2435
|
-
|
2436
|
-
|
2586
|
+
void ValueTypeSetInvert(ValueTypeSet* self, ValueTypeSet* other) {
|
2587
|
+
ValueTypeSetIt it;
|
2588
|
+
ValueTypeSet set;
|
2437
2589
|
assert(self);
|
2438
2590
|
assert(other);
|
2439
|
-
|
2440
|
-
|
2441
|
-
while(
|
2442
|
-
|
2443
|
-
if(!
|
2591
|
+
ValueTypeSetCtor(&set);
|
2592
|
+
ValueTypeSetItCtor(&it, self);
|
2593
|
+
while(ValueTypeSetItMove(&it)) {
|
2594
|
+
ValueType* e = ValueTypeSetItGetRef(&it);
|
2595
|
+
if(!ValueTypeSetContains(other, *e)) ValueTypeSetPut(&set, *e);
|
2444
2596
|
}
|
2445
|
-
|
2446
|
-
while(
|
2447
|
-
|
2448
|
-
if(!
|
2597
|
+
ValueTypeSetItCtor(&it, other);
|
2598
|
+
while(ValueTypeSetItMove(&it)) {
|
2599
|
+
ValueType* e = ValueTypeSetItGetRef(&it);
|
2600
|
+
if(!ValueTypeSetContains(self, *e)) ValueTypeSetPut(&set, *e);
|
2449
2601
|
}
|
2450
|
-
|
2602
|
+
ValueTypeSetDtor(self);
|
2451
2603
|
*self = set;
|
2452
2604
|
}
|
2453
|
-
|
2605
|
+
void ValueTypeSetItCtor(ValueTypeSetIt* self, ValueTypeSet* set) {
|
2454
2606
|
assert(self);
|
2455
2607
|
self->set = set;
|
2456
2608
|
self->bucket_index = -1;
|
2457
2609
|
}
|
2458
|
-
|
2610
|
+
int ValueTypeSetItMove(ValueTypeSetIt* self) {
|
2459
2611
|
assert(self);
|
2460
|
-
if(self->bucket_index < 0)
|
2461
|
-
if(
|
2612
|
+
if(self->bucket_index < 0) ValueTypeSetListItCtor(&self->it, &self->set->buckets[self->bucket_index = 0]);
|
2613
|
+
if(ValueTypeSetListItMove(&self->it)) return 1;
|
2462
2614
|
while(++self->bucket_index < self->set->bucket_count) {
|
2463
|
-
|
2464
|
-
if(
|
2615
|
+
ValueTypeSetListItCtor(&self->it, &self->set->buckets[self->bucket_index]);
|
2616
|
+
if(ValueTypeSetListItMove(&self->it)) return 1;
|
2465
2617
|
}
|
2466
2618
|
return 0;
|
2467
2619
|
}
|
2468
|
-
|
2620
|
+
ValueType ValueTypeSetItGet(ValueTypeSetIt* self) {
|
2469
2621
|
assert(self);
|
2470
|
-
return
|
2622
|
+
return ValueTypeSetListItGet(&self->it);
|
2471
2623
|
}
|
2472
|
-
|
2624
|
+
ValueType* ValueTypeSetItGetRef(ValueTypeSetIt* self) {
|
2473
2625
|
assert(self);
|
2474
|
-
return
|
2626
|
+
return ValueTypeSetListItGetRef(&self->it);
|
2475
2627
|
}
|
2476
2628
|
|
2477
|
-
|
2478
|
-
|
2629
|
+
#define AUTOC_COUNTER(p) (*(size_t*)((char*)(p) + sizeof(ValueType)))
|
2630
|
+
ValueType* ValueTypeNew() {
|
2631
|
+
ValueType* self = (ValueType*)malloc(sizeof(ValueType) + sizeof(size_t));
|
2479
2632
|
assert(self);
|
2480
|
-
|
2633
|
+
ValueTypeCtor(*self);
|
2634
|
+
AUTOC_COUNTER(self) = 1;
|
2635
|
+
return self;
|
2481
2636
|
}
|
2482
|
-
|
2637
|
+
ValueType* ValueTypeRef(ValueType* self) {
|
2483
2638
|
assert(self);
|
2484
|
-
|
2639
|
+
++AUTOC_COUNTER(self);
|
2640
|
+
return self;
|
2485
2641
|
}
|
2486
|
-
|
2487
|
-
int absent;
|
2642
|
+
void ValueTypeFree(ValueType* self) {
|
2488
2643
|
assert(self);
|
2489
|
-
|
2490
|
-
|
2491
|
-
|
2644
|
+
if(--AUTOC_COUNTER(self) == 0) {
|
2645
|
+
ValueTypeDtor(*self);
|
2646
|
+
free(self);
|
2492
2647
|
}
|
2493
|
-
return absent;
|
2494
2648
|
}
|
2495
|
-
|
2496
|
-
|
2649
|
+
#undef AUTOC_COUNTER
|
2650
|
+
|
2651
|
+
ValueType* ValueTypeListItGetRef(ValueTypeListIt*);
|
2652
|
+
void ValueTypeListCtor(ValueTypeList* self) {
|
2653
|
+
assert(self);
|
2654
|
+
self->head_node = NULL;
|
2655
|
+
self->node_count = 0;
|
2656
|
+
}
|
2657
|
+
void ValueTypeListDtor(ValueTypeList* self) {
|
2658
|
+
ValueTypeListNode* node;
|
2659
|
+
assert(self);
|
2660
|
+
node = self->head_node;
|
2661
|
+
while(node) {
|
2662
|
+
ValueTypeListNode* this_node = node;
|
2663
|
+
node = node->next_node;
|
2664
|
+
ValueTypeDtor(this_node->element);
|
2665
|
+
free(this_node);
|
2666
|
+
}
|
2667
|
+
}
|
2668
|
+
void ValueTypeListCopy(ValueTypeList* dst,ValueTypeList* src) {
|
2669
|
+
ValueTypeListIt it;
|
2497
2670
|
assert(src);
|
2498
2671
|
assert(dst);
|
2499
|
-
|
2500
|
-
|
2501
|
-
while(
|
2502
|
-
|
2503
|
-
ValueTypeMapPutEntryRef(dst, e);
|
2672
|
+
ValueTypeListCtor(dst);
|
2673
|
+
ValueTypeListItCtor(&it, src);
|
2674
|
+
while(ValueTypeListItMove(&it)) {
|
2675
|
+
ValueTypeListPush(dst, *ValueTypeListItGetRef(&it));
|
2504
2676
|
}
|
2505
2677
|
}
|
2506
|
-
|
2507
|
-
|
2508
|
-
|
2509
|
-
|
2510
|
-
|
2511
|
-
|
2512
|
-
|
2513
|
-
ValueType
|
2514
|
-
|
2515
|
-
|
2678
|
+
int ValueTypeListEqual(ValueTypeList* lt,ValueTypeList* rt) {
|
2679
|
+
if(ValueTypeListSize(lt) == ValueTypeListSize(rt)) {
|
2680
|
+
ValueTypeListIt lit, rit;
|
2681
|
+
ValueTypeListItCtor(&lit, lt);
|
2682
|
+
ValueTypeListItCtor(&rit, rt);
|
2683
|
+
while(ValueTypeListItMove(&lit) && ValueTypeListItMove(&rit)) {
|
2684
|
+
int equal;
|
2685
|
+
ValueType* le;
|
2686
|
+
ValueType* re;
|
2687
|
+
le = ValueTypeListItGetRef(&lit);
|
2688
|
+
re = ValueTypeListItGetRef(&rit);
|
2689
|
+
equal = ValueTypeEqual(*le,*re);
|
2690
|
+
if(!equal) return 0;
|
2516
2691
|
}
|
2517
|
-
|
2518
|
-
}
|
2519
|
-
|
2520
|
-
}
|
2521
|
-
int ValueTypeMapEqual(ValueTypeMap* lt, ValueTypeMap* rt) {
|
2522
|
-
assert(lt);
|
2523
|
-
assert(rt);
|
2524
|
-
return ValueTypeMapSize(lt) == ValueTypeMapSize(rt) && ValueTypeMapContainsAllOf(lt, rt) && ValueTypeMapContainsAllOf(rt, lt);
|
2692
|
+
return 1;
|
2693
|
+
} else
|
2694
|
+
return 0;
|
2525
2695
|
}
|
2526
|
-
size_t
|
2696
|
+
size_t ValueTypeListIdentify(ValueTypeList* self) {
|
2697
|
+
ValueTypeListNode* node;
|
2698
|
+
size_t result = 0;
|
2527
2699
|
assert(self);
|
2528
|
-
|
2700
|
+
for(node = self->head_node; node != NULL; node = node->next_node) {
|
2701
|
+
result ^= ValueTypeIdentify(node->element);
|
2702
|
+
result = AUTOC_RCYCLE(result);
|
2703
|
+
}
|
2704
|
+
return result;
|
2529
2705
|
}
|
2530
|
-
void
|
2706
|
+
void ValueTypeListPurge(ValueTypeList* self) {
|
2707
|
+
ValueTypeListDtor(self);
|
2708
|
+
ValueTypeListCtor(self);
|
2709
|
+
}
|
2710
|
+
ValueType ValueTypeListPeek(ValueTypeList* self) {
|
2711
|
+
ValueType result;
|
2531
2712
|
assert(self);
|
2532
|
-
|
2713
|
+
assert(!ValueTypeListEmpty(self));
|
2714
|
+
ValueTypeCopy(result,self->head_node->element);
|
2715
|
+
return result;
|
2533
2716
|
}
|
2534
|
-
|
2717
|
+
ValueType ValueTypeListPop(ValueTypeList* self) {
|
2718
|
+
ValueTypeListNode* node;
|
2719
|
+
ValueType result;
|
2535
2720
|
assert(self);
|
2536
|
-
|
2721
|
+
assert(!ValueTypeListEmpty(self));
|
2722
|
+
node = self->head_node;
|
2723
|
+
result = node->element;
|
2724
|
+
self->head_node = self->head_node->next_node;
|
2725
|
+
--self->node_count;
|
2726
|
+
free(node);
|
2727
|
+
return result;
|
2537
2728
|
}
|
2538
|
-
|
2539
|
-
|
2540
|
-
ValueTypeMapEntry entry;
|
2729
|
+
void ValueTypeListPush(ValueTypeList* self, ValueType element) {
|
2730
|
+
ValueTypeListNode* node;
|
2541
2731
|
assert(self);
|
2542
|
-
|
2543
|
-
|
2732
|
+
node = (ValueTypeListNode*)malloc(sizeof(ValueTypeListNode));
|
2733
|
+
assert(node);
|
2734
|
+
ValueTypeCopy(node->element,element);
|
2735
|
+
node->next_node = self->head_node;
|
2736
|
+
self->head_node = node;
|
2737
|
+
++self->node_count;
|
2738
|
+
}
|
2739
|
+
int ValueTypeListContains(ValueTypeList* self, ValueType what) {
|
2740
|
+
ValueTypeListNode* node;
|
2741
|
+
int found = 0;
|
2742
|
+
assert(self);
|
2743
|
+
node = self->head_node;
|
2744
|
+
while(node) {
|
2745
|
+
if(ValueTypeEqual(node->element,what)) {
|
2746
|
+
found = 1;
|
2747
|
+
break;
|
2748
|
+
}
|
2749
|
+
node = node->next_node;
|
2750
|
+
}
|
2751
|
+
return found;
|
2752
|
+
}
|
2753
|
+
ValueType ValueTypeListFind(ValueTypeList* self, ValueType what) {
|
2754
|
+
ValueTypeListNode* node;
|
2755
|
+
assert(self);
|
2756
|
+
assert(ValueTypeListContains(self, what));
|
2757
|
+
node = self->head_node;
|
2758
|
+
while(node) {
|
2759
|
+
if(ValueTypeEqual(node->element,what)) {
|
2760
|
+
ValueType result;
|
2761
|
+
ValueTypeCopy(result,node->element);
|
2762
|
+
return result;
|
2763
|
+
}
|
2764
|
+
node = node->next_node;
|
2765
|
+
}
|
2766
|
+
abort();
|
2767
|
+
}
|
2768
|
+
int ValueTypeListReplaceEx(ValueTypeList* self, ValueType with, int count) {
|
2769
|
+
ValueTypeListNode* node;
|
2770
|
+
int replaced = 0;
|
2771
|
+
assert(self);
|
2772
|
+
if(count == 0) return 0;
|
2773
|
+
node = self->head_node;
|
2774
|
+
while(node) {
|
2775
|
+
if(ValueTypeEqual(node->element,with)) {
|
2776
|
+
ValueTypeDtor(node->element);
|
2777
|
+
ValueTypeCopy(node->element,with);
|
2778
|
+
++replaced;
|
2779
|
+
if(count > 0 && replaced >= count) break;
|
2780
|
+
}
|
2781
|
+
node = node->next_node;
|
2782
|
+
}
|
2783
|
+
return replaced;
|
2784
|
+
}
|
2785
|
+
int ValueTypeListRemoveEx(ValueTypeList* self, ValueType what, int count) {
|
2786
|
+
ValueTypeListNode *node, *prev_node;
|
2787
|
+
int removed = 0;
|
2788
|
+
assert(self);
|
2789
|
+
if(count == 0) return 0;
|
2790
|
+
node = self->head_node;
|
2791
|
+
prev_node = NULL;
|
2792
|
+
while(node) {
|
2793
|
+
if(ValueTypeEqual(node->element,what)) {
|
2794
|
+
ValueTypeListNode* this_node;
|
2795
|
+
if(prev_node) {
|
2796
|
+
this_node = prev_node->next_node = node->next_node;
|
2797
|
+
} else {
|
2798
|
+
this_node = self->head_node = node->next_node;
|
2799
|
+
}
|
2800
|
+
++removed;
|
2801
|
+
--self->node_count;
|
2802
|
+
ValueTypeDtor(node->element);
|
2803
|
+
free(node);
|
2804
|
+
node = this_node;
|
2805
|
+
if(count > 0 && removed >= count) break;
|
2806
|
+
} else {
|
2807
|
+
prev_node = node;
|
2808
|
+
node = node->next_node;
|
2809
|
+
}
|
2810
|
+
}
|
2811
|
+
return removed;
|
2812
|
+
}
|
2813
|
+
size_t ValueTypeListSize(ValueTypeList* self) {
|
2814
|
+
assert(self);
|
2815
|
+
return self->node_count;
|
2816
|
+
}
|
2817
|
+
void ValueTypeListItCtor(ValueTypeListIt* self, ValueTypeList* list) {
|
2818
|
+
assert(self);
|
2819
|
+
assert(list);
|
2820
|
+
self->start = 1;
|
2821
|
+
self->list = list;
|
2822
|
+
}
|
2823
|
+
int ValueTypeListItMove(ValueTypeListIt* self) {
|
2824
|
+
assert(self);
|
2825
|
+
if(self->start) {
|
2826
|
+
self->this_node = self->list->head_node;
|
2827
|
+
self->start = 0;
|
2828
|
+
} else {
|
2829
|
+
self->this_node = self->this_node ? self->this_node->next_node : NULL;
|
2830
|
+
}
|
2831
|
+
return self->this_node != NULL;
|
2832
|
+
}
|
2833
|
+
ValueType ValueTypeListItGet(ValueTypeListIt* self) {
|
2834
|
+
ValueType result;
|
2835
|
+
assert(self);
|
2836
|
+
assert(self->this_node);
|
2837
|
+
ValueTypeCopy(result,self->this_node->element);
|
2544
2838
|
return result;
|
2545
2839
|
}
|
2546
|
-
ValueType
|
2840
|
+
ValueType* ValueTypeListItGetRef(ValueTypeListIt* self) {
|
2841
|
+
assert(self);
|
2842
|
+
assert(self->this_node);
|
2843
|
+
return &self->this_node->element;
|
2844
|
+
}
|
2845
|
+
|
2846
|
+
ValueType* ValueTypeQueueItGetRef(ValueTypeQueueIt*);
|
2847
|
+
void ValueTypeQueueCtor(ValueTypeQueue* self) {
|
2848
|
+
assert(self);
|
2849
|
+
self->head_node = self->tail_node = NULL;
|
2850
|
+
self->node_count = 0;
|
2851
|
+
}
|
2852
|
+
void ValueTypeQueueDtor(ValueTypeQueue* self) {
|
2853
|
+
ValueTypeQueueNode* node;
|
2854
|
+
assert(self);
|
2855
|
+
node = self->head_node;
|
2856
|
+
while(node) {
|
2857
|
+
ValueTypeQueueNode* this_node = node;
|
2858
|
+
node = node->next_node;
|
2859
|
+
ValueTypeDtor(this_node->element);
|
2860
|
+
free(this_node);
|
2861
|
+
}
|
2862
|
+
}
|
2863
|
+
void ValueTypeQueueCopy(ValueTypeQueue* dst,ValueTypeQueue* src) {
|
2864
|
+
ValueTypeQueueIt it;
|
2865
|
+
assert(src);
|
2866
|
+
assert(dst);
|
2867
|
+
ValueTypeQueueCtor(dst);
|
2868
|
+
ValueTypeQueueItCtor(&it, src);
|
2869
|
+
while(ValueTypeQueueItMove(&it)) {
|
2870
|
+
ValueType element;
|
2871
|
+
ValueTypeQueuePushTail(dst, element = ValueTypeQueueItGet(&it));
|
2872
|
+
ValueTypeDtor(element);
|
2873
|
+
}
|
2874
|
+
}
|
2875
|
+
int ValueTypeQueueEqual(ValueTypeQueue* lt,ValueTypeQueue* rt) {
|
2876
|
+
if(ValueTypeQueueSize(lt) == ValueTypeQueueSize(rt)) {
|
2877
|
+
ValueTypeQueueIt lit, rit;
|
2878
|
+
ValueTypeQueueItCtor(&lit, lt);
|
2879
|
+
ValueTypeQueueItCtor(&rit, rt);
|
2880
|
+
while(ValueTypeQueueItMove(&lit) && ValueTypeQueueItMove(&rit)) {
|
2881
|
+
int equal;
|
2882
|
+
ValueType *le, *re;
|
2883
|
+
le = ValueTypeQueueItGetRef(&lit);
|
2884
|
+
re = ValueTypeQueueItGetRef(&rit);
|
2885
|
+
equal = ValueTypeEqual(*le,*re);
|
2886
|
+
if(!equal) return 0;
|
2887
|
+
}
|
2888
|
+
return 1;
|
2889
|
+
} else
|
2890
|
+
return 0;
|
2891
|
+
}
|
2892
|
+
size_t ValueTypeQueueIdentify(ValueTypeQueue* self) {
|
2893
|
+
ValueTypeQueueNode* node;
|
2894
|
+
size_t result = 0;
|
2895
|
+
assert(self);
|
2896
|
+
for(node = self->head_node; node != NULL; node = node->next_node) {
|
2897
|
+
result ^= ValueTypeIdentify(node->element);
|
2898
|
+
result = AUTOC_RCYCLE(result);
|
2899
|
+
}
|
2900
|
+
return result;
|
2901
|
+
}
|
2902
|
+
void ValueTypeQueuePurge(ValueTypeQueue* self) {
|
2903
|
+
ValueTypeQueueDtor(self);
|
2904
|
+
ValueTypeQueueCtor(self);
|
2905
|
+
}
|
2906
|
+
ValueType ValueTypeQueuePeekHead(ValueTypeQueue* self) {
|
2547
2907
|
ValueType result;
|
2548
|
-
ValueTypeMapEntry entry, existing_entry;
|
2549
2908
|
assert(self);
|
2550
|
-
assert(
|
2551
|
-
|
2552
|
-
ValueTypeCopy(result, existing_entry.value);
|
2553
|
-
ValueTypeMapEntryDtor(existing_entry);
|
2554
|
-
ValueTypeMapEntryDtor(entry);
|
2909
|
+
assert(!ValueTypeQueueEmpty(self));
|
2910
|
+
ValueTypeCopy(result,self->head_node->element);
|
2555
2911
|
return result;
|
2556
2912
|
}
|
2557
|
-
|
2558
|
-
|
2559
|
-
ValueTypeMapEntry entry;
|
2913
|
+
ValueType ValueTypeQueuePeekTail(ValueTypeQueue* self) {
|
2914
|
+
ValueType result;
|
2560
2915
|
assert(self);
|
2561
|
-
|
2562
|
-
result
|
2563
|
-
ValueTypeMapEntryDtor(entry);
|
2916
|
+
assert(!ValueTypeQueueEmpty(self));
|
2917
|
+
ValueTypeCopy(result,self->tail_node->element);
|
2564
2918
|
return result;
|
2565
2919
|
}
|
2566
|
-
|
2567
|
-
|
2568
|
-
|
2920
|
+
ValueType ValueTypeQueuePopHead(ValueTypeQueue* self) {
|
2921
|
+
ValueTypeQueueNode* node;
|
2922
|
+
ValueType result;
|
2569
2923
|
assert(self);
|
2570
|
-
|
2571
|
-
|
2572
|
-
|
2924
|
+
assert(!ValueTypeQueueEmpty(self));
|
2925
|
+
node = self->head_node;
|
2926
|
+
result = node->element;
|
2927
|
+
self->head_node = self->head_node->next_node;
|
2928
|
+
self->head_node->prev_node = NULL;
|
2929
|
+
--self->node_count;
|
2930
|
+
free(node);
|
2931
|
+
return result;
|
2932
|
+
}
|
2933
|
+
ValueType ValueTypeQueuePopTail(ValueTypeQueue* self) {
|
2934
|
+
ValueTypeQueueNode* node;
|
2935
|
+
ValueType result;
|
2936
|
+
assert(self);
|
2937
|
+
assert(!ValueTypeQueueEmpty(self));
|
2938
|
+
node = self->tail_node;
|
2939
|
+
result = node->element;
|
2940
|
+
self->tail_node = self->tail_node->prev_node;
|
2941
|
+
self->tail_node->next_node = NULL;
|
2942
|
+
--self->node_count;
|
2943
|
+
free(node);
|
2573
2944
|
return result;
|
2574
2945
|
}
|
2575
|
-
|
2576
|
-
|
2577
|
-
|
2946
|
+
void ValueTypeQueuePushTail(ValueTypeQueue* self, ValueType element) {
|
2947
|
+
ValueTypeQueueNode* node;
|
2948
|
+
assert(self);
|
2949
|
+
node = (ValueTypeQueueNode*)malloc(sizeof(ValueTypeQueueNode));
|
2950
|
+
assert(node);
|
2951
|
+
ValueTypeCopy(node->element,element);
|
2952
|
+
if(ValueTypeQueueEmpty(self)) {
|
2953
|
+
node->prev_node = node->next_node = NULL;
|
2954
|
+
self->tail_node = self->head_node = node;
|
2955
|
+
} else {
|
2956
|
+
node->next_node = NULL;
|
2957
|
+
node->prev_node = self->tail_node;
|
2958
|
+
self->tail_node->next_node = node;
|
2959
|
+
self->tail_node = node;
|
2960
|
+
}
|
2961
|
+
++self->node_count;
|
2962
|
+
}
|
2963
|
+
void ValueTypeQueuePushHead(ValueTypeQueue* self, ValueType element) {
|
2964
|
+
ValueTypeQueueNode* node;
|
2965
|
+
assert(self);
|
2966
|
+
node = (ValueTypeQueueNode*)malloc(sizeof(ValueTypeQueueNode));
|
2967
|
+
assert(node);
|
2968
|
+
ValueTypeCopy(node->element,element);
|
2969
|
+
if(ValueTypeQueueEmpty(self)) {
|
2970
|
+
node->prev_node = node->next_node = NULL;
|
2971
|
+
self->tail_node = self->head_node = node;
|
2972
|
+
} else {
|
2973
|
+
node->prev_node = NULL;
|
2974
|
+
node->next_node = self->head_node;
|
2975
|
+
self->head_node->prev_node = node;
|
2976
|
+
self->head_node = node;
|
2977
|
+
}
|
2978
|
+
++self->node_count;
|
2979
|
+
}
|
2980
|
+
int ValueTypeQueueContains(ValueTypeQueue* self, ValueType what) {
|
2981
|
+
ValueTypeQueueNode* node;
|
2982
|
+
int found = 0;
|
2983
|
+
assert(self);
|
2984
|
+
node = self->head_node;
|
2985
|
+
while(node) {
|
2986
|
+
if(ValueTypeEqual(node->element,what)) {
|
2987
|
+
found = 1;
|
2988
|
+
break;
|
2989
|
+
}
|
2990
|
+
node = node->next_node;
|
2991
|
+
}
|
2992
|
+
return found;
|
2993
|
+
}
|
2994
|
+
ValueType ValueTypeQueueFind(ValueTypeQueue* self, ValueType what) {
|
2995
|
+
ValueTypeQueueNode* node;
|
2996
|
+
assert(self);
|
2997
|
+
assert(ValueTypeQueueContains(self, what));
|
2998
|
+
node = self->head_node;
|
2999
|
+
while(node) {
|
3000
|
+
if(ValueTypeEqual(node->element,what)) {
|
3001
|
+
ValueType result;
|
3002
|
+
ValueTypeCopy(result,node->element);
|
3003
|
+
return result;
|
3004
|
+
}
|
3005
|
+
node = node->next_node;
|
3006
|
+
}
|
3007
|
+
abort();
|
3008
|
+
}
|
3009
|
+
int ValueTypeQueueReplaceEx(ValueTypeQueue* self, ValueType with, int count) {
|
3010
|
+
ValueTypeQueueNode* node;
|
3011
|
+
int replaced = 0;
|
3012
|
+
assert(self);
|
3013
|
+
if(count == 0) return 0;
|
3014
|
+
node = self->head_node;
|
3015
|
+
while(node) {
|
3016
|
+
if(ValueTypeEqual(node->element,with)) {
|
3017
|
+
ValueTypeDtor(node->element);
|
3018
|
+
ValueTypeCopy(node->element,with);
|
3019
|
+
++replaced;
|
3020
|
+
if(count > 0 && replaced >= count) break;
|
3021
|
+
}
|
3022
|
+
node = node->next_node;
|
3023
|
+
}
|
3024
|
+
return replaced;
|
3025
|
+
}
|
3026
|
+
int ValueTypeQueueRemoveEx(ValueTypeQueue* self, ValueType what, int count) {
|
3027
|
+
ValueTypeQueueNode* node;
|
3028
|
+
int removed = 0;
|
2578
3029
|
assert(self);
|
2579
|
-
|
2580
|
-
|
2581
|
-
|
3030
|
+
if(count == 0) return 0;
|
3031
|
+
node = self->head_node;
|
3032
|
+
while(node) {
|
3033
|
+
if(ValueTypeEqual(node->element,what)) {
|
3034
|
+
ValueTypeQueueNode* this_node;
|
3035
|
+
if(node == self->head_node) {
|
3036
|
+
assert(!node->prev_node);
|
3037
|
+
this_node = self->head_node = node->next_node;
|
3038
|
+
if(self->head_node) self->head_node->prev_node = NULL;
|
3039
|
+
} else if(node == self->tail_node) {
|
3040
|
+
assert(!node->next_node);
|
3041
|
+
self->tail_node = node->prev_node;
|
3042
|
+
this_node = self->tail_node->next_node = NULL;
|
3043
|
+
} else {
|
3044
|
+
assert(node->prev_node);
|
3045
|
+
assert(node->next_node);
|
3046
|
+
this_node = node->next_node;
|
3047
|
+
node->next_node->prev_node = node->prev_node;
|
3048
|
+
node->prev_node->next_node = node->next_node;
|
3049
|
+
}
|
3050
|
+
++removed;
|
3051
|
+
--self->node_count;
|
3052
|
+
ValueTypeDtor(node->element);
|
3053
|
+
free(node);
|
3054
|
+
node = this_node;
|
3055
|
+
if(count > 0 && removed >= count) break;
|
3056
|
+
} else {
|
3057
|
+
node = node->next_node;
|
3058
|
+
}
|
3059
|
+
}
|
3060
|
+
return removed;
|
2582
3061
|
}
|
2583
|
-
|
3062
|
+
size_t ValueTypeQueueSize(ValueTypeQueue* self) {
|
2584
3063
|
assert(self);
|
2585
|
-
|
2586
|
-
ValueTypeMapSetItCtor(&self->it, &map->entries);
|
3064
|
+
return self->node_count;
|
2587
3065
|
}
|
2588
|
-
|
3066
|
+
void ValueTypeQueueItCtorEx(ValueTypeQueueIt* self, ValueTypeQueue* queue, int forward) {
|
2589
3067
|
assert(self);
|
2590
|
-
|
3068
|
+
assert(queue);
|
3069
|
+
self->start = 1;
|
3070
|
+
self->queue = queue;
|
3071
|
+
self->forward = forward;
|
2591
3072
|
}
|
2592
|
-
|
2593
|
-
ValueTypeMapEntry* e;
|
2594
|
-
ValueType key;
|
3073
|
+
int ValueTypeQueueItMove(ValueTypeQueueIt* self) {
|
2595
3074
|
assert(self);
|
2596
|
-
|
2597
|
-
|
2598
|
-
|
3075
|
+
if(self->start) {
|
3076
|
+
self->this_node = self->forward ? self->queue->head_node : self->queue->tail_node;
|
3077
|
+
self->start = 0;
|
3078
|
+
} else {
|
3079
|
+
self->this_node = self->forward ? self->this_node->next_node : self->this_node->prev_node;
|
3080
|
+
}
|
3081
|
+
return self->this_node != NULL;
|
2599
3082
|
}
|
2600
|
-
ValueType
|
2601
|
-
|
2602
|
-
ValueType value;
|
3083
|
+
ValueType ValueTypeQueueItGet(ValueTypeQueueIt* self) {
|
3084
|
+
ValueType result;
|
2603
3085
|
assert(self);
|
2604
|
-
|
2605
|
-
|
2606
|
-
|
2607
|
-
return value;
|
3086
|
+
assert(self->this_node);
|
3087
|
+
ValueTypeCopy(result,self->this_node->element);
|
3088
|
+
return result;
|
2608
3089
|
}
|
2609
|
-
|
3090
|
+
ValueType* ValueTypeQueueItGetRef(ValueTypeQueueIt* self) {
|
2610
3091
|
assert(self);
|
2611
|
-
|
3092
|
+
assert(self->this_node);
|
3093
|
+
return &self->this_node->element;
|
2612
3094
|
}
|
2613
|
-
#undef AUTOC_VALID_VALUE
|
2614
|
-
#undef AUTOC_VALID_KEY
|
2615
|
-
#undef AUTOC_OWNED_VALUE
|
2616
|
-
#undef AUTOC_OWNED_KEY
|
2617
3095
|
|
2618
|
-
static void
|
3096
|
+
static void PVectorValueAllocate(PVectorValue* self, size_t element_count) {
|
2619
3097
|
assert(self);
|
2620
3098
|
assert(element_count > 0);
|
2621
3099
|
self->element_count = element_count;
|
2622
|
-
self->values = (ValueType
|
3100
|
+
self->values = (ValueType**)malloc(element_count*sizeof(ValueType*));
|
2623
3101
|
assert(self->values);
|
2624
3102
|
}
|
2625
|
-
void
|
3103
|
+
void PVectorValueCtor(PVectorValue* self,size_t element_count) {
|
2626
3104
|
size_t index;
|
2627
3105
|
assert(self);
|
2628
|
-
|
2629
|
-
for(index = 0; index <
|
2630
|
-
|
3106
|
+
PVectorValueAllocate(self, element_count);
|
3107
|
+
for(index = 0; index < PVectorValueSize(self); ++index) {
|
3108
|
+
((self->values[index]) = ValueTypeNew());
|
2631
3109
|
}
|
2632
3110
|
}
|
2633
|
-
void
|
3111
|
+
void PVectorValueDtor(PVectorValue* self) {
|
2634
3112
|
size_t index;
|
2635
3113
|
assert(self);
|
2636
|
-
for(index = 0; index <
|
2637
|
-
|
3114
|
+
for(index = 0; index < PVectorValueSize(self); ++index) {
|
3115
|
+
ValueTypeFree(self->values[index]);
|
2638
3116
|
}
|
2639
3117
|
free(self->values);
|
2640
3118
|
}
|
2641
|
-
void
|
3119
|
+
void PVectorValueCopy(PVectorValue* dst,PVectorValue* src) {
|
2642
3120
|
size_t index, size;
|
2643
3121
|
assert(src);
|
2644
3122
|
assert(dst);
|
2645
|
-
|
3123
|
+
PVectorValueAllocate(dst, size = PVectorValueSize(src));
|
2646
3124
|
for(index = 0; index < size; ++index) {
|
2647
|
-
|
3125
|
+
((dst->values[index]) = ValueTypeRef(src->values[index]));
|
2648
3126
|
}
|
2649
3127
|
}
|
2650
|
-
int
|
3128
|
+
int PVectorValueEqual(PVectorValue* lt,PVectorValue* rt) {
|
2651
3129
|
size_t index, size;
|
2652
3130
|
assert(lt);
|
2653
3131
|
assert(rt);
|
2654
|
-
if(
|
3132
|
+
if(PVectorValueSize(lt) == (size = PVectorValueSize(rt))) {
|
2655
3133
|
for(index = 0; index < size; ++index) {
|
2656
|
-
if(!ValueTypeEqual(lt->values[index]
|
3134
|
+
if(!ValueTypeEqual(*lt->values[index],*rt->values[index])) return 0;
|
2657
3135
|
}
|
2658
3136
|
return 1;
|
2659
3137
|
} else
|
2660
3138
|
return 0;
|
2661
3139
|
}
|
2662
|
-
|
3140
|
+
size_t PVectorValueIdentify(PVectorValue* self) {
|
3141
|
+
size_t index, result = 0;
|
3142
|
+
assert(self);
|
3143
|
+
for(index = 0; index < self->element_count; ++index) {
|
3144
|
+
result ^= ValueTypeIdentify(*self->values[index]);
|
3145
|
+
result = AUTOC_RCYCLE(result);
|
3146
|
+
}
|
3147
|
+
return result;
|
3148
|
+
}
|
3149
|
+
void PVectorValueResize(PVectorValue* self, size_t new_element_count) {
|
2663
3150
|
size_t index, element_count, from, to;
|
2664
3151
|
assert(self);
|
2665
|
-
if((element_count =
|
2666
|
-
ValueType
|
3152
|
+
if((element_count = PVectorValueSize(self)) != new_element_count) {
|
3153
|
+
ValueType** values = (ValueType**)malloc(new_element_count*sizeof(ValueType*));
|
2667
3154
|
assert(values);
|
2668
3155
|
from = AUTOC_MIN(element_count, new_element_count);
|
2669
3156
|
to = AUTOC_MAX(element_count, new_element_count);
|
@@ -2672,11 +3159,11 @@ void ValueTypeVectorResize(ValueTypeVector* self, size_t new_element_count) {
|
|
2672
3159
|
}
|
2673
3160
|
if(element_count > new_element_count) {
|
2674
3161
|
for(index = from; index < to; ++index) {
|
2675
|
-
|
3162
|
+
ValueTypeFree(self->values[index]);
|
2676
3163
|
}
|
2677
3164
|
} else {
|
2678
3165
|
for(index = from; index < to; ++index) {
|
2679
|
-
|
3166
|
+
((values[index]) = ValueTypeNew());
|
2680
3167
|
}
|
2681
3168
|
}
|
2682
3169
|
free(self->values);
|
@@ -2684,28 +3171,237 @@ void ValueTypeVectorResize(ValueTypeVector* self, size_t new_element_count) {
|
|
2684
3171
|
self->element_count = new_element_count;
|
2685
3172
|
}
|
2686
3173
|
}
|
2687
|
-
|
2688
|
-
|
3174
|
+
|
3175
|
+
static int PVectorValueComparator(void* lp_, void* rp_) {
|
3176
|
+
ValueType** lp = (ValueType**)lp_;
|
3177
|
+
ValueType** rp = (ValueType**)rp_;
|
3178
|
+
if(ValueTypeEqual(**lp,**rp)) {
|
3179
|
+
return 0;
|
3180
|
+
} else if(ValueTypeLess(**lp,**rp)) {
|
3181
|
+
return -1;
|
3182
|
+
} else {
|
3183
|
+
return +1;
|
3184
|
+
}
|
3185
|
+
}
|
3186
|
+
void PVectorValueSort(PVectorValue* self) {
|
3187
|
+
typedef int (*F)(const void*, const void*);
|
2689
3188
|
assert(self);
|
2690
|
-
|
2691
|
-
|
3189
|
+
qsort(self->values, PVectorValueSize(self), sizeof(ValueType*), (F)PVectorValueComparator);
|
3190
|
+
}
|
3191
|
+
|
3192
|
+
#define AUTOC_COUNTER(p) (*(size_t*)((char*)(p) + sizeof(PVectorValue)))
|
3193
|
+
PVectorValue* PVectorValueNew(size_t element_count) {
|
3194
|
+
PVectorValue* self = (PVectorValue*)malloc(sizeof(PVectorValue) + sizeof(size_t));
|
3195
|
+
assert(self);
|
3196
|
+
_PVectorValueCtor(*self,element_count);
|
3197
|
+
AUTOC_COUNTER(self) = 1;
|
3198
|
+
return self;
|
3199
|
+
}
|
3200
|
+
PVectorValue* PVectorValueRef(PVectorValue* self) {
|
3201
|
+
assert(self);
|
3202
|
+
++AUTOC_COUNTER(self);
|
3203
|
+
return self;
|
3204
|
+
}
|
3205
|
+
void PVectorValueFree(PVectorValue* self) {
|
3206
|
+
assert(self);
|
3207
|
+
if(--AUTOC_COUNTER(self) == 0) {
|
3208
|
+
_PVectorValueDtor(*self);
|
3209
|
+
free(self);
|
3210
|
+
}
|
3211
|
+
}
|
3212
|
+
#undef AUTOC_COUNTER
|
3213
|
+
|
3214
|
+
PVectorValue** ListPVectorValueItGetRef(ListPVectorValueIt*);
|
3215
|
+
void ListPVectorValueCtor(ListPVectorValue* self) {
|
3216
|
+
assert(self);
|
3217
|
+
self->head_node = NULL;
|
3218
|
+
self->node_count = 0;
|
3219
|
+
}
|
3220
|
+
void ListPVectorValueDtor(ListPVectorValue* self) {
|
3221
|
+
ListPVectorValueNode* node;
|
3222
|
+
assert(self);
|
3223
|
+
node = self->head_node;
|
3224
|
+
while(node) {
|
3225
|
+
ListPVectorValueNode* this_node = node;
|
3226
|
+
node = node->next_node;
|
3227
|
+
PVectorValueFree(this_node->element);
|
3228
|
+
free(this_node);
|
3229
|
+
}
|
3230
|
+
}
|
3231
|
+
void ListPVectorValueCopy(ListPVectorValue* dst,ListPVectorValue* src) {
|
3232
|
+
ListPVectorValueIt it;
|
3233
|
+
assert(src);
|
3234
|
+
assert(dst);
|
3235
|
+
ListPVectorValueCtor(dst);
|
3236
|
+
ListPVectorValueItCtor(&it, src);
|
3237
|
+
while(ListPVectorValueItMove(&it)) {
|
3238
|
+
ListPVectorValuePush(dst, *ListPVectorValueItGetRef(&it));
|
3239
|
+
}
|
3240
|
+
}
|
3241
|
+
int ListPVectorValueEqual(ListPVectorValue* lt,ListPVectorValue* rt) {
|
3242
|
+
if(ListPVectorValueSize(lt) == ListPVectorValueSize(rt)) {
|
3243
|
+
ListPVectorValueIt lit, rit;
|
3244
|
+
ListPVectorValueItCtor(&lit, lt);
|
3245
|
+
ListPVectorValueItCtor(&rit, rt);
|
3246
|
+
while(ListPVectorValueItMove(&lit) && ListPVectorValueItMove(&rit)) {
|
3247
|
+
int equal;
|
3248
|
+
PVectorValue** le;
|
3249
|
+
PVectorValue** re;
|
3250
|
+
le = ListPVectorValueItGetRef(&lit);
|
3251
|
+
re = ListPVectorValueItGetRef(&rit);
|
3252
|
+
equal = _PVectorValueEqual(**le,**re);
|
3253
|
+
if(!equal) return 0;
|
3254
|
+
}
|
3255
|
+
return 1;
|
3256
|
+
} else
|
3257
|
+
return 0;
|
3258
|
+
}
|
3259
|
+
size_t ListPVectorValueIdentify(ListPVectorValue* self) {
|
3260
|
+
ListPVectorValueNode* node;
|
3261
|
+
size_t result = 0;
|
3262
|
+
assert(self);
|
3263
|
+
for(node = self->head_node; node != NULL; node = node->next_node) {
|
3264
|
+
result ^= _PVectorValueIdentify(*node->element);
|
2692
3265
|
result = AUTOC_RCYCLE(result);
|
2693
3266
|
}
|
2694
3267
|
return result;
|
2695
3268
|
}
|
2696
|
-
|
2697
|
-
|
2698
|
-
|
2699
|
-
|
2700
|
-
|
2701
|
-
|
2702
|
-
|
3269
|
+
void ListPVectorValuePurge(ListPVectorValue* self) {
|
3270
|
+
ListPVectorValueDtor(self);
|
3271
|
+
ListPVectorValueCtor(self);
|
3272
|
+
}
|
3273
|
+
PVectorValue* ListPVectorValuePeek(ListPVectorValue* self) {
|
3274
|
+
PVectorValue* result;
|
3275
|
+
assert(self);
|
3276
|
+
assert(!ListPVectorValueEmpty(self));
|
3277
|
+
((result) = PVectorValueRef(self->head_node->element));
|
3278
|
+
return result;
|
3279
|
+
}
|
3280
|
+
PVectorValue* ListPVectorValuePop(ListPVectorValue* self) {
|
3281
|
+
ListPVectorValueNode* node;
|
3282
|
+
PVectorValue* result;
|
3283
|
+
assert(self);
|
3284
|
+
assert(!ListPVectorValueEmpty(self));
|
3285
|
+
node = self->head_node;
|
3286
|
+
result = node->element;
|
3287
|
+
self->head_node = self->head_node->next_node;
|
3288
|
+
--self->node_count;
|
3289
|
+
free(node);
|
3290
|
+
return result;
|
3291
|
+
}
|
3292
|
+
void ListPVectorValuePush(ListPVectorValue* self, PVectorValue* element) {
|
3293
|
+
ListPVectorValueNode* node;
|
3294
|
+
assert(self);
|
3295
|
+
node = (ListPVectorValueNode*)malloc(sizeof(ListPVectorValueNode));
|
3296
|
+
assert(node);
|
3297
|
+
((node->element) = PVectorValueRef(element));
|
3298
|
+
node->next_node = self->head_node;
|
3299
|
+
self->head_node = node;
|
3300
|
+
++self->node_count;
|
3301
|
+
}
|
3302
|
+
int ListPVectorValueContains(ListPVectorValue* self, PVectorValue* what) {
|
3303
|
+
ListPVectorValueNode* node;
|
3304
|
+
int found = 0;
|
3305
|
+
assert(self);
|
3306
|
+
node = self->head_node;
|
3307
|
+
while(node) {
|
3308
|
+
if(_PVectorValueEqual(*node->element,*what)) {
|
3309
|
+
found = 1;
|
3310
|
+
break;
|
3311
|
+
}
|
3312
|
+
node = node->next_node;
|
3313
|
+
}
|
3314
|
+
return found;
|
3315
|
+
}
|
3316
|
+
PVectorValue* ListPVectorValueFind(ListPVectorValue* self, PVectorValue* what) {
|
3317
|
+
ListPVectorValueNode* node;
|
3318
|
+
assert(self);
|
3319
|
+
assert(ListPVectorValueContains(self, what));
|
3320
|
+
node = self->head_node;
|
3321
|
+
while(node) {
|
3322
|
+
if(_PVectorValueEqual(*node->element,*what)) {
|
3323
|
+
PVectorValue* result;
|
3324
|
+
((result) = PVectorValueRef(node->element));
|
3325
|
+
return result;
|
3326
|
+
}
|
3327
|
+
node = node->next_node;
|
3328
|
+
}
|
3329
|
+
abort();
|
3330
|
+
}
|
3331
|
+
int ListPVectorValueReplaceEx(ListPVectorValue* self, PVectorValue* with, int count) {
|
3332
|
+
ListPVectorValueNode* node;
|
3333
|
+
int replaced = 0;
|
3334
|
+
assert(self);
|
3335
|
+
if(count == 0) return 0;
|
3336
|
+
node = self->head_node;
|
3337
|
+
while(node) {
|
3338
|
+
if(_PVectorValueEqual(*node->element,*with)) {
|
3339
|
+
PVectorValueFree(node->element);
|
3340
|
+
((node->element) = PVectorValueRef(with));
|
3341
|
+
++replaced;
|
3342
|
+
if(count > 0 && replaced >= count) break;
|
3343
|
+
}
|
3344
|
+
node = node->next_node;
|
3345
|
+
}
|
3346
|
+
return replaced;
|
3347
|
+
}
|
3348
|
+
int ListPVectorValueRemoveEx(ListPVectorValue* self, PVectorValue* what, int count) {
|
3349
|
+
ListPVectorValueNode *node, *prev_node;
|
3350
|
+
int removed = 0;
|
3351
|
+
assert(self);
|
3352
|
+
if(count == 0) return 0;
|
3353
|
+
node = self->head_node;
|
3354
|
+
prev_node = NULL;
|
3355
|
+
while(node) {
|
3356
|
+
if(_PVectorValueEqual(*node->element,*what)) {
|
3357
|
+
ListPVectorValueNode* this_node;
|
3358
|
+
if(prev_node) {
|
3359
|
+
this_node = prev_node->next_node = node->next_node;
|
3360
|
+
} else {
|
3361
|
+
this_node = self->head_node = node->next_node;
|
3362
|
+
}
|
3363
|
+
++removed;
|
3364
|
+
--self->node_count;
|
3365
|
+
PVectorValueFree(node->element);
|
3366
|
+
free(node);
|
3367
|
+
node = this_node;
|
3368
|
+
if(count > 0 && removed >= count) break;
|
3369
|
+
} else {
|
3370
|
+
prev_node = node;
|
3371
|
+
node = node->next_node;
|
3372
|
+
}
|
3373
|
+
}
|
3374
|
+
return removed;
|
3375
|
+
}
|
3376
|
+
size_t ListPVectorValueSize(ListPVectorValue* self) {
|
3377
|
+
assert(self);
|
3378
|
+
return self->node_count;
|
3379
|
+
}
|
3380
|
+
void ListPVectorValueItCtor(ListPVectorValueIt* self, ListPVectorValue* list) {
|
3381
|
+
assert(self);
|
3382
|
+
assert(list);
|
3383
|
+
self->start = 1;
|
3384
|
+
self->list = list;
|
3385
|
+
}
|
3386
|
+
int ListPVectorValueItMove(ListPVectorValueIt* self) {
|
3387
|
+
assert(self);
|
3388
|
+
if(self->start) {
|
3389
|
+
self->this_node = self->list->head_node;
|
3390
|
+
self->start = 0;
|
2703
3391
|
} else {
|
2704
|
-
|
3392
|
+
self->this_node = self->this_node ? self->this_node->next_node : NULL;
|
2705
3393
|
}
|
3394
|
+
return self->this_node != NULL;
|
2706
3395
|
}
|
2707
|
-
|
2708
|
-
|
3396
|
+
PVectorValue* ListPVectorValueItGet(ListPVectorValueIt* self) {
|
3397
|
+
PVectorValue* result;
|
2709
3398
|
assert(self);
|
2710
|
-
|
3399
|
+
assert(self->this_node);
|
3400
|
+
((result) = PVectorValueRef(self->this_node->element));
|
3401
|
+
return result;
|
3402
|
+
}
|
3403
|
+
PVectorValue** ListPVectorValueItGetRef(ListPVectorValueIt* self) {
|
3404
|
+
assert(self);
|
3405
|
+
assert(self->this_node);
|
3406
|
+
return &self->this_node->element;
|
2711
3407
|
}
|