libyang  2.2.8
libyang is YANG data modelling language parser and toolkit written (and providing API) in C.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
hash_table.h
Go to the documentation of this file.
1 
16 #ifndef LY_HASH_TABLE_H_
17 #define LY_HASH_TABLE_H_
18 
19 #include <stddef.h>
20 #include <stdint.h>
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 #include "log.h"
27 
32 struct ly_ht;
33 
47 LIBYANG_API_DECL uint32_t lyht_hash_multi(uint32_t hash, const char *key_part, size_t len);
48 
61 LIBYANG_API_DECL uint32_t lyht_hash(const char *key, size_t len);
62 
72 typedef ly_bool (*lyht_value_equal_cb)(void *val1_p, void *val2_p, ly_bool mod, void *cb_data);
73 
84 LIBYANG_API_DECL struct ly_ht *lyht_new(uint32_t size, uint16_t val_size, lyht_value_equal_cb val_equal, void *cb_data,
85  uint16_t resize);
86 
94 LIBYANG_API_DECL lyht_value_equal_cb lyht_set_cb(struct ly_ht *ht, lyht_value_equal_cb new_val_equal);
95 
103 LIBYANG_API_DECL void *lyht_set_cb_data(struct ly_ht *ht, void *new_cb_data);
104 
111 LIBYANG_API_DECL struct ly_ht *lyht_dup(const struct ly_ht *orig);
112 
119 LIBYANG_API_DECL void lyht_free(struct ly_ht *ht, void (*val_free)(void *val_p));
120 
131 LIBYANG_API_DECL LY_ERR lyht_find(const struct ly_ht *ht, void *val_p, uint32_t hash, void **match_p);
132 
144 LIBYANG_API_DECL LY_ERR lyht_find_with_val_cb(const struct ly_ht *ht, void *val_p, uint32_t hash,
145  lyht_value_equal_cb val_equal, void **match_p);
146 
157 LIBYANG_API_DECL LY_ERR lyht_find_next(const struct ly_ht *ht, void *val_p, uint32_t hash, void **match_p);
158 
171 LIBYANG_API_DECL LY_ERR lyht_find_next_with_collision_cb(const struct ly_ht *ht, void *val_p, uint32_t hash,
172  lyht_value_equal_cb collision_val_equal, void **match_p);
173 
186 LIBYANG_API_DECL LY_ERR lyht_insert(struct ly_ht *ht, void *val_p, uint32_t hash, void **match_p);
187 
199 LIBYANG_API_DECL LY_ERR lyht_insert_no_check(struct ly_ht *ht, void *val_p, uint32_t hash, void **match_p);
200 
216 LIBYANG_API_DECL LY_ERR lyht_insert_with_resize_cb(struct ly_ht *ht, void *val_p, uint32_t hash,
217  lyht_value_equal_cb resize_val_equal, void **match_p);
218 
229 LIBYANG_API_DECL LY_ERR lyht_remove(struct ly_ht *ht, void *val_p, uint32_t hash);
230 
244 LIBYANG_API_DECL LY_ERR lyht_remove_with_resize_cb(struct ly_ht *ht, void *val_p, uint32_t hash,
245  lyht_value_equal_cb resize_val_equal);
246 
253 LIBYANG_API_DECL uint32_t lyht_get_fixed_size(uint32_t item_count);
254 
255 #ifdef __cplusplus
256 }
257 #endif
258 
259 #endif /* LY_HASH_TABLE_H_ */
ly_bool(* lyht_value_equal_cb)(void *val1_p, void *val2_p, ly_bool mod, void *cb_data)
Callback for checking hash table values equivalence.
Definition: hash_table.h:72
LIBYANG_API_DECL LY_ERR lyht_insert(struct ly_ht *ht, void *val_p, uint32_t hash, void **match_p)
Insert a value into a hash table.
LIBYANG_API_DECL uint32_t lyht_get_fixed_size(uint32_t item_count)
Get suitable size of a hash table for a fixed number of items.
uint8_t ly_bool
Type to indicate boolean value.
Definition: log.h:28
LIBYANG_API_DECL LY_ERR lyht_insert_with_resize_cb(struct ly_ht *ht, void *val_p, uint32_t hash, lyht_value_equal_cb resize_val_equal, void **match_p)
Insert a value into hash table. Same functionality as lyht_insert() but allows to specify a temporary...
LIBYANG_API_DECL LY_ERR lyht_remove_with_resize_cb(struct ly_ht *ht, void *val_p, uint32_t hash, lyht_value_equal_cb resize_val_equal)
Remove a value from a hash table. Same functionality as lyht_remove() but allows to specify a tempora...
libyang hash table.
LIBYANG_API_DECL LY_ERR lyht_find_next(const struct ly_ht *ht, void *val_p, uint32_t hash, void **match_p)
Find another equal value in the hash table.
LIBYANG_API_DECL lyht_value_equal_cb lyht_set_cb(struct ly_ht *ht, lyht_value_equal_cb new_val_equal)
Set hash table value equal callback.
LIBYANG_API_DECL uint32_t lyht_hash_multi(uint32_t hash, const char *key_part, size_t len)
Compute hash from (several) string(s).
LIBYANG_API_DECL LY_ERR lyht_find(const struct ly_ht *ht, void *val_p, uint32_t hash, void **match_p)
Find a value in a hash table.
LIBYANG_API_DECL void * lyht_set_cb_data(struct ly_ht *ht, void *new_cb_data)
Set hash table value equal callback user data.
LIBYANG_API_DECL LY_ERR lyht_insert_no_check(struct ly_ht *ht, void *val_p, uint32_t hash, void **match_p)
Insert a value into a hash table, without checking whether the value has already been inserted...
LIBYANG_API_DECL LY_ERR lyht_find_next_with_collision_cb(const struct ly_ht *ht, void *val_p, uint32_t hash, lyht_value_equal_cb collision_val_equal, void **match_p)
Find another equal value in the hash table. Same functionality as lyht_find_next() but allows to spec...
LIBYANG_API_DECL struct ly_ht * lyht_dup(const struct ly_ht *orig)
Make a duplicate of an existing hash table.
LIBYANG_API_DECL struct ly_ht * lyht_new(uint32_t size, uint16_t val_size, lyht_value_equal_cb val_equal, void *cb_data, uint16_t resize)
Create new hash table.
LIBYANG_API_DECL LY_ERR lyht_remove(struct ly_ht *ht, void *val_p, uint32_t hash)
Remove a value from a hash table.
LIBYANG_API_DECL uint32_t lyht_hash(const char *key, size_t len)
Compute hash from a string.
LIBYANG_API_DECL LY_ERR lyht_find_with_val_cb(const struct ly_ht *ht, void *val_p, uint32_t hash, lyht_value_equal_cb val_equal, void **match_p)
Find a value in a hash table but use a custom val_equal callback.
Logger manipulation routines and error definitions.
LY_ERR
libyang&#39;s error codes returned by the libyang functions.
Definition: log.h:240
LIBYANG_API_DECL void lyht_free(struct ly_ht *ht, void(*val_free)(void *val_p))
Free a hash table.