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.
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.

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

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] t fanout table to add to
[in] key Key for this entry
[in] data Data to add. Must not be NULL
Returns:
0 on success, -1 on errors
fanout_table* fanout_create ( unsigned long  size  ) 

Create a fanout table.

Parameters:
[in] size The size of the table. Preferably a power of 2
Returns:
Pointer to a newly created table
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] 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.

Parameters:
[in] t table to fetch from
[in] key key to fetch
Returns:
NULL on errors; Pointer to data on success
void* fanout_remove ( fanout_table t,
unsigned long  key 
)

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

Parameters:
[in] t fanout table to look in
[in] key The key whose data we should locate
Returns:
Pointer to the data stored on success; NULL on errors
 All Data Structures Files Functions Variables Typedefs Defines

Generated on 5 Feb 2019 for Nagios by  doxygen 1.6.1