From: Brian Norris Date: Tue, 16 Apr 2013 16:49:01 +0000 (-0700) Subject: hashtable: enforce, document non-zero keys X-Git-Tag: oopsla2013~53 X-Git-Url: http://demsky.eecs.uci.edu/git/?p=model-checker.git;a=commitdiff_plain;h=896f385f6690cfbe51ea1c07d7361a01914e9f9f hashtable: enforce, document non-zero keys HashTable does not support a key of "zero." ... --- diff --git a/hashtable.h b/hashtable.h index c09b3ff..71b05ce 100644 --- a/hashtable.h +++ b/hashtable.h @@ -37,7 +37,8 @@ struct hashlistnode { * @brief A simple, custom hash table * * By default it is snapshotting, but you can pass in your own allocation - * functions. + * functions. Note that this table does not support 0 (NULL) keys and is + * designed primarily with pointer-based keys in mind. * * @tparam _Key Type name for the key * @tparam _Val Type name for the values to be stored @@ -105,6 +106,9 @@ template threshold) resize(capacity << 1); @@ -130,6 +134,9 @@ template *search; + /* HashTable cannot handle 0 as a key */ + ASSERT(key); + unsigned int index = ((_KeyInt)key) >> _Shift; do { index &= capacitymask; @@ -145,6 +152,9 @@ template *search; + /* HashTable cannot handle 0 as a key */ + ASSERT(key); + unsigned int index = ((_KeyInt)key) >> _Shift; do { index &= capacitymask;