Nagios  4.3.4
Dev docs for Nagios core and neb-module hackers
fanout.h File Reference

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_tablefanout_create (unsigned long size)
 Create a fanout table. More...
 
void fanout_destroy (fanout_table *t, void(*destructor)(void *))
 Destroy a fanout table, with optional destructor. More...
 
void * fanout_get (fanout_table *t, unsigned long key)
 Return a pointer from the fanout table t. More...
 
int fanout_add (fanout_table *t, unsigned long key, void *data)
 Add an entry to the fanout table. More...
 
void * fanout_remove (fanout_table *t, unsigned long key)
 Remove an entry from the fanout table and return its data. More...
 

Detailed Description

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.

Function Documentation

◆ fanout_add()

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.

Parameters
[in]tfanout table to add to
[in]keyKey for this entry
[in]dataData to add. Must not be NULL
Returns
0 on success, -1 on errors

◆ fanout_create()

fanout_table* fanout_create ( unsigned long  size)

Create a fanout table.

Parameters
[in]sizeThe size of the table. Preferably a power of 2
Returns
Pointer to a newly created table

◆ fanout_destroy()

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.

Parameters
[in]tThe fanout table to destroy
[in]destructorFunction to call on data pointers in table

◆ fanout_get()

void* fanout_get ( fanout_table t,
unsigned long  key 
)

Return a pointer from the fanout table t.

Parameters
[in]ttable to fetch from
[in]keykey to fetch
Returns
NULL on errors; Pointer to data on success

◆ fanout_remove()

void* fanout_remove ( fanout_table t,
unsigned long  key 
)

Remove an entry from the fanout table and return its data.

Parameters
[in]tfanout table to look in
[in]keyThe key whose data we should locate
Returns
Pointer to the data stored on success; NULL on errors