Nagios
4.4.7
Dev docs for Nagios core and neb-module hackers
|
Dual-key hash functions for Nagios. More...
#include <errno.h>
Go to the source code of this file.
#define | DKHASH_WALK_REMOVE 1 |
return flags usable from the callback function of dkhash_walk_data() More... | |
#define | DKHASH_WALK_STOP 2 |
Cause walking to stop. | |
#define | DKHASH_OK 0 |
return values for dkhash_insert() More... | |
#define | DKHASH_EDUPE (-EPERM) |
duplicate insert attempted | |
#define | DKHASH_EPERM (-EPERM) |
duplicate insert attempted | |
#define | DKHASH_EINVAL (-EINVAL) |
Invalid parameters passed. | |
#define | DKHASH_ENOMEM (-ENOMEM) |
Memory allocation failed. | |
typedef struct dkhash_table | dkhash_table |
opaque type | |
dkhash_table * | dkhash_create (unsigned int size) |
Create a dual-keyed hash-table of the given size Note that it's generally useful to make the table 25-30% larger than the number of items you intend to store, and also note that the 'size' arguments gets rounded up to the nearest power of 2. More... | |
int | dkhash_destroy (dkhash_table *t) |
Destroy a dual-keyed hash table. More... | |
void * | dkhash_get (dkhash_table *t, const char *k1, const char *k2) |
Fetch the data associated with a particular key. More... | |
int | dkhash_insert (dkhash_table *t, const char *k1, const char *k2, void *data) |
Insert a new entry into the hash table. More... | |
void * | dkhash_remove (dkhash_table *t, const char *k1, const char *k2) |
Remove data from the hash table Note that this does not free() the pointer to the data stored in the table. More... | |
void | dkhash_walk_data (dkhash_table *t, int(*walker)(void *data)) |
Call a function once for each item in the hash-table The callback function can return DKHASH_WALK_{REMOVE,STOP} or any OR'ed combination thereof to control the walking procedure, and should return 0 on the normal case. More... | |
unsigned int | dkhash_collisions (dkhash_table *t) |
Get number of collisions in hash table Many collisions is a sign of a too small hash table or poor hash-function. More... | |
unsigned int | dkhash_num_entries (dkhash_table *t) |
Get number of items in the hash table. More... | |
unsigned int | dkhash_num_entries_max (dkhash_table *t) |
Get max number of items stored in the hash table. More... | |
unsigned int | dkhash_num_entries_added (dkhash_table *t) |
Get number of entries added to hash table Note that some of them may have been removed. More... | |
unsigned int | dkhash_num_entries_removed (dkhash_table *t) |
Get number of removed items from hash table. More... | |
unsigned int | dkhash_table_size (dkhash_table *t) |
Get actual table size (in number of buckets) More... | |
Dual-key hash functions for Nagios.
Having a dual-key hash function is pretty unusual, but since so much data in Nagios pertains to services (which are uniquely identified based on both host_name and service_description), it makes sense here.
#define DKHASH_OK 0 |
return values for dkhash_insert()
Success
#define DKHASH_WALK_REMOVE 1 |
return flags usable from the callback function of dkhash_walk_data()
Remove the most recently visited object
unsigned int dkhash_collisions | ( | dkhash_table * | t | ) |
Get number of collisions in hash table Many collisions is a sign of a too small hash table or poor hash-function.
t | The hash table to report on |
dkhash_table* dkhash_create | ( | unsigned int | size | ) |
Create a dual-keyed hash-table of the given size Note that it's generally useful to make the table 25-30% larger than the number of items you intend to store, and also note that the 'size' arguments gets rounded up to the nearest power of 2.
size | The desired size of the hash-table. |
int dkhash_destroy | ( | dkhash_table * | t | ) |
Destroy a dual-keyed hash table.
t | The table to destroy |
void* dkhash_get | ( | dkhash_table * | t, |
const char * | k1, | ||
const char * | k2 | ||
) |
Fetch the data associated with a particular key.
t | The table to get the data from |
k1 | The first key |
k2 | The second key |
int dkhash_insert | ( | dkhash_table * | t, |
const char * | k1, | ||
const char * | k2, | ||
void * | data | ||
) |
Insert a new entry into the hash table.
t | The hash table |
k1 | The first key |
k2 | The second key (may be null) |
data | The data to insert |
unsigned int dkhash_num_entries | ( | dkhash_table * | t | ) |
Get number of items in the hash table.
t | The hash table |
unsigned int dkhash_num_entries_added | ( | dkhash_table * | t | ) |
Get number of entries added to hash table Note that some of them may have been removed.
t | The hash table |
unsigned int dkhash_num_entries_max | ( | dkhash_table * | t | ) |
Get max number of items stored in the hash table.
t | The hash table |
unsigned int dkhash_num_entries_removed | ( | dkhash_table * | t | ) |
Get number of removed items from hash table.
t | The hash table |
void* dkhash_remove | ( | dkhash_table * | t, |
const char * | k1, | ||
const char * | k2 | ||
) |
Remove data from the hash table Note that this does not free() the pointer to the data stored in the table.
It just destroys containers for that data in the hash table.
t | The hash table |
k1 | The first key |
k2 | The second key |
unsigned int dkhash_table_size | ( | dkhash_table * | t | ) |
Get actual table size (in number of buckets)
t | The hash table |
void dkhash_walk_data | ( | dkhash_table * | t, |
int(*)(void *data) | walker | ||
) |
Call a function once for each item in the hash-table The callback function can return DKHASH_WALK_{REMOVE,STOP} or any OR'ed combination thereof to control the walking procedure, and should return 0 on the normal case.
t | The hash table |
walker | The callback function to send the data to |