From 7f4b96fe11fe1f6171adb8fa2b71f24522e849d2 Mon Sep 17 00:00:00 2001 From: Matthias Hochsteger Date: Mon, 2 Dec 2019 17:05:50 +0100 Subject: [PATCH] Fix ctor with LocalHeap in ClosedHashTable Set mask, round up size to next power of 2 --- libsrc/core/hashtable.hpp | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/libsrc/core/hashtable.hpp b/libsrc/core/hashtable.hpp index 36fb9f77..72cb73db 100644 --- a/libsrc/core/hashtable.hpp +++ b/libsrc/core/hashtable.hpp @@ -582,38 +582,28 @@ namespace ngcore size_t size; size_t mask; /// - size_t used; + size_t used = 0; /// Array hash; /// Array 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 _hash, FlatArray _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); }