*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/hash/dynahash.c,v 1.61 2005/05/29 04:23:06 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/hash/dynahash.c,v 1.62 2005/06/18 20:51:30 tgl Exp $
*
*-------------------------------------------------------------------------
*/
else
hashp->match = memcmp;
+ /*
+ * Similarly, the key-copying function defaults to strncpy() or memcpy().
+ */
+ if (flags & HASH_KEYCOPY)
+ hashp->keycopy = info->keycopy;
+ else if (hashp->hash == string_hash)
+ hashp->keycopy = (HashCopyFunc) strncpy;
+ else
+ hashp->keycopy = memcpy;
+
if (flags & HASH_ALLOC)
hashp->alloc = info->alloc;
else
/* copy key into record */
currBucket->hashvalue = hashvalue;
- memcpy(ELEMENTKEY(currBucket), keyPtr, hctl->keysize);
+ hashp->keycopy(ELEMENTKEY(currBucket), keyPtr, keysize);
/* caller is expected to fill the data field on return */
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/utils/hsearch.h,v 1.37 2005/06/08 23:02:05 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/utils/hsearch.h,v 1.38 2005/06/18 20:51:30 tgl Exp $
*
*-------------------------------------------------------------------------
*/
/*
- * 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().
HASHSEGMENT *dir; /* directory of segment starts */
HashValueFunc hash; /* hash function */
HashCompareFunc match; /* key comparison function */
+ HashCopyFunc keycopy; /* key copying function */
HashAllocFunc alloc; /* memory allocator */
MemoryContext hcxt; /* memory context if default allocator
* used */
Size entrysize; /* total user element size in bytes */
HashValueFunc hash; /* hash function */
HashCompareFunc match; /* key comparison function */
+ HashCopyFunc keycopy; /* key copying function */
HashAllocFunc alloc; /* memory allocator */
HASHSEGMENT *dir; /* directory of segment starts */
HASHHDR *hctl; /* location of header in shared mem */
#define HASH_ALLOC 0x100 /* Set memory allocator */
#define HASH_CONTEXT 0x200 /* Set explicit memory context */
#define HASH_COMPARE 0x400 /* Set user defined comparison function */
+#define HASH_KEYCOPY 0x800 /* Set user defined key-copying function */
/* max_dsize value to indicate expansible directory */