libnl 3.12.0
hashtable.h
1/* SPDX-License-Identifier: LGPL-2.1-only */
2/*
3 * Copyright (c) 2012 Cumulus Networks, Inc
4 */
5
6#ifndef NETLINK_HASHTABLE_H_
7#define NETLINK_HASHTABLE_H_
8
9#include <stddef.h>
10#include <stdint.h>
11
12#ifdef __cplusplus
13extern "C" {
14#endif
15
16typedef struct nl_hash_node {
17 uint32_t key;
18 uint32_t key_size;
19 struct nl_object *obj;
20 struct nl_hash_node *next;
21} nl_hash_node_t;
22
23typedef struct nl_hash_table {
24 int size;
25 nl_hash_node_t **nodes;
26} nl_hash_table_t;
27
28/* Default hash table size */
29#define NL_MAX_HASH_ENTRIES 1024
30
31/* Access Functions */
32extern nl_hash_table_t *nl_hash_table_alloc(int size);
33extern void nl_hash_table_free(nl_hash_table_t *ht);
34
35extern int nl_hash_table_add(nl_hash_table_t *ht, struct nl_object *obj);
36extern int nl_hash_table_del(nl_hash_table_t *ht, struct nl_object *obj);
37
38extern struct nl_object *nl_hash_table_lookup(nl_hash_table_t *ht,
39 struct nl_object *obj);
40extern uint32_t nl_hash(void *k, size_t length, uint32_t initval);
41
42#ifdef __cplusplus
43}
44#endif
45
46#endif /* NETLINK_HASHTABLE_H_ */
int nl_hash_table_del(nl_hash_table_t *ht, struct nl_object *obj)
Remove object from hashtable.
Definition hashtable.c:170
nl_hash_table_t * nl_hash_table_alloc(int size)
Allocate hashtable.
Definition hashtable.c:41
void nl_hash_table_free(nl_hash_table_t *ht)
Free hashtable including all nodes.
Definition hashtable.c:78
int nl_hash_table_add(nl_hash_table_t *ht, struct nl_object *obj)
Add object to hashtable.
Definition hashtable.c:125
struct nl_object * nl_hash_table_lookup(nl_hash_table_t *ht, struct nl_object *obj)
Lookup identical object in hashtable.
Definition hashtable.c:94