• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * netlink/hashtable.h       Netlink hashtable Utilities
3  *
4  *      This library is free software; you can redistribute it and/or
5  *      modify it under the terms of the GNU Lesser General Public
6  *      License as published by the Free Software Foundation version 2.1
7  *      of the License.
8  *
9  * Copyright (c) 2012 Cumulus Networks, Inc
10  */
11 
12 #ifndef NETLINK_HASHTABLE_H_
13 #define NETLINK_HASHTABLE_H_
14 
15 #include <stddef.h>
16 #include <stdint.h>
17 
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21 
22 typedef struct nl_hash_node {
23     uint32_t			key;
24     uint32_t			key_size;
25     struct nl_object *		obj;
26     struct nl_hash_node *	next;
27 } nl_hash_node_t;
28 
29 typedef struct nl_hash_table {
30     int 			size;
31     nl_hash_node_t **		nodes;
32 } nl_hash_table_t;
33 
34 /* Default hash table size */
35 #define NL_MAX_HASH_ENTRIES 1024
36 
37 /* Access Functions */
38 extern nl_hash_table_t *	nl_hash_table_alloc(int size);
39 extern void 			nl_hash_table_free(nl_hash_table_t *ht);
40 
41 extern int			nl_hash_table_add(nl_hash_table_t *ht,
42 						  struct nl_object *obj);
43 extern int			nl_hash_table_del(nl_hash_table_t *ht,
44 						  struct nl_object *obj);
45 
46 extern struct nl_object *	nl_hash_table_lookup(nl_hash_table_t *ht,
47 						     struct nl_object *obj);
48 extern uint32_t 		nl_hash(void *k, size_t length,
49 					uint32_t initval);
50 
51 #ifdef __cplusplus
52 }
53 #endif
54 
55 #endif /* NETLINK_HASHTABLE_H_ */
56