Fix ctor with LocalHeap in ClosedHashTable

Set mask, round up size to next power of 2
This commit is contained in:
Matthias Hochsteger 2019-12-02 17:05:50 +01:00
parent 3ebe0649f2
commit 7f4b96fe11

View File

@ -582,38 +582,28 @@ namespace ngcore
size_t size;
size_t mask;
///
size_t used;
size_t used = 0;
///
Array<T_HASH> hash;
///
Array<T> cont;
///
T_HASH invalid;
T_HASH invalid = -1;
public:
///
ClosedHashTable (size_t asize = 128)
: size(RoundUp2(asize)), used(0), hash(size), cont(size)
: size(RoundUp2(asize)), hash(size), cont(size)
{
mask = size-1;
invalid = -1;
hash = T_HASH(invalid);
}
ClosedHashTable (ClosedHashTable && ht2) = default;
// who needs that ?
ClosedHashTable (FlatArray<T_HASH> _hash, FlatArray<T> _cont)
: size(_hash.Size()), used(0), hash(_hash.Size(), _hash.Addr(0)), cont(_cont.Size(), _cont.Addr(0))
{
invalid = -1;
hash = T_HASH(invalid);
}
/// allocate on local heap
ClosedHashTable (size_t asize, LocalHeap & lh)
: size(asize), hash(asize, lh), cont(asize, lh)
: size(RoundUp2(asize)), mask(size-1), hash(size, lh), cont(size, lh)
{
invalid = -1;
hash = T_HASH(invalid);
}