Commit ee0e2745 authored by Thomas Munro's avatar Thomas Munro

Code review for simplehash.h.

Fix reference to non-existent file in comment.

Add SH_ prefix to the EMPTY and IN_USE tokens, to reduce likelihood of
collisions with unrelated macros.

Add include guards around the function definitions that are not
"parameterized", so the header can be used again in the same translation
unit.

Undefine SH_EQUAL macro where other "parameter" macros are undefined, for
the same reason.

Author: Thomas Munro
Reviewed-by: Tom Lane
Discussion: https://postgr.es/m/CAEepm%3D1LdXZ3mMTM8tHt_b%3DK1kREit%3Dp8sikesak%3DkzHHM07Nw%40mail.gmail.com
parent 7a3b7bbf
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
* - SH_STORE_HASH - if defined the hash is stored in the elements * - SH_STORE_HASH - if defined the hash is stored in the elements
* - SH_GET_HASH(tb, a) - return the field to store the hash in * - SH_GET_HASH(tb, a) - return the field to store the hash in
* *
* For examples of usage look at simplehash.c (file local definition) and * For examples of usage look at tidbitmap.c (file local definition) and
* execnodes.h/execGrouping.c (exposed declaration, file local * execnodes.h/execGrouping.c (exposed declaration, file local
* implementation). * implementation).
* *
...@@ -65,8 +65,8 @@ ...@@ -65,8 +65,8 @@
/* type declarations */ /* type declarations */
#define SH_TYPE SH_MAKE_NAME(hash) #define SH_TYPE SH_MAKE_NAME(hash)
#define SH_STATUS SH_MAKE_NAME(status) #define SH_STATUS SH_MAKE_NAME(status)
#define SH_STATUS_EMPTY SH_MAKE_NAME(EMPTY) #define SH_STATUS_EMPTY SH_MAKE_NAME(SH_EMPTY)
#define SH_STATUS_IN_USE SH_MAKE_NAME(IN_USE) #define SH_STATUS_IN_USE SH_MAKE_NAME(SH_IN_USE)
#define SH_ITERATOR SH_MAKE_NAME(iterator) #define SH_ITERATOR SH_MAKE_NAME(iterator)
/* function declarations */ /* function declarations */
...@@ -185,6 +185,16 @@ SH_SCOPE void SH_STAT(SH_TYPE * tb); ...@@ -185,6 +185,16 @@ SH_SCOPE void SH_STAT(SH_TYPE * tb);
#define SH_COMPARE_KEYS(tb, ahash, akey, b) (SH_EQUAL(tb, b->SH_KEY, akey)) #define SH_COMPARE_KEYS(tb, ahash, akey, b) (SH_EQUAL(tb, b->SH_KEY, akey))
#endif #endif
/*
* Wrap the following definitions in include guards, to avoid multiple
* definition errors if this header is included more than once. The rest of
* the file deliberately has no include guards, because it can be included
* with different parameters to define functions and types with non-colliding
* names.
*/
#ifndef SIMPLEHASH_H
#define SIMPLEHASH_H
/* FIXME: can we move these to a central location? */ /* FIXME: can we move these to a central location? */
/* calculate ceil(log base 2) of num */ /* calculate ceil(log base 2) of num */
...@@ -206,6 +216,8 @@ sh_pow2(uint64 num) ...@@ -206,6 +216,8 @@ sh_pow2(uint64 num)
return ((uint64) 1) << sh_log2(num); return ((uint64) 1) << sh_log2(num);
} }
#endif
/* /*
* Compute sizing parameters for hashtable. Called when creating and growing * Compute sizing parameters for hashtable. Called when creating and growing
* the hashtable. * the hashtable.
...@@ -924,6 +936,7 @@ SH_STAT(SH_TYPE * tb) ...@@ -924,6 +936,7 @@ SH_STAT(SH_TYPE * tb)
#undef SH_GET_HASH #undef SH_GET_HASH
#undef SH_STORE_HASH #undef SH_STORE_HASH
#undef SH_USE_NONDEFAULT_ALLOCATOR #undef SH_USE_NONDEFAULT_ALLOCATOR
#undef SH_EQUAL
/* undefine locally declared macros */ /* undefine locally declared macros */
#undef SH_MAKE_PREFIX #undef SH_MAKE_PREFIX
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment