Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit ee0e274

Browse files
committed
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
1 parent 7a3b7bb commit ee0e274

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/include/lib/simplehash.h

+16-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
* - SH_STORE_HASH - if defined the hash is stored in the elements
3333
* - SH_GET_HASH(tb, a) - return the field to store the hash in
3434
*
35-
* For examples of usage look at simplehash.c (file local definition) and
35+
* For examples of usage look at tidbitmap.c (file local definition) and
3636
* execnodes.h/execGrouping.c (exposed declaration, file local
3737
* implementation).
3838
*
@@ -65,8 +65,8 @@
6565
/* type declarations */
6666
#define SH_TYPE SH_MAKE_NAME(hash)
6767
#define SH_STATUS SH_MAKE_NAME(status)
68-
#define SH_STATUS_EMPTY SH_MAKE_NAME(EMPTY)
69-
#define SH_STATUS_IN_USE SH_MAKE_NAME(IN_USE)
68+
#define SH_STATUS_EMPTY SH_MAKE_NAME(SH_EMPTY)
69+
#define SH_STATUS_IN_USE SH_MAKE_NAME(SH_IN_USE)
7070
#define SH_ITERATOR SH_MAKE_NAME(iterator)
7171

7272
/* function declarations */
@@ -185,6 +185,16 @@ SH_SCOPE void SH_STAT(SH_TYPE * tb);
185185
#define SH_COMPARE_KEYS(tb, ahash, akey, b) (SH_EQUAL(tb, b->SH_KEY, akey))
186186
#endif
187187

188+
/*
189+
* Wrap the following definitions in include guards, to avoid multiple
190+
* definition errors if this header is included more than once. The rest of
191+
* the file deliberately has no include guards, because it can be included
192+
* with different parameters to define functions and types with non-colliding
193+
* names.
194+
*/
195+
#ifndef SIMPLEHASH_H
196+
#define SIMPLEHASH_H
197+
188198
/* FIXME: can we move these to a central location? */
189199

190200
/* calculate ceil(log base 2) of num */
@@ -206,6 +216,8 @@ sh_pow2(uint64 num)
206216
return ((uint64) 1) << sh_log2(num);
207217
}
208218

219+
#endif
220+
209221
/*
210222
* Compute sizing parameters for hashtable. Called when creating and growing
211223
* the hashtable.
@@ -924,6 +936,7 @@ SH_STAT(SH_TYPE * tb)
924936
#undef SH_GET_HASH
925937
#undef SH_STORE_HASH
926938
#undef SH_USE_NONDEFAULT_ALLOCATOR
939+
#undef SH_EQUAL
927940

928941
/* undefine locally declared macros */
929942
#undef SH_MAKE_PREFIX

0 commit comments

Comments
 (0)