autoc 1.4 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGES.md +3 -0
- data/README.md +149 -0
- data/cmake/AutoC.cmake +39 -0
- data/lib/autoc/allocators.rb +51 -0
- data/lib/autoc/association.rb +126 -0
- data/lib/autoc/box.rb +311 -0
- data/lib/autoc/cmake.rb +54 -0
- data/lib/autoc/collection.rb +83 -110
- data/lib/autoc/composite.rb +333 -0
- data/lib/autoc/cstring.rb +263 -0
- data/lib/autoc/function.rb +247 -0
- data/lib/autoc/hash_map.rb +328 -0
- data/lib/autoc/hash_set.rb +339 -0
- data/lib/autoc/hashers.rb +102 -0
- data/lib/autoc/list.rb +444 -0
- data/lib/autoc/module.rb +434 -0
- data/lib/autoc/openmp.rb +15 -0
- data/lib/autoc/primitive.rb +27 -0
- data/lib/autoc/ranges.rb +707 -0
- data/lib/autoc/record.rb +247 -0
- data/lib/autoc/scaffold/docs.rb +117 -0
- data/lib/autoc/scaffold/generic_value.rb +86 -0
- data/lib/autoc/scaffold/project.rb +75 -0
- data/lib/autoc/scaffold/test_cstring.rb +113 -0
- data/lib/autoc/scaffold/test_cstring_hash_set.rb +35 -0
- data/lib/autoc/scaffold/test_int_box.rb +22 -0
- data/lib/autoc/scaffold/test_int_hash_set.rb +448 -0
- data/lib/autoc/scaffold/test_int_list.rb +106 -0
- data/lib/autoc/scaffold/test_int_vector.rb +83 -0
- data/lib/autoc/scaffold/test_v2v_hash_map.rb +83 -0
- data/lib/autoc/scaffold/test_value_hash_set.rb +60 -0
- data/lib/autoc/scaffold/test_value_vector.rb +146 -0
- data/{test/test.rb → lib/autoc/scaffold/tests.rb} +179 -158
- data/lib/autoc/scaffold.rb +12 -0
- data/lib/autoc/sequential.rb +99 -0
- data/lib/autoc/set.rb +331 -0
- data/lib/autoc/std.rb +149 -0
- data/lib/autoc/type.rb +93 -531
- data/lib/autoc/vector.rb +290 -0
- data/lib/autoc.rb +4 -35
- metadata +55 -85
- data/.yardopts +0 -4
- data/CHANGES +0 -23
- data/README +0 -28
- data/doc/AutoC/Code.html +0 -523
- data/doc/AutoC/Collection.html +0 -1214
- data/doc/AutoC/HashMap.html +0 -1441
- data/doc/AutoC/HashSet.html +0 -916
- data/doc/AutoC/Iterators/Bidirectional.html +0 -204
- data/doc/AutoC/Iterators/Unidirectional.html +0 -200
- data/doc/AutoC/Iterators.html +0 -126
- data/doc/AutoC/List.html +0 -1039
- data/doc/AutoC/Maps.html +0 -290
- data/doc/AutoC/Module/File.html +0 -415
- data/doc/AutoC/Module/Header.html +0 -437
- data/doc/AutoC/Module/Source.html +0 -707
- data/doc/AutoC/Module.html +0 -948
- data/doc/AutoC/Priority.html +0 -138
- data/doc/AutoC/Queue.html +0 -1172
- data/doc/AutoC/Reference.html +0 -735
- data/doc/AutoC/Sets.html +0 -520
- data/doc/AutoC/String.html +0 -1394
- data/doc/AutoC/TreeMap.html +0 -1565
- data/doc/AutoC/TreeSet.html +0 -1447
- data/doc/AutoC/Type.html +0 -2148
- data/doc/AutoC/UserDefinedType.html +0 -1047
- data/doc/AutoC/Vector.html +0 -987
- data/doc/AutoC.html +0 -331
- data/doc/_index.html +0 -388
- data/doc/class_list.html +0 -51
- data/doc/css/common.css +0 -1
- data/doc/css/full_list.css +0 -58
- data/doc/css/style.css +0 -481
- data/doc/file.CHANGES.html +0 -117
- data/doc/file.README.html +0 -116
- data/doc/file_list.html +0 -61
- data/doc/frames.html +0 -17
- data/doc/index.html +0 -116
- data/doc/js/app.js +0 -243
- data/doc/js/full_list.js +0 -216
- data/doc/js/jquery.js +0 -4
- data/doc/method_list.html +0 -1307
- data/doc/top-level-namespace.html +0 -112
- data/lib/autoc/code.rb +0 -237
- data/lib/autoc/collection/hash_map.rb +0 -385
- data/lib/autoc/collection/hash_set.rb +0 -337
- data/lib/autoc/collection/iterator.rb +0 -39
- data/lib/autoc/collection/list.rb +0 -429
- data/lib/autoc/collection/map.rb +0 -41
- data/lib/autoc/collection/queue.rb +0 -517
- data/lib/autoc/collection/set.rb +0 -134
- data/lib/autoc/collection/tree_map.rb +0 -464
- data/lib/autoc/collection/tree_set.rb +0 -611
- data/lib/autoc/collection/vector.rb +0 -336
- data/lib/autoc/string.rb +0 -492
- data/test/test_auto.c +0 -7141
- data/test/test_auto.h +0 -753
- data/test/test_char_string.rb +0 -270
- data/test/test_int_list.rb +0 -35
- data/test/test_int_tree_set.rb +0 -111
- data/test/test_int_vector.rb +0 -34
- data/test/test_value_hash_map.rb +0 -162
- data/test/test_value_hash_set.rb +0 -173
- data/test/test_value_list.rb +0 -193
- data/test/test_value_queue.rb +0 -275
- data/test/test_value_tree_map.rb +0 -176
- data/test/test_value_tree_set.rb +0 -173
- data/test/test_value_vector.rb +0 -155
- data/test/value.rb +0 -80
@@ -1,337 +0,0 @@
|
|
1
|
-
require "autoc/collection"
|
2
|
-
require "autoc/collection/list"
|
3
|
-
|
4
|
-
|
5
|
-
require "autoc/collection/set"
|
6
|
-
require "autoc/collection/iterator"
|
7
|
-
|
8
|
-
|
9
|
-
module AutoC
|
10
|
-
|
11
|
-
|
12
|
-
=begin
|
13
|
-
|
14
|
-
HashSet< *_E_* > is a hash-based unordered container holding unique elements.
|
15
|
-
|
16
|
-
The collection's C++ counterpart is +std::unordered_set<>+ template class.
|
17
|
-
|
18
|
-
== Generated C interface
|
19
|
-
|
20
|
-
=== Collection management
|
21
|
-
|
22
|
-
[cols=2*]
|
23
|
-
|===
|
24
|
-
|*_void_* ~type~Copy(*_Type_* * +dst+, *_Type_* * +src+)
|
25
|
-
|
|
26
|
-
Create a new set +dst+ filled with the contents of +src+.
|
27
|
-
A copy operation is performed on every element in +src+.
|
28
|
-
|
29
|
-
NOTE: Previous contents of +dst+ is overwritten.
|
30
|
-
|
31
|
-
|*_void_* ~type~Ctor(*_Type_* * +self+)
|
32
|
-
|
|
33
|
-
Create a new empty set +self+.
|
34
|
-
|
35
|
-
NOTE: Previous contents of +self+ is overwritten.
|
36
|
-
|
37
|
-
|*_void_* ~type~Dtor(*_Type_* * +self+)
|
38
|
-
|
|
39
|
-
Destroy set +self+.
|
40
|
-
Stored elements are destroyed as well by calling the respective destructors.
|
41
|
-
|
42
|
-
|*_int_* ~type~Equal(*_Type_* * +lt+, *_Type_* * +rt+)
|
43
|
-
|
|
44
|
-
Return non-zero value if sets +lt+ and +rt+ are considered equal by contents and zero value otherwise.
|
45
|
-
|
46
|
-
|*_size_t_* ~type~Identify(*_Type_* * +self+)
|
47
|
-
|
|
48
|
-
Return hash code for set +self+.
|
49
|
-
|===
|
50
|
-
|
51
|
-
=== Basic operations
|
52
|
-
|
53
|
-
[cols=2*]
|
54
|
-
|===
|
55
|
-
|*_int_* ~type~Contains(*_Type_* * +self+, *_E_* +what+)
|
56
|
-
|
|
57
|
-
Return non-zero value if set +self+ contains an element considered equal to the element +what+ and zero value otherwise.
|
58
|
-
|
59
|
-
|*_int_* ~type~Empty(*_Type_* * +self+)
|
60
|
-
|
|
61
|
-
Return non-zero value if set +self+ contains no elements and zero value otherwise.
|
62
|
-
|
63
|
-
|*_E_* ~type~Get(*_Type_* * +self+, *_E_* +what+)
|
64
|
-
|
|
65
|
-
Return a _copy_ of the element in +self+ considered equal to the element +what+.
|
66
|
-
|
67
|
-
WARNING: +self+ *must* contain such element otherwise the behavior is undefined. See ~type~Contains().
|
68
|
-
|
69
|
-
|*_void_* ~type~Purge(*_Type_* * +self+)
|
70
|
-
|
|
71
|
-
Remove and destroy all elements stored in +self+.
|
72
|
-
|
73
|
-
|*_int_* ~type~Put(*_Type_* * +self+, *_E_* +what+)
|
74
|
-
|
|
75
|
-
Put a _copy_ of the element +what+ into +self+ *only if* there is no such element in +self+ which is considered equal to +what+.
|
76
|
-
|
77
|
-
Return non-zero value on successful element put (that is there was not such element in +self+) and zero value otherwise.
|
78
|
-
|
79
|
-
|*_int_* ~type~Replace(*_Type_* * +self+, *_E_* +with+)
|
80
|
-
|
|
81
|
-
If +self+ contains an element which is considered equal to the element +with+,
|
82
|
-
replace that element with a _copy_ of +with+, otherwise do nothing.
|
83
|
-
Replaced element is destroyed.
|
84
|
-
|
85
|
-
Return non-zero value if the replacement was actually performed and zero value otherwise.
|
86
|
-
|
87
|
-
|*_int_* ~type~Remove(*_Type_* * +self+, *_E_* +what+)
|
88
|
-
|
|
89
|
-
Remove and destroy an element in +self+ which is considered equal to the element +what+.
|
90
|
-
|
91
|
-
Return non-zero value on successful element removal and zero value otherwise.
|
92
|
-
|
93
|
-
|*_size_t_* ~type~Size(*_Type_* * +self+)
|
94
|
-
|
|
95
|
-
Return number of elements stored in +self+.
|
96
|
-
|===
|
97
|
-
|
98
|
-
=== Logical operations
|
99
|
-
|
100
|
-
[cols=2*]
|
101
|
-
|===
|
102
|
-
|*_void_* ~type~Exclude(*_Type_* * +self+, *_Type_* * +other+)
|
103
|
-
|
|
104
|
-
Perform the difference operation that is +self+ will retain only the elements not contained in +other+.
|
105
|
-
|
106
|
-
Removed elements are destroyed.
|
107
|
-
|*_void_* ~type~Include(*_Type_* * +self+, *_Type_* * +other+)
|
108
|
-
|
|
109
|
-
Perform the union operation that is +self+ will contain the elements from both +self+ and +other+.
|
110
|
-
|
111
|
-
+self+ receives the _copies_ of extra elements in +other+.
|
112
|
-
|
113
|
-
|*_void_* ~type~Invert(*_Type_* * +self+, *_Type_* * +other+)
|
114
|
-
|
|
115
|
-
Perform the symmetric difference operation that is +self+ will retain the elements contained in either +self+ or +other+, but not in both.
|
116
|
-
|
117
|
-
Removed elements are destroyed, extra elements are _copied_.
|
118
|
-
|
119
|
-
|*_void_* ~type~Retain(*_Type_* * +self+, *_Type_* * +other+)
|
120
|
-
|
|
121
|
-
Perform the intersection operation that is +self+ will retain only the elements contained in both +self+ and +other+.
|
122
|
-
|
123
|
-
Removed elements are destroyed.
|
124
|
-
|===
|
125
|
-
|
126
|
-
=== Iteration
|
127
|
-
|
128
|
-
[cols=2*]
|
129
|
-
|===
|
130
|
-
|*_void_* ~it~Ctor(*_IteratorType_* * +it+, *_Type_* * +self+)
|
131
|
-
|
|
132
|
-
Create a new iterator +it+ on set +self+.
|
133
|
-
|
134
|
-
NOTE: As the set is an unordered sequence, the traversal order is unspecified.
|
135
|
-
|
136
|
-
NOTE: Previous contents of +it+ is overwritten.
|
137
|
-
|
138
|
-
|*_int_* ~it~Move(*_IteratorType_* * +it+)
|
139
|
-
|
|
140
|
-
Advance iterator position of +it+ *and* return non-zero value if new position is valid and zero value otherwise.
|
141
|
-
|
142
|
-
|*_E_* ~it~Get(*_IteratorType_* * +it+)
|
143
|
-
|
|
144
|
-
Return a _copy_ of current element pointed to by the iterator +it+.
|
145
|
-
|
146
|
-
WARNING: current position *must* be valid otherwise the behavior is undefined. See ~it~Move().
|
147
|
-
|===
|
148
|
-
|
149
|
-
=end
|
150
|
-
class HashSet < Collection
|
151
|
-
|
152
|
-
include Sets
|
153
|
-
include Iterators::Unidirectional
|
154
|
-
|
155
|
-
def initialize(*args)
|
156
|
-
super
|
157
|
-
@list = List.new(list, element, :static)
|
158
|
-
key_requirement(element)
|
159
|
-
end
|
160
|
-
|
161
|
-
def write_intf_decls(stream, declare, define)
|
162
|
-
super
|
163
|
-
end
|
164
|
-
|
165
|
-
def write_intf_types(stream)
|
166
|
-
super
|
167
|
-
@list.write_intf_types(stream)
|
168
|
-
stream << %$
|
169
|
-
typedef struct #{type} #{type};
|
170
|
-
typedef struct #{it} #{it};
|
171
|
-
struct #{type} {
|
172
|
-
#{@list.type_ref} buckets;
|
173
|
-
size_t bucket_count, min_bucket_count;
|
174
|
-
size_t size, min_size, max_size;
|
175
|
-
unsigned min_fill, max_fill, capacity_multiplier; /* ?*1e-2 */
|
176
|
-
};
|
177
|
-
struct #{it} {
|
178
|
-
#{type_ref} set;
|
179
|
-
size_t bucket_index;
|
180
|
-
#{@list.it} it;
|
181
|
-
};
|
182
|
-
$
|
183
|
-
end
|
184
|
-
|
185
|
-
def write_impls(stream, define)
|
186
|
-
@list.write_intf_decls(stream, static, inline)
|
187
|
-
@list.write_impls(stream, static)
|
188
|
-
super
|
189
|
-
stream << %$
|
190
|
-
static void #{rehash}(#{type_ref} self) {
|
191
|
-
#{@list.type_ref} buckets;
|
192
|
-
size_t index, bucket_count, size, fill;
|
193
|
-
#{assert}(self);
|
194
|
-
#{assert}(self->min_fill > 0);
|
195
|
-
#{assert}(self->max_fill > 0);
|
196
|
-
#{assert}(self->min_fill < self->max_fill);
|
197
|
-
#{assert}(self->min_bucket_count > 0);
|
198
|
-
if(self->buckets) {
|
199
|
-
if(self->min_size < self->size && self->size < self->max_size) return;
|
200
|
-
fill = (size_t)((float)self->size/self->bucket_count*100);
|
201
|
-
if(fill > self->max_fill) {
|
202
|
-
bucket_count = (size_t)((float)self->bucket_count/100*self->capacity_multiplier);
|
203
|
-
} else
|
204
|
-
if(fill < self->min_fill && self->bucket_count > self->min_bucket_count) {
|
205
|
-
bucket_count = (size_t)((float)self->bucket_count/self->capacity_multiplier*100);
|
206
|
-
if(bucket_count < self->min_bucket_count) bucket_count = self->min_bucket_count;
|
207
|
-
} else
|
208
|
-
return;
|
209
|
-
size = self->size;
|
210
|
-
self->min_size = (size_t)((float)self->min_fill/100*size);
|
211
|
-
self->max_size = (size_t)((float)self->max_fill/100*size);
|
212
|
-
} else {
|
213
|
-
bucket_count = self->min_bucket_count;
|
214
|
-
size = 0;
|
215
|
-
}
|
216
|
-
buckets = (#{@list.type_ref})#{malloc}(bucket_count*sizeof(#{@list.type})); #{assert}(buckets);
|
217
|
-
for(index = 0; index < bucket_count; ++index) {
|
218
|
-
#{@list.ctor}(&buckets[index]);
|
219
|
-
}
|
220
|
-
if(self->buckets) {
|
221
|
-
#{it} it;
|
222
|
-
#{itCtor}(&it, self);
|
223
|
-
while(#{itMove}(&it)) {
|
224
|
-
#{@list.type}* bucket;
|
225
|
-
#{element.type} element = #{itGet}(&it);
|
226
|
-
bucket = &buckets[#{element.identify("element")} % bucket_count];
|
227
|
-
#{@list.push}(bucket, element);
|
228
|
-
#{element.dtor("element")};
|
229
|
-
}
|
230
|
-
#{dtor}(self);
|
231
|
-
}
|
232
|
-
self->buckets = buckets;
|
233
|
-
self->bucket_count = bucket_count;
|
234
|
-
self->size = size;
|
235
|
-
}
|
236
|
-
#{define} #{ctor.definition} {
|
237
|
-
#{assert}(self);
|
238
|
-
self->min_bucket_count = 16;
|
239
|
-
self->min_fill = 20;
|
240
|
-
self->max_fill = 80;
|
241
|
-
self->min_size = (size_t)((float)self->min_fill/100*self->min_bucket_count);
|
242
|
-
self->max_size = (size_t)((float)self->max_fill/100*self->min_bucket_count);
|
243
|
-
self->capacity_multiplier = 200;
|
244
|
-
self->buckets = NULL;
|
245
|
-
#{rehash}(self);
|
246
|
-
}
|
247
|
-
#{define} #{dtor.definition} {
|
248
|
-
size_t i;
|
249
|
-
#{assert}(self);
|
250
|
-
for(i = 0; i < self->bucket_count; ++i) {
|
251
|
-
#{@list.dtor}(&self->buckets[i]);
|
252
|
-
}
|
253
|
-
#{free}(self->buckets);
|
254
|
-
}
|
255
|
-
#{define} void #{purge}(#{type_ref} self) {
|
256
|
-
#{assert}(self);
|
257
|
-
#{dtor}(self);
|
258
|
-
self->buckets = NULL;
|
259
|
-
#{rehash}(self);
|
260
|
-
}
|
261
|
-
#{define} int #{contains}(#{type_ref} self, #{element.type} element) {
|
262
|
-
#{assert}(self);
|
263
|
-
return #{@list.contains}(&self->buckets[#{element.identify("element")} % self->bucket_count], element);
|
264
|
-
}
|
265
|
-
#{define} #{element.type} #{get}(#{type_ref} self, #{element.type} element) {
|
266
|
-
#{element.type} result;
|
267
|
-
#{assert}(self);
|
268
|
-
#{assert}(#{contains}(self, element));
|
269
|
-
result = #{@list.find}(&self->buckets[#{element.identify("element")} % self->bucket_count], element);
|
270
|
-
return result;
|
271
|
-
}
|
272
|
-
#{define} int #{put}(#{type_ref} self, #{element.type} element) {
|
273
|
-
#{@list.type_ref} bucket;
|
274
|
-
#{assert}(self);
|
275
|
-
bucket = &self->buckets[#{element.identify("element")} % self->bucket_count];
|
276
|
-
if(!#{@list.contains}(bucket, element)) {
|
277
|
-
#{@list.push}(bucket, element);
|
278
|
-
++self->size;
|
279
|
-
#{rehash}(self);
|
280
|
-
return 1;
|
281
|
-
}
|
282
|
-
return 0;
|
283
|
-
}
|
284
|
-
#{define} int #{replace}(#{type_ref} self, #{element.type} element) {
|
285
|
-
#{@list.type_ref} bucket;
|
286
|
-
#{assert}(self);
|
287
|
-
bucket = &self->buckets[#{element.identify("element")} % self->bucket_count];
|
288
|
-
return #{@list.replace}(bucket, element);
|
289
|
-
}
|
290
|
-
#{define} int #{remove}(#{type_ref} self, #{element.type} element) {
|
291
|
-
#{@list.type_ref} bucket;
|
292
|
-
#{assert}(self);
|
293
|
-
bucket = &self->buckets[#{element.identify("element")} % self->bucket_count];
|
294
|
-
if(#{@list.remove}(bucket, element)) {
|
295
|
-
--self->size;
|
296
|
-
#{rehash}(self);
|
297
|
-
return 1;
|
298
|
-
}
|
299
|
-
return 0;
|
300
|
-
}
|
301
|
-
#{define} void #{itCtor}(#{it_ref} self, #{type_ref} set) {
|
302
|
-
#{assert}(self);
|
303
|
-
self->set = set;
|
304
|
-
self->bucket_index = self->set->bucket_count;
|
305
|
-
}
|
306
|
-
#{define} int #{itMove}(#{it_ref} self) {
|
307
|
-
#{assert}(self);
|
308
|
-
if(self->bucket_index >= self->set->bucket_count) #{@list.itCtor}(&self->it, &self->set->buckets[self->bucket_index = 0]);
|
309
|
-
if(#{@list.itMove}(&self->it)) return 1;
|
310
|
-
while(++self->bucket_index < self->set->bucket_count) {
|
311
|
-
#{@list.itCtor}(&self->it, &self->set->buckets[self->bucket_index]);
|
312
|
-
if(#{@list.itMove}(&self->it)) return 1;
|
313
|
-
}
|
314
|
-
return 0;
|
315
|
-
}
|
316
|
-
#{define} #{element.type} #{itGet}(#{it_ref} self) {
|
317
|
-
#{assert}(self);
|
318
|
-
return #{@list.itGet}(&self->it);
|
319
|
-
}
|
320
|
-
static #{element.type_ref} #{itGetRef}(#{it_ref} self) {
|
321
|
-
#{assert}(self);
|
322
|
-
return #{@list.itGetRef}(&self->it);
|
323
|
-
}
|
324
|
-
$
|
325
|
-
end
|
326
|
-
|
327
|
-
private
|
328
|
-
|
329
|
-
def key_requirement(obj)
|
330
|
-
element_requirement(obj)
|
331
|
-
raise "type #{obj.type} (#{obj}) must be hashable" unless obj.hashable?
|
332
|
-
end
|
333
|
-
|
334
|
-
end # HashSet
|
335
|
-
|
336
|
-
|
337
|
-
end # AutoC
|
@@ -1,39 +0,0 @@
|
|
1
|
-
module AutoC
|
2
|
-
|
3
|
-
|
4
|
-
# :nodoc:
|
5
|
-
module Iterators
|
6
|
-
|
7
|
-
|
8
|
-
# :nodoc:
|
9
|
-
module Unidirectional
|
10
|
-
def write_intf_decls(stream, declare, define)
|
11
|
-
super
|
12
|
-
stream << %$
|
13
|
-
#{declare} void #{itCtor}(#{it_ref}, #{type_ref});
|
14
|
-
#{declare} int #{itMove}(#{it_ref});
|
15
|
-
#{declare} #{element.type} #{itGet}(#{it_ref});
|
16
|
-
$
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
|
21
|
-
# :nodoc:
|
22
|
-
module Bidirectional
|
23
|
-
def write_intf_decls(stream, declare, define)
|
24
|
-
super
|
25
|
-
stream << %$
|
26
|
-
#{declare} void #{itCtor}(#{it_ref}, #{type_ref});
|
27
|
-
#define #{itCtor}(self, type) #{itCtorEx}(self, type, 1)
|
28
|
-
#{declare} void #{itCtorEx}(#{it_ref}, #{type_ref}, int);
|
29
|
-
#{declare} int #{itMove}(#{it_ref});
|
30
|
-
#{declare} #{element.type} #{itGet}(#{it_ref});
|
31
|
-
$
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
|
36
|
-
end # Iterators
|
37
|
-
|
38
|
-
|
39
|
-
end # AutoC
|