From 3613af3daafe162d66dce847fd0fd50714ce5709 Mon Sep 17 00:00:00 2001 From: q66 Date: Mon, 20 Jul 2015 00:50:31 +0100 Subject: [PATCH] alloc an extra bucket ptr as trailing sentinel value (for later usage) --- ostd/internal/hashtable.hh | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/ostd/internal/hashtable.hh b/ostd/internal/hashtable.hh index 71dd69a..da3d1a3 100644 --- a/ostd/internal/hashtable.hh +++ b/ostd/internal/hashtable.hh @@ -317,8 +317,8 @@ protected: FuncPair(hf, eqf))), p_maxlf(1.0f) { if (!size) return; - p_data.first() = allocator_allocate(get_cpalloc(), size); - memset(p_data.first(), 0, size * sizeof(Chain *)); + p_data.first() = allocator_allocate(get_cpalloc(), size + 1); + memset(p_data.first(), 0, (size + 1) * sizeof(Chain *)); } Hashtable(const Hashtable &ht, const A &alloc): p_size(ht.p_size), @@ -327,8 +327,8 @@ protected: FuncPair(ht.get_hash(), ht.get_eq()))), p_maxlf(ht.p_maxlf) { if (!p_size) return; - p_data.first() = allocator_allocate(get_cpalloc(), p_size); - memset(p_data.first(), 0, p_size * sizeof(Chain *)); + p_data.first() = allocator_allocate(get_cpalloc(), p_size + 1); + memset(p_data.first(), 0, (p_size + 1) * sizeof(Chain *)); Chain **och = ht.p_data.first(); for (Size h = 0; h < p_size; ++h) { Chain *oc = och[h]; @@ -368,8 +368,8 @@ protected: p_len = 0; p_chunks = nullptr; p_unused = nullptr; - p_data.first() = allocator_allocate(get_cpalloc(), p_size); - memset(p_data.first(), 0, p_size * sizeof(Chain *)); + p_data.first() = allocator_allocate(get_cpalloc(), p_size + 1); + memset(p_data.first(), 0, (p_size + 1) * sizeof(Chain *)); Chain **och = ht.p_data.first(); for (Size h = 0; h < p_size; ++h) { Chain *oc = och[h]; @@ -385,10 +385,10 @@ protected: if (AllocatorPropagateOnContainerCopyAssignment::value) { if ((get_cpalloc() != ht.get_cpalloc()) && p_size) { allocator_deallocate(get_cpalloc(), - p_data.first(), p_size); + p_data.first(), p_size + 1); p_data.first() = allocator_allocate(get_cpalloc(), - p_size); - memset(p_data.first(), 0, p_size * sizeof(Chain *)); + p_size + 1); + memset(p_data.first(), 0, (p_size + 1) * sizeof(Chain *)); } get_alloc() = ht.get_alloc(); get_cpalloc() = ht.get_cpalloc(); @@ -437,7 +437,7 @@ protected: public: ~Hashtable() { if (p_size) allocator_deallocate(get_cpalloc(), - p_data.first(), p_size); + p_data.first(), p_size + 1); delete_chunks(p_chunks); } @@ -447,7 +447,7 @@ public: void clear() { if (!p_len) return; - memset(p_data.first(), 0, p_size * sizeof(Chain *)); + memset(p_data.first(), 0, (p_size + 1) * sizeof(Chain *)); p_len = 0; p_unused = nullptr; delete_chunks(p_chunks); @@ -562,8 +562,8 @@ public: if (fbcount > count) count = fbcount; Chain **och = p_data.first(); - Chain **nch = allocator_allocate(get_cpalloc(), count); - memset(nch, 0, count * sizeof(Chain *)); + Chain **nch = allocator_allocate(get_cpalloc(), count + 1); + memset(nch, 0, (count + 1) * sizeof(Chain *)); p_data.first() = nch; Size osize = p_size;