Home | History | Annotate | Download | only in netlink
      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 #ifdef __cplusplus
     16 extern "C" {
     17 #endif
     18 
     19 typedef struct nl_hash_node {
     20     uint32_t			key;
     21     uint32_t			key_size;
     22     struct nl_object *		obj;
     23     struct nl_hash_node *	next;
     24 } nl_hash_node_t;
     25 
     26 typedef struct nl_hash_table {
     27     int 			size;
     28     nl_hash_node_t **		nodes;
     29 } nl_hash_table_t;
     30 
     31 /* Default hash table size */
     32 #define NL_MAX_HASH_ENTRIES 1024
     33 
     34 /* Access Functions */
     35 extern nl_hash_table_t *	nl_hash_table_alloc(int size);
     36 extern void 			nl_hash_table_free(nl_hash_table_t *ht);
     37 
     38 extern int			nl_hash_table_add(nl_hash_table_t *ht,
     39 						  struct nl_object *obj);
     40 extern int			nl_hash_table_del(nl_hash_table_t *ht,
     41 						  struct nl_object *obj);
     42 
     43 extern struct nl_object *	nl_hash_table_lookup(nl_hash_table_t *ht,
     44 						     struct nl_object *obj);
     45 extern uint32_t 		nl_hash(void *k, size_t length,
     46 					uint32_t initval);
     47 
     48 #ifdef __cplusplus
     49 }
     50 #endif
     51 
     52 #endif /* NETLINK_HASHTABLE_H_ */
     53