else
hashp->match = memcmp;
+ /*
+ * Similarly, the key-copying function defaults to strncpy() or memcpy().
+ */
+ if (hashp->hash == string_hash)
+ hashp->keycopy = (HashCopyFunc) strncpy;
+ else
+ hashp->keycopy = memcpy;
+
if (flags & HASH_SHARED_MEM)
{
/*
/* copy key into record */
currBucket->hashvalue = hashvalue;
- memcpy(ELEMENTKEY(currBucket), keyPtr, hctl->keysize);
+ hashp->keycopy(ELEMENTKEY(currBucket), keyPtr, hctl->keysize);
/* caller is expected to fill the data field on return */
/*
- * Hash and comparison functions must have these signatures. Comparison
- * functions return zero for match, nonzero for no match. (The comparison
- * function definition is designed to allow memcmp() and strncmp() to be
- * used directly as key comparison functions.)
+ * Hash functions must have this signature.
*/
typedef uint32 (*HashValueFunc) (const void *key, Size keysize);
+
+/*
+ * Key comparison functions must have this signature. Comparison functions
+ * return zero for match, nonzero for no match. (The comparison function
+ * definition is designed to allow memcmp() and strncmp() to be used directly
+ * as key comparison functions.)
+ */
typedef int (*HashCompareFunc) (const void *key1, const void *key2,
- Size keysize);
+ Size keysize);
+
+/*
+ * Key copying functions must have this signature. The return value is not
+ * used. (The definition is set up to allow memcpy() and strncpy() to be
+ * used directly.)
+ */
+typedef void *(*HashCopyFunc) (void *dest, const void *src, Size keysize);
/*
* Space allocation function for a hashtable --- designed to match malloc().
* used */
char *tabname; /* table name (for error messages) */
bool isshared; /* true if table is in shared memory */
+ HashCopyFunc keycopy; /* key copying function */
} HTAB;
/* Parameter data structure for hash_create */