12 #include <netlink-private/netlink.h>
13 #include <netlink/object.h>
14 #include <netlink/hash.h>
15 #include <netlink/hashtable.h>
33 ht = calloc(1,
sizeof (*ht));
37 ht->nodes = calloc(size,
sizeof (*ht->nodes));
60 for(i = 0; i < ht->size; i++) {
87 struct nl_object *obj)
93 node = ht->nodes[key_hash];
123 node = ht->nodes[key_hash];
127 NL_DBG(2,
"Warning: Add to hashtable found duplicate...\n");
133 NL_DBG (5,
"adding cache entry of obj %p in table %p, with hash 0x%x\n",
141 node->key = key_hash;
142 node->key_size =
sizeof(uint32_t);
143 node->next = ht->nodes[key_hash];
144 ht->nodes[key_hash] = node;
167 prev = node = ht->nodes[key_hash];
173 NL_DBG (5,
"deleting cache entry of obj %p in table %p, with"
174 " hash 0x%x\n", obj, ht, key_hash);
176 if (node == ht->nodes[key_hash])
177 ht->nodes[key_hash] = node->next;
179 prev->next = node->next;
189 return -NLE_OBJ_NOTFOUND;
192 uint32_t nl_hash(
void *k,
size_t length, uint32_t initval)
194 return(__nl_hash(k, length, initval));
void nl_object_get(struct nl_object *obj)
Acquire a reference on a object.
void nl_hash_table_free(nl_hash_table_t *ht)
Free hashtable including all nodes.
nl_hash_table_t * nl_hash_table_alloc(int size)
Allocate hashtable.
struct nl_object * nl_hash_table_lookup(nl_hash_table_t *ht, struct nl_object *obj)
Lookup identical object in hashtable.
int nl_hash_table_add(nl_hash_table_t *ht, struct nl_object *obj)
Add object to 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.
int nl_hash_table_del(nl_hash_table_t *ht, struct nl_object *obj)
Remove object from hashtable.
void nl_object_keygen(struct nl_object *obj, uint32_t *hashkey, uint32_t hashtbl_sz)
Generate object hash key.