HashTable/Set: Add proper assignment

This commit is contained in:
2018-05-20 21:58:15 +02:00
parent 9efbc9d5e0
commit c268696ee9
3 changed files with 61 additions and 19 deletions

View File

@ -194,7 +194,7 @@ if (is(typeof(hasher(Key.init)) == size_t))
do
{
this(allocator);
rehash(n);
this.data.rehash(n);
}
///
@ -265,7 +265,6 @@ if (is(typeof(hasher(Key.init)) == size_t))
if (is(Unqual!S == HashTable))
{
this.data = that.data;
this.data.lengthIndex = that.data.lengthIndex;
return this;
}
@ -604,6 +603,16 @@ if (is(typeof(hasher(Key.init)) == size_t))
assert(hashTable.capacity == 7);
}
// Assigns by reference
@nogc nothrow pure @safe unittest
{
auto hashTable1 = HashTable!(string, int)(7);
HashTable!(string, int) hashTable2;
hashTable1 = hashTable2;
assert(hashTable1.length == hashTable2.length);
assert(hashTable1.capacity == hashTable2.capacity);
}
// Assigns by value
@nogc nothrow pure @safe unittest
{
@ -611,3 +620,14 @@ if (is(typeof(hasher(Key.init)) == size_t))
hashTable = HashTable!(string, int)(7);
assert(hashTable.capacity == 7);
}
// Postblit copies
@nogc nothrow pure @safe unittest
{
auto hashTable = HashTable!(string, int)(7);
void testFunc(HashTable!(string, int) hashTable)
{
assert(hashTable.capacity == 7);
}
testFunc(hashTable);
}