From 809f6eb3321edb91fcc96b1f8353dbfe2f762fa7 Mon Sep 17 00:00:00 2001 From: Nick Alcock Date: Tue, 2 Jun 2020 21:31:45 +0100 Subject: libctf: add new dynhash functions Future commits will use these. ctf_dynhash_elements: count elements in a dynhash ctf_dynhash_lookup_kv: look up and return pointers to the original key and value in a dynhash (the only way of getting a reference to the original key) ctf_dynhash_iter_find: iterate until an item is found, then return its key ctf_dynhash_cinsert: insert a const key / value into a dynhash (a thim wrapper in a new header dedicated to inline functions). As with the rest of ctf_dynhash, this is not public API. No impact on existing callers is expected. libctf/ * ctf-inlines.h: New file. * ctf-impl.h: Include it. (ctf_hash_iter_find_f): New typedef. (ctf_dynhash_elements): New. (ctf_dynhash_lookup_kv): New. (ctf_dynhash_iter_find): New. * ctf-hash.c (ctf_dynhash_lookup_kv): New. (ctf_traverse_find_cb_arg_t): New. (ctf_hashtab_traverse_find): New. (ctf_dynhash_iter_find): New. (ctf_dynhash_elements): New. --- libctf/ctf-impl.h | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'libctf/ctf-impl.h') diff --git a/libctf/ctf-impl.h b/libctf/ctf-impl.h index f832c71..3e09779 100644 --- a/libctf/ctf-impl.h +++ b/libctf/ctf-impl.h @@ -382,6 +382,7 @@ typedef void (*ctf_hash_free_fun) (void *); typedef void (*ctf_hash_iter_f) (void *key, void *value, void *arg); typedef int (*ctf_hash_iter_remove_f) (void *key, void *value, void *arg); +typedef int (*ctf_hash_iter_find_f) (void *key, void *value, void *arg); extern ctf_hash_t *ctf_hash_create (unsigned long, ctf_hash_fun, ctf_hash_eq_fun); extern int ctf_hash_insert_type (ctf_hash_t *, ctf_file_t *, uint32_t, uint32_t); @@ -394,12 +395,17 @@ extern ctf_dynhash_t *ctf_dynhash_create (ctf_hash_fun, ctf_hash_eq_fun, ctf_hash_free_fun, ctf_hash_free_fun); extern int ctf_dynhash_insert (ctf_dynhash_t *, void *, void *); extern void ctf_dynhash_remove (ctf_dynhash_t *, const void *); +extern size_t ctf_dynhash_elements (ctf_dynhash_t *); extern void ctf_dynhash_empty (ctf_dynhash_t *); extern void *ctf_dynhash_lookup (ctf_dynhash_t *, const void *); +extern int ctf_dynhash_lookup_kv (ctf_dynhash_t *, const void *key, + const void **orig_key, void **value); extern void ctf_dynhash_destroy (ctf_dynhash_t *); extern void ctf_dynhash_iter (ctf_dynhash_t *, ctf_hash_iter_f, void *); extern void ctf_dynhash_iter_remove (ctf_dynhash_t *, ctf_hash_iter_remove_f, void *); +extern void *ctf_dynhash_iter_find (ctf_dynhash_t *, ctf_hash_iter_find_f, + void *); #define ctf_list_prev(elem) ((void *)(((ctf_list_t *)(elem))->l_prev)) #define ctf_list_next(elem) ((void *)(((ctf_list_t *)(elem))->l_next)) @@ -492,6 +498,8 @@ extern const char _CTF_NULLSTR[]; /* empty string */ extern int _libctf_version; /* library client version */ extern int _libctf_debug; /* debugging messages enabled */ +#include "ctf-inlines.h" + #ifdef __cplusplus } #endif -- cgit v1.1