summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBill Wendling <wendling@ncsa.uiuc.edu>2000-05-08 22:29:07 (GMT)
committerBill Wendling <wendling@ncsa.uiuc.edu>2000-05-08 22:29:07 (GMT)
commit96c529af87fced0de58b3d9e09ae1fc376cba73d (patch)
tree508515669984cd0795261f8309d7241c220b9846 /src
parentdca5c02b3140197e1f7a5ebbd177875959121739 (diff)
downloadhdf5-96c529af87fced0de58b3d9e09ae1fc376cba73d.zip
hdf5-96c529af87fced0de58b3d9e09ae1fc376cba73d.tar.gz
hdf5-96c529af87fced0de58b3d9e09ae1fc376cba73d.tar.bz2
[svn-r2219] This simplifies the "check for power of 2" in the hashing function. There
was also a subtle bug in the previous code. A valid size of 16K would have been rejected since it was checking for an invalid number. The scheme that replaces it relies on the fact that powers of two and only powers of two have 1 bit set in binary.
Diffstat (limited to 'src')
-rw-r--r--src/H5I.c23
1 files changed, 7 insertions, 16 deletions
diff --git a/src/H5I.c b/src/H5I.c
index a092b24..e8cebb6 100644
--- a/src/H5I.c
+++ b/src/H5I.c
@@ -87,7 +87,8 @@ static herr_t H5I_init_interface(void);
* Map an ID to a hash location (assumes s is a power of 2 and smaller
* than the ID_MASK constant).
*/
-# define H5I_LOC(a,s) ((hid_t)((size_t)(a)&((s)-1)))
+# define H5I_LOC(a,s) ((hid_t)((size_t)(a)&((s)-1)))
+# define POWER_OF_TWO(n) ((((n) - 1) & (n)) == 0 && (n) > 1)
#else
/*
* Map an ID to a hash location.
@@ -219,6 +220,10 @@ H5I_term_interface(void)
* Friday, February 19, 1999
*
* Modifications:
+ * Bill Wendling, 2000-05-05
+ * Instead of the ugly test of whether hash_size is a power of
+ * two, I placed it in a macro POWER_OF_TWO which uses the fact
+ * that a number that is a power of two has only 1 bit set.
*
*-------------------------------------------------------------------------
*/
@@ -236,21 +241,7 @@ H5I_init_group(H5I_type_t grp, size_t hash_size, uintn reserved,
HGOTO_DONE(FAIL);
}
#ifdef HASH_SIZE_POWER_2
- /*
- * If anyone knows a faster test for a power of two, please change this
- * silly code -QAK
- */
- if (!(hash_size == 2 || hash_size == 4 || hash_size == 8 ||
- hash_size == 16 || hash_size == 32 || hash_size == 64 ||
- hash_size == 128 || hash_size == 256 || hash_size == 512 ||
- hash_size == 1024 || hash_size == 2048 || hash_size == 4096 ||
- hash_size == 8192 || hash_size == 16374 || hash_size == 32768 ||
- hash_size == 65536 || hash_size == 131072 || hash_size == 262144 ||
- hash_size == 524288 || hash_size == 1048576 ||
- hash_size == 2097152 || hash_size == 4194304 ||
- hash_size == 8388608 || hash_size == 16777216 ||
- hash_size == 33554432 || hash_size == 67108864 ||
- hash_size == 134217728 || hash_size == 268435456))
+ if (!POWER_OF_TWO(hash_size))
HGOTO_DONE(FAIL);
#endif /* HASH_SIZE_POWER_2 */