From: Brian Norris Date: Sat, 11 Aug 2012 00:44:36 +0000 (-0700) Subject: hashtable: bugfix - increment size only when new bins are linked X-Git-Url: http://plrg.eecs.uci.edu/git/?p=c11tester.git;a=commitdiff_plain;h=18e9e9e8f1bc9c12049520498e06e24d25d8d72d hashtable: bugfix - increment size only when new bins are linked In both put() and ensureptr(), the 'size' counter should not be incremented until we decide if we're adding a new bin or not. When incremented improperly, 'size' ended up out of sync with the hash table; it reported a size much larger than the actual table. --- diff --git a/hashtable.h b/hashtable.h index 84baaba1..2b703c59 100644 --- a/hashtable.h +++ b/hashtable.h @@ -134,7 +134,6 @@ template *ptr = table[(((_KeyInt)key) & mask)>>_Shift]; - size++; struct hashlistnode<_Key,_Val, _malloc, _calloc, _free> *search = ptr; while(search!=NULL) { @@ -150,6 +149,7 @@ templateval=val; newptr->next=ptr; table[(((_KeyInt)key)&mask)>>_Shift]=newptr; + size++; } /** Put a key entry into the table. */ @@ -158,7 +158,6 @@ template *ptr = table[(((_KeyInt)key) & mask)>>_Shift]; - size++; struct hashlistnode<_Key,_Val, _malloc, _calloc, _free> *search = ptr; while(search!=NULL) { @@ -172,6 +171,7 @@ templatekey=key; newptr->next=ptr; table[(((_KeyInt)key)&mask)>>_Shift]=newptr; + size++; return &newptr->val; }