lib/autoc/collection/hash_set.rb in autoc-1.2 vs lib/autoc/collection/hash_set.rb in autoc-1.3
- old
+ new
@@ -68,15 +68,15 @@
|*_int_* ~type~Put(*_Type_* * +self+, *_E_* +what+)
|
Put a _copy_ of the element +what+ into +self+ *only if* there is no such element in +self+ which is considered equal to +what+.
-Return non-zero value on successful element put and zero value otherwise.
+Return non-zero value on successful element put (that is there was not such element in +self+) and zero value otherwise.
|*_int_* ~type~Replace(*_Type_* * +self+, *_E_* +with+)
|
-*If* +self+ contains an element which is considered equal to the element +with+,
+If +self+ contains an element which is considered equal to the element +with+,
replace that element with a _copy_ of +with+, otherwise do nothing.
Replaced element is destroyed.
Return non-zero value if the replacement was actually performed and zero value otherwise.
@@ -146,15 +146,15 @@
class HashSet < Collection
def initialize(*args)
super
@list = List.new(list, element, :static)
- @capability.subtract [:orderable]
- key_type_check(element)
+ key_requirement(element)
end
def write_intf_types(stream)
+ super
stream << %$
/***
**** #{type}<#{element.type}> (#{self.class})
***/
$ if public?
@@ -168,11 +168,11 @@
size_t size, min_size, max_size;
unsigned min_fill, max_fill, capacity_multiplier; /* ?*1e-2 */
};
struct #{it} {
#{type_ref} set;
- int bucket_index;
+ size_t bucket_index;
#{@list.it} it;
};
$
end
@@ -201,14 +201,15 @@
#{declare} #{element.type} #{itGet}(#{it_ref});
$
end
def write_impls(stream, define)
+ super
@list.write_intf_decls(stream, static, inline)
@list.write_impls(stream, static)
stream << %$
- #{define} #{element.type_ref} #{itGetRef}(#{it_ref});
+ static #{element.type_ref} #{itGetRef}(#{it_ref});
static void #{rehash}(#{type_ref} self) {
#{@list.type_ref} buckets;
size_t index, bucket_count, size, fill;
#{assert}(self);
#{assert}(self->min_fill > 0);
@@ -405,15 +406,15 @@
*self = set;
}
#{define} void #{itCtor}(#{it_ref} self, #{type_ref} set) {
#{assert}(self);
self->set = set;
- self->bucket_index = -1;
+ self->bucket_index = self->set->bucket_count;
}
#{define} int #{itMove}(#{it_ref} self) {
#{assert}(self);
- if(self->bucket_index < 0) #{@list.itCtor}(&self->it, &self->set->buckets[self->bucket_index = 0]);
+ if(self->bucket_index >= self->set->bucket_count) #{@list.itCtor}(&self->it, &self->set->buckets[self->bucket_index = 0]);
if(#{@list.itMove}(&self->it)) return 1;
while(++self->bucket_index < self->set->bucket_count) {
#{@list.itCtor}(&self->it, &self->set->buckets[self->bucket_index]);
if(#{@list.itMove}(&self->it)) return 1;
}
@@ -421,21 +422,21 @@
}
#{define} #{element.type} #{itGet}(#{it_ref} self) {
#{assert}(self);
return #{@list.itGet}(&self->it);
}
- #{define} #{element.type_ref} #{itGetRef}(#{it_ref} self) {
+ static #{element.type_ref} #{itGetRef}(#{it_ref} self) {
#{assert}(self);
return #{@list.itGetRef}(&self->it);
}
$
end
private
- def key_type_check(obj)
+ def key_requirement(obj)
+ element_requirement(obj)
raise "type #{obj.type} (#{obj}) must be hashable" unless obj.hashable?
- element_type_check(obj)
end
end # HashSet
\ No newline at end of file