|
|
@@ -7,6 +7,11 @@ namespace Invercargill.DataStructures {
|
|
|
private class HashSetItem<T> {
|
|
|
public uint hash;
|
|
|
public T item;
|
|
|
+
|
|
|
+ public HashSetItem(owned T item, uint hash) {
|
|
|
+ this.item = (owned)item;
|
|
|
+ this.hash = hash;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private HashSetItem<T>* tombstone;
|
|
|
@@ -28,7 +33,7 @@ namespace Invercargill.DataStructures {
|
|
|
}
|
|
|
|
|
|
private void setup(HashDelegate<T>? value_hash_func = null, EqualityDelegate<T>? value_equal_func = null) {
|
|
|
- tombstone = new HashSetItem<T>();
|
|
|
+ tombstone = new HashSetItem<T>(null, 0);
|
|
|
hash_func = value_hash_func ?? Operators.hash<T>();
|
|
|
equal_func = value_equal_func ?? Operators.equality<T>();
|
|
|
safe_read = get_safe_read_function_for<T>();
|
|
|
@@ -120,9 +125,7 @@ namespace Invercargill.DataStructures {
|
|
|
bucket = buckets[bucket_index];
|
|
|
}
|
|
|
|
|
|
- HashSetItem<T>* new_bucket = new HashSetItem<T>();
|
|
|
- new_bucket->hash = bucket_hash;
|
|
|
- new_bucket->item = (owned)item;
|
|
|
+ HashSetItem<T>* new_bucket = new HashSetItem<T>((owned) item, bucket_hash);
|
|
|
buckets[bucket_index] = new_bucket;
|
|
|
n_items++;
|
|
|
return true;
|
|
|
@@ -174,6 +177,7 @@ namespace Invercargill.DataStructures {
|
|
|
if(buckets[bucket_index] != tombstone) {
|
|
|
var ours = buckets[bucket_index]->item;
|
|
|
if(equal_func(ours, item)) {
|
|
|
+ buckets[bucket_index]->item = null;
|
|
|
delete buckets[bucket_index];
|
|
|
buckets[bucket_index] = tombstone;
|
|
|
n_items--;
|
|
|
@@ -195,8 +199,10 @@ namespace Invercargill.DataStructures {
|
|
|
|
|
|
private void delete_items() {
|
|
|
for(uint i = 0; i < buckets.length; i++) {
|
|
|
- if(buckets[i] != null && buckets[i] != tombstone)
|
|
|
- delete buckets[i];
|
|
|
+ if(buckets[i] != null && buckets[i] != tombstone) {
|
|
|
+ buckets[i]->item = null;
|
|
|
+ delete buckets[i];
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|