Nagios  4.3.4
Dev docs for Nagios core and neb-module hackers
fanout.h
Go to the documentation of this file.
1 #ifndef LIBNAGIOS_FANOUT_H_INCLUDED
2 #define LIBNAGIOS_FANOUT_H_INCLUDED
3 #include "lnag-utils.h"
4 
5 /**
6  * @file fanout.h
7  * @brief Simple fanout table implementation
8  *
9  * Fanouts are useful to hold short-lived integer-indexed data where
10  * the keyspan between smallest and largest key can be too large and
11  * change too often for it to be practical to maintain a growing array.
12  * If you think of it as a hash-table optimized for unsigned longs you've
13  * got the right idea.
14  *
15  * @{
16  */
17 
19 
20 /** Primary (opaque) type for this api */
21 typedef struct fanout_table fanout_table;
22 
23 /**
24  * Create a fanout table
25  * @param[in] size The size of the table. Preferably a power of 2
26  * @return Pointer to a newly created table
27  */
28 extern fanout_table *fanout_create(unsigned long size);
29 
30 /**
31  * Destroy a fanout table, with optional destructor.
32  * This function will iterate over all the entries in the fanout
33  * table and remove them, one by one. If 'destructor' is not NULL,
34  * it will be called on each and every object in the table. Note that
35  * 'free' is a valid destructor.
36  *
37  * @param[in] t The fanout table to destroy
38  * @param[in] destructor Function to call on data pointers in table
39  */
40 extern void fanout_destroy(fanout_table *t, void (*destructor)(void *));
41 
42 /**
43  * Return a pointer from the fanout table t
44  *
45  * @param[in] t table to fetch from
46  * @param[in] key key to fetch
47  * @return NULL on errors; Pointer to data on success
48  */
49 extern void *fanout_get(fanout_table *t, unsigned long key);
50 
51 /**
52  * Add an entry to the fanout table.
53  * Note that we don't check if the key is unique. If it isn't,
54  * fanout_remove() will remove the latest added first.
55  *
56  * @param[in] t fanout table to add to
57  * @param[in] key Key for this entry
58  * @param[in] data Data to add. Must not be NULL
59  * @return 0 on success, -1 on errors
60  */
61 extern int fanout_add(fanout_table *t, unsigned long key, void *data);
62 
63 /**
64  * Remove an entry from the fanout table and return its data.
65  *
66  * @param[in] t fanout table to look in
67  * @param[in] key The key whose data we should locate
68  * @return Pointer to the data stored on success; NULL on errors
69  */
70 extern void *fanout_remove(fanout_table *t, unsigned long key);
72 /** @} */
73 #endif
typedefNAGIOS_BEGIN_DECL struct fanout_table fanout_table
Primary (opaque) type for this api.
Definition: fanout.h:21
#define NAGIOS_END_DECL
C++ compatibility macro that avoid confusing indentation programs.
Definition: lnag-utils.h:32
fanout_table * fanout_create(unsigned long size)
Create a fanout table.
libnagios helper and compatibility macros that lack a "real" home.
void * fanout_get(fanout_table *t, unsigned long key)
Return a pointer from the fanout table t.
void fanout_destroy(fanout_table *t, void(*destructor)(void *))
Destroy a fanout table, with optional destructor.
int fanout_add(fanout_table *t, unsigned long key, void *data)
Add an entry to the fanout table.
void * fanout_remove(fanout_table *t, unsigned long key)
Remove an entry from the fanout table and return its data.
#define NAGIOS_BEGIN_DECL
C++ compatibility macro that avoids confusing indentation programs.
Definition: lnag-utils.h:30