13 #include <netlink-private/netlink.h> 14 #include <netlink/object.h> 15 #include <netlink/hash.h> 16 #include <netlink/hashtable.h> 34 ht = calloc(1,
sizeof (*ht));
38 ht->nodes = calloc(size,
sizeof (*ht->nodes));
61 for(i = 0; i < ht->size; i++) {
88 struct nl_object *obj)
94 node = ht->nodes[key_hash];
124 node = ht->nodes[key_hash];
128 NL_DBG(2,
"Warning: Add to hashtable found duplicate...\n");
134 NL_DBG (5,
"adding cache entry of obj %p in table %p, with hash 0x%x\n",
142 node->key = key_hash;
143 node->key_size =
sizeof(uint32_t);
144 node->next = ht->nodes[key_hash];
145 ht->nodes[key_hash] = node;
168 prev = node = ht->nodes[key_hash];
174 NL_DBG (5,
"deleting cache entry of obj %p in table %p, with" 175 " hash 0x%x\n", obj, ht, key_hash);
177 if (node == ht->nodes[key_hash])
178 ht->nodes[key_hash] = node->next;
180 prev->next = node->next;
190 return -NLE_OBJ_NOTFOUND;
193 uint32_t nl_hash(
void *k,
size_t length, uint32_t initval)
195 return(__nl_hash((
char *) 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.