1
/*-------------------------------------------------------------------------
4
* Hash functions for use in dynahash.c hashtables
7
* Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group
8
* Portions Copyright (c) 1994, Regents of the University of California
12
* src/backend/utils/hash/hashfn.c
15
* It is expected that every bit of a hash function's 32-bit result is
16
* as random as every other; failure to ensure this is likely to lead
17
* to poor performance of hash tables. In most cases a hash
18
* function should use hash_any() or its variant hash_uint32().
20
*-------------------------------------------------------------------------
24
#include "access/hash.h"
25
#include "nodes/bitmapset.h"
29
* string_hash: hash function for keys that are null-terminated strings.
31
* NOTE: this is the default hash function if none is specified.
34
string_hash(const void *key, Size keysize)
37
* If the string exceeds keysize-1 bytes, we want to hash only that many,
38
* because when it is copied into the hash table it will be truncated at
41
Size s_len = strlen((const char *) key);
43
s_len = Min(s_len, keysize - 1);
44
return DatumGetUInt32(hash_any((const unsigned char *) key,
49
* tag_hash: hash function for fixed-size tag values
52
tag_hash(const void *key, Size keysize)
54
return DatumGetUInt32(hash_any((const unsigned char *) key,
59
* oid_hash: hash function for keys that are OIDs
61
* (tag_hash works for this case too, but is slower)
64
oid_hash(const void *key, Size keysize)
66
Assert(keysize == sizeof(Oid));
67
return DatumGetUInt32(hash_uint32((uint32) *((const Oid *) key)));
71
* bitmap_hash: hash function for keys that are (pointers to) Bitmapsets
73
* Note: don't forget to specify bitmap_match as the match function!
76
bitmap_hash(const void *key, Size keysize)
78
Assert(keysize == sizeof(Bitmapset *));
79
return bms_hash_value(*((const Bitmapset *const *) key));
83
* bitmap_match: match function to use with bitmap_hash
86
bitmap_match(const void *key1, const void *key2, Size keysize)
88
Assert(keysize == sizeof(Bitmapset *));
89
return !bms_equal(*((const Bitmapset *const *) key1),
90
*((const Bitmapset *const *) key2));