summaryrefslogtreecommitdiff
path: root/src/include/lib
diff options
context:
space:
mode:
authorAndres Freund2017-08-25 00:01:36 +0000
committerAndres Freund2017-08-25 00:01:36 +0000
commitd7694fc148707cd8335d9ccfde9f4c17290189db (patch)
tree1329774530a926ab580e878be5ea41da0d0775a7 /src/include/lib
parent4569715bd6faa4c43e489a7069ab7abca68ff663 (diff)
Consolidate the function pointer types used by dshash.c.
Commit 8c0d7bafad36434cb08ac2c78e69ae72c194ca20 introduced dshash with hash and compare functions like DynaHash's, and also variants that take a user data pointer instead of size. Simplify the interface by merging them into a single pair of function pointer types that take both size and a user data pointer. Since it is anticipated that memcmp and tag_hash behavior will be a common requirement, provide wrapper functions dshash_memcmp and dshash_memhash that conform to the new function types. Author: Thomas Munro Reviewed-By: Andres Freund Discussion: https://postgr.es/m/20170823054644.efuzftxjpfi6wwqs%40alap3.anarazel.de
Diffstat (limited to 'src/include/lib')
-rw-r--r--src/include/lib/dshash.h37
1 files changed, 10 insertions, 27 deletions
diff --git a/src/include/lib/dshash.h b/src/include/lib/dshash.h
index 187f58b4e49..3fd91f86977 100644
--- a/src/include/lib/dshash.h
+++ b/src/include/lib/dshash.h
@@ -26,32 +26,13 @@ typedef dsa_pointer dshash_table_handle;
/* The type for hash values. */
typedef uint32 dshash_hash;
-/*
- * A function used for comparing keys. This version is compatible with
- * HashCompareFunction in hsearch.h and memcmp.
- */
-typedef int (*dshash_compare_function) (const void *a, const void *b, size_t size);
+/* A function type for comparing keys. */
+typedef int (*dshash_compare_function) (const void *a, const void *b,
+ size_t size, void *arg);
-/*
- * A function type used for comparing keys. This version allows compare
- * functions to receive a pointer to arbitrary user data that was given to the
- * create or attach function. Similar to qsort_arg_comparator.
- */
-typedef int (*dshash_compare_arg_function) (const void *a, const void *b, void *arg);
-
-/*
- * A function type for computing hash values for keys. This version is
- * compatible with HashValueFunc in hsearch.h and hash functions like
- * tag_hash.
- */
-typedef dshash_hash (*dshash_hash_function) (const void *v, size_t size);
-
-/*
- * A function type for computing hash values for keys. This version allows
- * hash functions to receive a pointer to arbitrary user data that was given
- * to the create or attach function.
- */
-typedef dshash_hash (*dshash_hash_arg_function) (const void *v, void *arg);
+/* A function type for computing hash values for keys. */
+typedef dshash_hash (*dshash_hash_function) (const void *v, size_t size,
+ void *arg);
/*
* The set of parameters needed to create or attach to a hash table. The
@@ -70,9 +51,7 @@ typedef struct dshash_parameters
size_t key_size; /* Size of the key (initial bytes of entry) */
size_t entry_size; /* Total size of entry */
dshash_compare_function compare_function; /* Compare function */
- dshash_compare_arg_function compare_arg_function; /* Arg version */
dshash_hash_function hash_function; /* Hash function */
- dshash_hash_arg_function hash_arg_function; /* Arg version */
int tranche_id; /* The tranche ID to use for locks */
} dshash_parameters;
@@ -101,6 +80,10 @@ extern bool dshash_delete_key(dshash_table *hash_table, const void *key);
extern void dshash_delete_entry(dshash_table *hash_table, void *entry);
extern void dshash_release_lock(dshash_table *hash_table, void *entry);
+/* Convenience hash and compare functions wrapping memcmp and tag_hash. */
+extern int dshash_memcmp(const void *a, const void *b, size_t size, void *arg);
+extern dshash_hash dshash_memhash(const void *v, size_t size, void *arg);
+
/* Debugging support. */
extern void dshash_dump(dshash_table *hash_table);