7#include <netlink-private/netlink.h>
8#include <netlink/object.h>
9#include <netlink/hash.h>
10#include <netlink/hashtable.h>
28 ht = calloc(1,
sizeof (*ht));
32 ht->nodes = calloc(size,
sizeof (*ht->nodes));
55 for(i = 0; i < ht->size; i++) {
82 struct nl_object *obj)
88 node = ht->nodes[key_hash];
118 node = ht->nodes[key_hash];
122 NL_DBG(2,
"Warning: Add to hashtable found duplicate...\n");
128 NL_DBG (5,
"adding cache entry of obj %p in table %p, with hash 0x%x\n",
136 node->key = key_hash;
137 node->key_size =
sizeof(uint32_t);
138 node->next = ht->nodes[key_hash];
139 ht->nodes[key_hash] = node;
162 prev = node = ht->nodes[key_hash];
168 NL_DBG (5,
"deleting cache entry of obj %p in table %p, with"
169 " hash 0x%x\n", obj, ht, key_hash);
171 if (node == ht->nodes[key_hash])
172 ht->nodes[key_hash] = node->next;
174 prev->next = node->next;
184 return -NLE_OBJ_NOTFOUND;
187uint32_t nl_hash(
void *k,
size_t length, uint32_t initval)
189 return(__nl_hash((
char *) k, length, initval));
int nl_hash_table_del(nl_hash_table_t *ht, struct nl_object *obj)
Remove object from hashtable.
nl_hash_table_t * nl_hash_table_alloc(int size)
Allocate hashtable.
void nl_hash_table_free(nl_hash_table_t *ht)
Free hashtable including all nodes.
int nl_hash_table_add(nl_hash_table_t *ht, struct nl_object *obj)
Add object to hashtable.
struct nl_object * nl_hash_table_lookup(nl_hash_table_t *ht, struct nl_object *obj)
Lookup identical object in hashtable.
void nl_object_put(struct nl_object *obj)
Release a reference from an object.
int nl_object_identical(struct nl_object *a, struct nl_object *b)
Check if the identifiers of two objects are identical.
void nl_object_get(struct nl_object *obj)
Acquire a reference on a object.
void nl_object_keygen(struct nl_object *obj, uint32_t *hashkey, uint32_t hashtbl_sz)
Generate object hash key.