Nagios 4.4.14
Dev docs for Nagios core and neb-module hackers
|
Simple fanout table implementation. More...
#include "lnag-utils.h"
Go to the source code of this file.
typedef typedefNAGIOS_BEGIN_DECL struct fanout_table | fanout_table |
Primary (opaque) type for this api. | |
fanout_table * | fanout_create (unsigned long size) |
Create a fanout table. | |
void | fanout_destroy (fanout_table *t, void(*destructor)(void *)) |
Destroy a fanout table, with optional destructor. | |
void * | fanout_get (fanout_table *t, unsigned long key) |
Return a pointer from the fanout table t. | |
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. | |
Simple fanout table implementation.
Fanouts are useful to hold short-lived integer-indexed data where the keyspan between smallest and largest key can be too large and change too often for it to be practical to maintain a growing array. If you think of it as a hash-table optimized for unsigned longs you've got the right idea.
int fanout_add | ( | fanout_table * | t, |
unsigned long | key, | ||
void * | data | ||
) |
Add an entry to the fanout table.
Note that we don't check if the key is unique. If it isn't, fanout_remove() will remove the latest added first.
[in] | t | fanout table to add to |
[in] | key | Key for this entry |
[in] | data | Data to add. Must not be NULL |
fanout_table * fanout_create | ( | unsigned long | size | ) |
Create a fanout table.
[in] | size | The size of the table. Preferably a power of 2 |
void fanout_destroy | ( | fanout_table * | t, |
void(*)(void *) | destructor | ||
) |
Destroy a fanout table, with optional destructor.
This function will iterate over all the entries in the fanout table and remove them, one by one. If 'destructor' is not NULL, it will be called on each and every object in the table. Note that 'free' is a valid destructor.
[in] | t | The fanout table to destroy |
[in] | destructor | Function to call on data pointers in table |
void * fanout_get | ( | fanout_table * | t, |
unsigned long | key | ||
) |
Return a pointer from the fanout table t.
[in] | t | table to fetch from |
[in] | key | Key to fetch |
void * fanout_remove | ( | fanout_table * | t, |
unsigned long | key | ||
) |
Remove an entry from the fanout table and return its data.
[in] | t | fanout table to look in |
[in] | key | The key whose data we should locate |