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
@@ -148,64 +148,67 @@ class HashSet < Collection
|
|
148
148
|
def initialize(*args)
|
149
149
|
super
|
150
150
|
@list = List.new(list, element, :static)
|
151
|
+
@capability.subtract [:orderable]
|
152
|
+
key_type_check(element)
|
151
153
|
end
|
152
154
|
|
153
|
-
def
|
155
|
+
def write_intf_types(stream)
|
154
156
|
stream << %$
|
155
157
|
/***
|
156
158
|
**** #{type}<#{element.type}> (#{self.class})
|
157
159
|
***/
|
158
160
|
$ if public?
|
159
|
-
@list.
|
161
|
+
@list.write_intf_types(stream)
|
160
162
|
stream << %$
|
161
163
|
typedef struct #{type} #{type};
|
162
164
|
typedef struct #{it} #{it};
|
163
165
|
struct #{type} {
|
164
|
-
#{@list.
|
166
|
+
#{@list.type_ref} buckets;
|
165
167
|
size_t bucket_count, min_bucket_count;
|
166
168
|
size_t size, min_size, max_size;
|
167
169
|
unsigned min_fill, max_fill, capacity_multiplier; /* ?*1e-2 */
|
168
170
|
};
|
169
171
|
struct #{it} {
|
170
|
-
#{
|
172
|
+
#{type_ref} set;
|
171
173
|
int bucket_index;
|
172
174
|
#{@list.it} it;
|
173
175
|
};
|
174
176
|
$
|
175
177
|
end
|
176
178
|
|
177
|
-
def
|
179
|
+
def write_intf_decls(stream, declare, define)
|
180
|
+
super
|
178
181
|
stream << %$
|
179
|
-
#{declare}
|
180
|
-
#{declare}
|
181
|
-
#{declare}
|
182
|
-
#{declare}
|
183
|
-
#{declare}
|
184
|
-
#{declare} void #{purge}(#{
|
185
|
-
#{declare} int #{contains}(#{
|
186
|
-
#{declare} #{element.type} #{get}(#{
|
187
|
-
#{declare} size_t #{size}(#{
|
182
|
+
#{declare} #{ctor.declaration};
|
183
|
+
#{declare} #{dtor.declaration};
|
184
|
+
#{declare} #{copy.declaration};
|
185
|
+
#{declare} #{equal.declaration};
|
186
|
+
#{declare} #{identify.declaration};
|
187
|
+
#{declare} void #{purge}(#{type_ref});
|
188
|
+
#{declare} int #{contains}(#{type_ref}, #{element.type});
|
189
|
+
#{declare} #{element.type} #{get}(#{type_ref}, #{element.type});
|
190
|
+
#{declare} size_t #{size}(#{type_ref});
|
188
191
|
#define #{empty}(self) (#{size}(self) == 0)
|
189
|
-
#{declare} int #{put}(#{
|
190
|
-
#{declare} int #{replace}(#{
|
191
|
-
#{declare} int #{remove}(#{
|
192
|
-
#{declare} void #{exclude}(#{
|
193
|
-
#{declare} void #{retain}(#{
|
194
|
-
#{declare} void #{include}(#{
|
195
|
-
#{declare} void #{invert}(#{
|
196
|
-
#{declare} void #{itCtor}(#{
|
197
|
-
#{declare} int #{itMove}(#{
|
198
|
-
#{declare} #{element.type} #{itGet}(#{
|
192
|
+
#{declare} int #{put}(#{type_ref}, #{element.type});
|
193
|
+
#{declare} int #{replace}(#{type_ref}, #{element.type});
|
194
|
+
#{declare} int #{remove}(#{type_ref}, #{element.type});
|
195
|
+
#{declare} void #{exclude}(#{type_ref}, #{type_ref});
|
196
|
+
#{declare} void #{retain}(#{type_ref}, #{type_ref});
|
197
|
+
#{declare} void #{include}(#{type_ref}, #{type_ref});
|
198
|
+
#{declare} void #{invert}(#{type_ref}, #{type_ref});
|
199
|
+
#{declare} void #{itCtor}(#{it_ref}, #{type_ref});
|
200
|
+
#{declare} int #{itMove}(#{it_ref});
|
201
|
+
#{declare} #{element.type} #{itGet}(#{it_ref});
|
199
202
|
$
|
200
203
|
end
|
201
204
|
|
202
|
-
def
|
203
|
-
@list.
|
204
|
-
@list.
|
205
|
+
def write_impls(stream, define)
|
206
|
+
@list.write_intf_decls(stream, static, inline)
|
207
|
+
@list.write_impls(stream, static)
|
205
208
|
stream << %$
|
206
|
-
#{define} #{element.
|
207
|
-
static void #{rehash}(#{
|
208
|
-
#{@list.
|
209
|
+
#{define} #{element.type_ref} #{itGetRef}(#{it_ref});
|
210
|
+
static void #{rehash}(#{type_ref} self) {
|
211
|
+
#{@list.type_ref} buckets;
|
209
212
|
size_t index, bucket_count, size, fill;
|
210
213
|
#{assert}(self);
|
211
214
|
#{assert}(self->min_fill > 0);
|
@@ -230,7 +233,7 @@ class HashSet < Collection
|
|
230
233
|
bucket_count = self->min_bucket_count;
|
231
234
|
size = 0;
|
232
235
|
}
|
233
|
-
buckets = (#{@list.
|
236
|
+
buckets = (#{@list.type_ref})#{malloc}(bucket_count*sizeof(#{@list.type})); #{assert}(buckets);
|
234
237
|
for(index = 0; index < bucket_count; ++index) {
|
235
238
|
#{@list.ctor}(&buckets[index]);
|
236
239
|
}
|
@@ -250,7 +253,17 @@ class HashSet < Collection
|
|
250
253
|
self->bucket_count = bucket_count;
|
251
254
|
self->size = size;
|
252
255
|
}
|
253
|
-
|
256
|
+
static int #{containsAllOf}(#{type_ref} self, #{type_ref} other) {
|
257
|
+
#{it} it;
|
258
|
+
#{itCtor}(&it, self);
|
259
|
+
while(#{itMove}(&it)) {
|
260
|
+
int found = 0;
|
261
|
+
if(#{contains}(other, *#{itGetRef}(&it))) found = 1;
|
262
|
+
if(!found) return 0;
|
263
|
+
}
|
264
|
+
return 1;
|
265
|
+
}
|
266
|
+
#{define} #{ctor.definition} {
|
254
267
|
#{assert}(self);
|
255
268
|
self->min_bucket_count = 16;
|
256
269
|
self->min_fill = 20;
|
@@ -261,7 +274,7 @@ class HashSet < Collection
|
|
261
274
|
self->buckets = NULL;
|
262
275
|
#{rehash}(self);
|
263
276
|
}
|
264
|
-
#{define}
|
277
|
+
#{define} #{dtor.definition} {
|
265
278
|
size_t i;
|
266
279
|
#{assert}(self);
|
267
280
|
for(i = 0; i < self->bucket_count; ++i) {
|
@@ -269,7 +282,7 @@ class HashSet < Collection
|
|
269
282
|
}
|
270
283
|
#{free}(self->buckets);
|
271
284
|
}
|
272
|
-
#{define}
|
285
|
+
#{define} #{copy.definition} {
|
273
286
|
#{it} it;
|
274
287
|
#{assert}(src);
|
275
288
|
#{assert}(dst);
|
@@ -277,22 +290,12 @@ class HashSet < Collection
|
|
277
290
|
#{itCtor}(&it, src);
|
278
291
|
while(#{itMove}(&it)) #{put}(dst, *#{itGetRef}(&it));
|
279
292
|
}
|
280
|
-
|
281
|
-
#{it} it;
|
282
|
-
#{itCtor}(&it, self);
|
283
|
-
while(#{itMove}(&it)) {
|
284
|
-
int found = 0;
|
285
|
-
if(#{contains}(other, *#{itGetRef}(&it))) found = 1;
|
286
|
-
if(!found) return 0;
|
287
|
-
}
|
288
|
-
return 1;
|
289
|
-
}
|
290
|
-
#{define} int #{equal}(#{type}* lt, #{type}* rt) {
|
293
|
+
#{define} #{equal.definition} {
|
291
294
|
#{assert}(lt);
|
292
295
|
#{assert}(rt);
|
293
296
|
return #{size}(lt) == #{size}(rt) && #{containsAllOf}(lt, rt) && #{containsAllOf}(rt, lt);
|
294
297
|
}
|
295
|
-
#{define}
|
298
|
+
#{define} #{identify.definition} {
|
296
299
|
#{it} it;
|
297
300
|
size_t result = 0;
|
298
301
|
#{assert}(self);
|
@@ -304,29 +307,29 @@ class HashSet < Collection
|
|
304
307
|
}
|
305
308
|
return result;
|
306
309
|
}
|
307
|
-
#{define} void #{purge}(#{
|
310
|
+
#{define} void #{purge}(#{type_ref} self) {
|
308
311
|
#{assert}(self);
|
309
312
|
#{dtor}(self);
|
310
313
|
self->buckets = NULL;
|
311
314
|
#{rehash}(self);
|
312
315
|
}
|
313
|
-
#{define} int #{contains}(#{
|
316
|
+
#{define} int #{contains}(#{type_ref} self, #{element.type} element) {
|
314
317
|
#{assert}(self);
|
315
318
|
return #{@list.contains}(&self->buckets[#{element.identify("element")} % self->bucket_count], element);
|
316
319
|
}
|
317
|
-
#{define} #{element.type} #{get}(#{
|
320
|
+
#{define} #{element.type} #{get}(#{type_ref} self, #{element.type} element) {
|
318
321
|
#{element.type} result;
|
319
322
|
#{assert}(self);
|
320
323
|
#{assert}(#{contains}(self, element));
|
321
324
|
result = #{@list.find}(&self->buckets[#{element.identify("element")} % self->bucket_count], element);
|
322
325
|
return result;
|
323
326
|
}
|
324
|
-
#{define} size_t #{size}(#{
|
327
|
+
#{define} size_t #{size}(#{type_ref} self) {
|
325
328
|
#{assert}(self);
|
326
329
|
return self->size;
|
327
330
|
}
|
328
|
-
#{define} int #{put}(#{
|
329
|
-
#{@list.
|
331
|
+
#{define} int #{put}(#{type_ref} self, #{element.type} element) {
|
332
|
+
#{@list.type_ref} bucket;
|
330
333
|
#{assert}(self);
|
331
334
|
bucket = &self->buckets[#{element.identify("element")} % self->bucket_count];
|
332
335
|
if(!#{@list.contains}(bucket, element)) {
|
@@ -337,14 +340,14 @@ class HashSet < Collection
|
|
337
340
|
}
|
338
341
|
return 0;
|
339
342
|
}
|
340
|
-
#{define} int #{replace}(#{
|
341
|
-
#{@list.
|
343
|
+
#{define} int #{replace}(#{type_ref} self, #{element.type} element) {
|
344
|
+
#{@list.type_ref} bucket;
|
342
345
|
#{assert}(self);
|
343
346
|
bucket = &self->buckets[#{element.identify("element")} % self->bucket_count];
|
344
347
|
return #{@list.replace}(bucket, element);
|
345
348
|
}
|
346
|
-
#{define} int #{remove}(#{
|
347
|
-
#{@list.
|
349
|
+
#{define} int #{remove}(#{type_ref} self, #{element.type} element) {
|
350
|
+
#{@list.type_ref} bucket;
|
348
351
|
#{assert}(self);
|
349
352
|
bucket = &self->buckets[#{element.identify("element")} % self->bucket_count];
|
350
353
|
if(#{@list.remove}(bucket, element)) {
|
@@ -354,21 +357,21 @@ class HashSet < Collection
|
|
354
357
|
}
|
355
358
|
return 0;
|
356
359
|
}
|
357
|
-
#{define} void #{exclude}(#{
|
360
|
+
#{define} void #{exclude}(#{type_ref} self, #{type_ref} other) {
|
358
361
|
#{it} it;
|
359
362
|
#{assert}(self);
|
360
363
|
#{assert}(other);
|
361
364
|
#{itCtor}(&it, other);
|
362
365
|
while(#{itMove}(&it)) #{remove}(self, *#{itGetRef}(&it));
|
363
366
|
}
|
364
|
-
#{define} void #{include}(#{
|
367
|
+
#{define} void #{include}(#{type_ref} self, #{type_ref} other) {
|
365
368
|
#{it} it;
|
366
369
|
#{assert}(self);
|
367
370
|
#{assert}(other);
|
368
371
|
#{itCtor}(&it, other);
|
369
372
|
while(#{itMove}(&it)) #{put}(self, *#{itGetRef}(&it));
|
370
373
|
}
|
371
|
-
#{define} void #{retain}(#{
|
374
|
+
#{define} void #{retain}(#{type_ref} self, #{type_ref} other) {
|
372
375
|
#{it} it;
|
373
376
|
#{type} set;
|
374
377
|
#{assert}(self);
|
@@ -382,7 +385,7 @@ class HashSet < Collection
|
|
382
385
|
#{dtor}(self);
|
383
386
|
*self = set;
|
384
387
|
}
|
385
|
-
#{define} void #{invert}(#{
|
388
|
+
#{define} void #{invert}(#{type_ref} self, #{type_ref} other) {
|
386
389
|
#{it} it;
|
387
390
|
#{type} set;
|
388
391
|
#{assert}(self);
|
@@ -401,12 +404,12 @@ class HashSet < Collection
|
|
401
404
|
#{dtor}(self);
|
402
405
|
*self = set;
|
403
406
|
}
|
404
|
-
#{define} void #{itCtor}(#{
|
407
|
+
#{define} void #{itCtor}(#{it_ref} self, #{type_ref} set) {
|
405
408
|
#{assert}(self);
|
406
409
|
self->set = set;
|
407
410
|
self->bucket_index = -1;
|
408
411
|
}
|
409
|
-
#{define} int #{itMove}(#{
|
412
|
+
#{define} int #{itMove}(#{it_ref} self) {
|
410
413
|
#{assert}(self);
|
411
414
|
if(self->bucket_index < 0) #{@list.itCtor}(&self->it, &self->set->buckets[self->bucket_index = 0]);
|
412
415
|
if(#{@list.itMove}(&self->it)) return 1;
|
@@ -416,17 +419,24 @@ class HashSet < Collection
|
|
416
419
|
}
|
417
420
|
return 0;
|
418
421
|
}
|
419
|
-
#{define} #{element.type} #{itGet}(#{
|
422
|
+
#{define} #{element.type} #{itGet}(#{it_ref} self) {
|
420
423
|
#{assert}(self);
|
421
424
|
return #{@list.itGet}(&self->it);
|
422
425
|
}
|
423
|
-
#{define} #{element.
|
426
|
+
#{define} #{element.type_ref} #{itGetRef}(#{it_ref} self) {
|
424
427
|
#{assert}(self);
|
425
428
|
return #{@list.itGetRef}(&self->it);
|
426
429
|
}
|
427
430
|
$
|
428
431
|
end
|
429
432
|
|
433
|
+
private
|
434
|
+
|
435
|
+
def key_type_check(obj)
|
436
|
+
raise "type #{obj.type} (#{obj}) must be hashable" unless obj.hashable?
|
437
|
+
element_type_check(obj)
|
438
|
+
end
|
439
|
+
|
430
440
|
end # HashSet
|
431
441
|
|
432
442
|
|
@@ -154,7 +154,12 @@ WARNING: current position *must* be valid otherwise the behavior is undefined. S
|
|
154
154
|
=end
|
155
155
|
class List < Collection
|
156
156
|
|
157
|
-
def
|
157
|
+
def initialize(*args)
|
158
|
+
super
|
159
|
+
@capability.subtract [:orderable]
|
160
|
+
end
|
161
|
+
|
162
|
+
def write_intf_types(stream)
|
158
163
|
stream << %$
|
159
164
|
/***
|
160
165
|
**** #{type}<#{element.type}> (#{self.class})
|
@@ -170,7 +175,7 @@ class List < Collection
|
|
170
175
|
};
|
171
176
|
struct #{it} {
|
172
177
|
int start;
|
173
|
-
#{
|
178
|
+
#{type_ref} list;
|
174
179
|
#{node}* this_node;
|
175
180
|
};
|
176
181
|
struct #{node} {
|
@@ -180,42 +185,43 @@ class List < Collection
|
|
180
185
|
$
|
181
186
|
end
|
182
187
|
|
183
|
-
def
|
188
|
+
def write_intf_decls(stream, declare, define)
|
189
|
+
super
|
184
190
|
stream << %$
|
185
|
-
#{declare}
|
186
|
-
#{declare}
|
187
|
-
#{declare}
|
188
|
-
#{declare}
|
189
|
-
#{declare}
|
190
|
-
#{declare} void #{purge}(#{
|
191
|
-
#{declare} #{element.type} #{peek}(#{
|
192
|
-
#{declare} #{element.type} #{pop}(#{
|
193
|
-
#{declare} void #{push}(#{
|
194
|
-
#{declare} int #{contains}(#{
|
195
|
-
#{declare} #{element.type} #{find}(#{
|
191
|
+
#{declare} #{ctor.declaration};
|
192
|
+
#{declare} #{dtor.declaration};
|
193
|
+
#{declare} #{copy.declaration};
|
194
|
+
#{declare} #{equal.declaration};
|
195
|
+
#{declare} #{identify.declaration};
|
196
|
+
#{declare} void #{purge}(#{type_ref});
|
197
|
+
#{declare} #{element.type} #{peek}(#{type_ref});
|
198
|
+
#{declare} #{element.type} #{pop}(#{type_ref});
|
199
|
+
#{declare} void #{push}(#{type_ref}, #{element.type});
|
200
|
+
#{declare} int #{contains}(#{type_ref}, #{element.type});
|
201
|
+
#{declare} #{element.type} #{find}(#{type_ref}, #{element.type});
|
196
202
|
#define #{replace}(self, with) #{replaceEx}(self, with, 1)
|
197
203
|
#define #{replaceAll}(self, with) #{replaceEx}(self, with, -1)
|
198
|
-
#{declare} int #{replaceEx}(#{
|
204
|
+
#{declare} int #{replaceEx}(#{type_ref}, #{element.type}, int);
|
199
205
|
#define #{remove}(self, what) #{removeEx}(self, what, 1)
|
200
206
|
#define #{removeAll}(self, what) #{removeEx}(self, what, -1)
|
201
|
-
#{declare} int #{removeEx}(#{
|
202
|
-
#{declare} size_t #{size}(#{
|
207
|
+
#{declare} int #{removeEx}(#{type_ref}, #{element.type}, int);
|
208
|
+
#{declare} size_t #{size}(#{type_ref});
|
203
209
|
#define #{empty}(self) (#{size}(self) == 0)
|
204
|
-
#{declare} void #{itCtor}(#{
|
205
|
-
#{declare} int #{itMove}(#{
|
206
|
-
#{declare} #{element.type} #{itGet}(#{
|
210
|
+
#{declare} void #{itCtor}(#{it_ref}, #{type_ref});
|
211
|
+
#{declare} int #{itMove}(#{it_ref});
|
212
|
+
#{declare} #{element.type} #{itGet}(#{it_ref});
|
207
213
|
$
|
208
214
|
end
|
209
215
|
|
210
|
-
def
|
216
|
+
def write_impls(stream, define)
|
211
217
|
stream << %$
|
212
|
-
#{define} #{element.
|
213
|
-
#{define}
|
218
|
+
#{define} #{element.type_ref} #{itGetRef}(#{it_ref});
|
219
|
+
#{define} #{ctor.definition} {
|
214
220
|
#{assert}(self);
|
215
221
|
self->head_node = NULL;
|
216
222
|
self->node_count = 0;
|
217
223
|
}
|
218
|
-
#{define}
|
224
|
+
#{define} #{dtor.definition} {
|
219
225
|
#{node}* node;
|
220
226
|
#{assert}(self);
|
221
227
|
node = self->head_node;
|
@@ -226,7 +232,7 @@ class List < Collection
|
|
226
232
|
#{free}(this_node);
|
227
233
|
}
|
228
234
|
}
|
229
|
-
#{define}
|
235
|
+
#{define} #{copy.definition} {
|
230
236
|
#{it} it;
|
231
237
|
#{assert}(src);
|
232
238
|
#{assert}(dst);
|
@@ -236,14 +242,15 @@ class List < Collection
|
|
236
242
|
#{push}(dst, *#{itGetRef}(&it));
|
237
243
|
}
|
238
244
|
}
|
239
|
-
#{define}
|
245
|
+
#{define} #{equal.definition} {
|
240
246
|
if(#{size}(lt) == #{size}(rt)) {
|
241
247
|
#{it} lit, rit;
|
242
248
|
#{itCtor}(&lit, lt);
|
243
249
|
#{itCtor}(&rit, rt);
|
244
250
|
while(#{itMove}(&lit) && #{itMove}(&rit)) {
|
245
251
|
int equal;
|
246
|
-
#{element.
|
252
|
+
#{element.type_ref} le;
|
253
|
+
#{element.type_ref} re;
|
247
254
|
le = #{itGetRef}(&lit);
|
248
255
|
re = #{itGetRef}(&rit);
|
249
256
|
equal = #{element.equal("*le", "*re")};
|
@@ -253,7 +260,7 @@ class List < Collection
|
|
253
260
|
} else
|
254
261
|
return 0;
|
255
262
|
}
|
256
|
-
#{define}
|
263
|
+
#{define} #{identify.definition} {
|
257
264
|
#{node}* node;
|
258
265
|
size_t result = 0;
|
259
266
|
#{assert}(self);
|
@@ -263,18 +270,18 @@ class List < Collection
|
|
263
270
|
}
|
264
271
|
return result;
|
265
272
|
}
|
266
|
-
#{define} void #{purge}(#{
|
273
|
+
#{define} void #{purge}(#{type_ref} self) {
|
267
274
|
#{dtor}(self);
|
268
275
|
#{ctor}(self);
|
269
276
|
}
|
270
|
-
#{define} #{element.type} #{peek}(#{
|
277
|
+
#{define} #{element.type} #{peek}(#{type_ref} self) {
|
271
278
|
#{element.type} result;
|
272
279
|
#{assert}(self);
|
273
280
|
#{assert}(!#{empty}(self));
|
274
281
|
#{element.copy("result", "self->head_node->element")};
|
275
282
|
return result;
|
276
283
|
}
|
277
|
-
#{define} #{element.type} #{pop}(#{
|
284
|
+
#{define} #{element.type} #{pop}(#{type_ref} self) {
|
278
285
|
#{node}* node;
|
279
286
|
#{element.type} result;
|
280
287
|
#{assert}(self);
|
@@ -286,7 +293,7 @@ class List < Collection
|
|
286
293
|
#{free}(node);
|
287
294
|
return result;
|
288
295
|
}
|
289
|
-
#{define} void #{push}(#{
|
296
|
+
#{define} void #{push}(#{type_ref} self, #{element.type} element) {
|
290
297
|
#{node}* node;
|
291
298
|
#{assert}(self);
|
292
299
|
node = (#{node}*)#{malloc}(sizeof(#{node})); #{assert}(node);
|
@@ -295,7 +302,7 @@ class List < Collection
|
|
295
302
|
self->head_node = node;
|
296
303
|
++self->node_count;
|
297
304
|
}
|
298
|
-
#{define} int #{contains}(#{
|
305
|
+
#{define} int #{contains}(#{type_ref} self, #{element.type} what) {
|
299
306
|
#{node}* node;
|
300
307
|
int found = 0;
|
301
308
|
#{assert}(self);
|
@@ -309,7 +316,7 @@ class List < Collection
|
|
309
316
|
}
|
310
317
|
return found;
|
311
318
|
}
|
312
|
-
#{define} #{element.type} #{find}(#{
|
319
|
+
#{define} #{element.type} #{find}(#{type_ref} self, #{element.type} what) {
|
313
320
|
#{node}* node;
|
314
321
|
#{assert}(self);
|
315
322
|
#{assert}(#{contains}(self, what));
|
@@ -324,7 +331,7 @@ class List < Collection
|
|
324
331
|
}
|
325
332
|
#{abort}();
|
326
333
|
}
|
327
|
-
#{define} int #{replaceEx}(#{
|
334
|
+
#{define} int #{replaceEx}(#{type_ref} self, #{element.type} with, int count) {
|
328
335
|
#{node}* node;
|
329
336
|
int replaced = 0;
|
330
337
|
#{assert}(self);
|
@@ -341,7 +348,7 @@ class List < Collection
|
|
341
348
|
}
|
342
349
|
return replaced;
|
343
350
|
}
|
344
|
-
#{define} int #{removeEx}(#{
|
351
|
+
#{define} int #{removeEx}(#{type_ref} self, #{element.type} what, int count) {
|
345
352
|
#{node} *node, *prev_node;
|
346
353
|
int removed = 0;
|
347
354
|
#{assert}(self);
|
@@ -369,17 +376,17 @@ class List < Collection
|
|
369
376
|
}
|
370
377
|
return removed;
|
371
378
|
}
|
372
|
-
#{define} size_t #{size}(#{
|
379
|
+
#{define} size_t #{size}(#{type_ref} self) {
|
373
380
|
#{assert}(self);
|
374
381
|
return self->node_count;
|
375
382
|
}
|
376
|
-
#{define} void #{itCtor}(#{
|
383
|
+
#{define} void #{itCtor}(#{it_ref} self, #{type_ref} list) {
|
377
384
|
#{assert}(self);
|
378
385
|
#{assert}(list);
|
379
386
|
self->start = 1;
|
380
387
|
self->list = list;
|
381
388
|
}
|
382
|
-
#{define} int #{itMove}(#{
|
389
|
+
#{define} int #{itMove}(#{it_ref} self) {
|
383
390
|
#{assert}(self);
|
384
391
|
if(self->start) {
|
385
392
|
self->this_node = self->list->head_node;
|
@@ -389,14 +396,14 @@ class List < Collection
|
|
389
396
|
}
|
390
397
|
return self->this_node != NULL;
|
391
398
|
}
|
392
|
-
#{define} #{element.type} #{itGet}(#{
|
399
|
+
#{define} #{element.type} #{itGet}(#{it_ref} self) {
|
393
400
|
#{element.type} result;
|
394
401
|
#{assert}(self);
|
395
402
|
#{assert}(self->this_node);
|
396
403
|
#{element.copy("result", "self->this_node->element")};
|
397
404
|
return result;
|
398
405
|
}
|
399
|
-
#{define} #{element.
|
406
|
+
#{define} #{element.type_ref} #{itGetRef}(#{it_ref} self) {
|
400
407
|
#{assert}(self);
|
401
408
|
#{assert}(self->this_node);
|
402
409
|
return &self->this_node->element;
|