From: Brian Norris Date: Sat, 11 Aug 2012 00:42:40 +0000 (-0700) Subject: hashtable: some refactoring, signed-ness X-Git-Tag: pldi2013~276 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=e32494ed2cfb8353b7ccfab60a89421314ee9068;hp=c7d1fa37dfd38155acd2137fbeb9b7e5703fb3dc;p=model-checker.git 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. --- 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++;