diff options
author | Robert Haas <rhaas@postgresql.org> | 2020-02-24 17:27:15 +0530 |
---|---|---|
committer | Robert Haas <rhaas@postgresql.org> | 2020-02-24 17:27:15 +0530 |
commit | a91e2fa94180f24dd68fb6c99136cda820e02089 (patch) | |
tree | 0aac0e3930a043b621e5be2f82142d21c913b127 /src/include/utils/hashutils.h | |
parent | 9341c783cc42ffae5860c86bdc713bd47d734ffd (diff) | |
download | postgresql-a91e2fa94180f24dd68fb6c99136cda820e02089.tar.gz postgresql-a91e2fa94180f24dd68fb6c99136cda820e02089.zip |
Adapt hashfn.c and hashutils.h for frontend use.
hash_any() and its various variants are defined to return Datum,
which is a backend-only concept, but the underlying functions
actually want to return uint32 and uint64, and only return Datum
because it's convenient for callers who are using them to
implement a hash function for some SQL datatype.
However, changing these functions to return uint32 and uint64
seems like it might lead to programming errors or back-patching
difficulties, both because they are widely used and because
failure to use UInt{32,64}GetDatum() might not provoke a
compilation error. Instead, rename the existing functions as
well as changing the return type, and add static inline wrappers
for those callers that need the previous behavior.
Although this commit adapts hashutils.h and hashfn.c so that they
can be compiled as frontend code, it does not actually do
anything that would cause them to be so compiled. That is left
for another commit.
Patch by me, reviewed by Suraj Kharage and Mark Dilger.
Discussion: http://postgr.es/m/CA+TgmoaRiG4TXND8QuM6JXFRkM_1wL2ZNhzaUKsuec9-4yrkgw@mail.gmail.com
Diffstat (limited to 'src/include/utils/hashutils.h')
-rw-r--r-- | src/include/utils/hashutils.h | 36 |
1 files changed, 31 insertions, 5 deletions
diff --git a/src/include/utils/hashutils.h b/src/include/utils/hashutils.h index f2ae55194ae..ba3ecb75925 100644 --- a/src/include/utils/hashutils.h +++ b/src/include/utils/hashutils.h @@ -20,11 +20,37 @@ (((v) >> 31) & UINT64CONST(0x100000001))) -extern Datum hash_any(const unsigned char *k, int keylen); -extern Datum hash_any_extended(const unsigned char *k, - int keylen, uint64 seed); -extern Datum hash_uint32(uint32 k); -extern Datum hash_uint32_extended(uint32 k, uint64 seed); +extern uint32 hash_bytes(const unsigned char *k, int keylen); +extern uint64 hash_bytes_extended(const unsigned char *k, + int keylen, uint64 seed); +extern uint32 hash_bytes_uint32(uint32 k); +extern uint64 hash_bytes_uint32_extended(uint32 k, uint64 seed); + +#ifndef FRONTEND +static inline Datum +hash_any(const unsigned char *k, int keylen) +{ + return UInt32GetDatum(hash_bytes(k, keylen)); +} + +static inline Datum +hash_any_extended(const unsigned char *k, int keylen, uint64 seed) +{ + return UInt64GetDatum(hash_bytes_extended(k, keylen, seed)); +} + +static inline Datum +hash_uint32(uint32 k) +{ + return UInt32GetDatum(hash_bytes_uint32(k)); +} + +static inline Datum +hash_uint32_extended(uint32 k, uint64 seed) +{ + return UInt64GetDatum(hash_bytes_uint32_extended(k, seed)); +} +#endif extern uint32 string_hash(const void *key, Size keysize); extern uint32 tag_hash(const void *key, Size keysize); |