• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
13 extern "C" {
14 #endif
15 
16 typedef 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 
23 typedef 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 */
32 extern nl_hash_table_t *	nl_hash_table_alloc(int size);
33 extern void 			nl_hash_table_free(nl_hash_table_t *ht);
34 
35 extern int			nl_hash_table_add(nl_hash_table_t *ht,
36 						  struct nl_object *obj);
37 extern int			nl_hash_table_del(nl_hash_table_t *ht,
38 						  struct nl_object *obj);
39 
40 extern struct nl_object *	nl_hash_table_lookup(nl_hash_table_t *ht,
41 						     struct nl_object *obj);
42 extern uint32_t 		nl_hash(void *k, size_t length,
43 					uint32_t initval);
44 
45 #ifdef __cplusplus
46 }
47 #endif
48 
49 #endif /* NETLINK_HASHTABLE_H_ */
50