From e32494ed2cfb8353b7ccfab60a89421314ee9068 Mon Sep 17 00:00:00 2001 From: Brian Norris Date: Fri, 10 Aug 2012 17:42:40 -0700 Subject: [PATCH] hashtable: some refactoring, signed-ness Since 'capacity' is unsigned, so should the index that compares with it. The (duplicated) compare/resize code can be a bit shorter and (IMO) easier to read. --- hashtable.h | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/hashtable.h b/hashtable.h index 8427f67..84baaba 100644 --- a/hashtable.h +++ b/hashtable.h @@ -116,7 +116,7 @@ template * bin = table[i]; while(bin!=NULL) { struct hashlistnode<_Key,_Val, _malloc, _calloc, _free> * next=bin->next; @@ -130,11 +130,8 @@ template threshold) { - //Resize - unsigned int newsize = capacity << 1; - resize(newsize); - } + if (size > threshold) + resize(capacity << 1); struct hashlistnode<_Key,_Val, _malloc, _calloc, _free> *ptr = table[(((_KeyInt)key) & mask)>>_Shift]; size++; @@ -157,11 +154,8 @@ template threshold) { - //Resize - unsigned int newsize = capacity << 1; - resize(newsize); - } + if (size > threshold) + resize(capacity << 1); struct hashlistnode<_Key,_Val, _malloc, _calloc, _free> *ptr = table[(((_KeyInt)key) & mask)>>_Shift]; size++; -- 2.34.1