dkhash.h File Reference

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()
#define DKHASH_WALK_STOP   2
 Cause walking to stop.
#define DKHASH_OK   0
 return values for dkhash_insert()
#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_tabledkhash_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.
int dkhash_destroy (dkhash_table *t)
 Destroy a dual-keyed hash table.
void * dkhash_get (dkhash_table *t, const char *k1, const char *k2)
 Fetch the data associated with a particular key.
int dkhash_insert (dkhash_table *t, const char *k1, const char *k2, void *data)
 Insert a new entry into 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.
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.
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.
unsigned int dkhash_num_entries (dkhash_table *t)
 Get number of items in the hash table.
unsigned int dkhash_num_entries_max (dkhash_table *t)
 Get max number of items stored in 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.
unsigned int dkhash_num_entries_removed (dkhash_table *t)
 Get number of removed items from hash table.
unsigned int dkhash_table_size (dkhash_table *t)
 Get actual table size (in number of buckets).

Detailed Description

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 Documentation

#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


Function Documentation

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.

Parameters:
t The hash table to report on
Returns:
The total number of collisions (not duplicates) from inserts
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.

Parameters:
size The desired size of the hash-table.
int dkhash_destroy ( dkhash_table t  ) 

Destroy a dual-keyed hash table.

Parameters:
t The table to destroy
Returns:
0 on success, -1 on errors
void* dkhash_get ( dkhash_table t,
const char *  k1,
const char *  k2 
)

Fetch the data associated with a particular key.

Parameters:
t The table to get the data from
k1 The first key
k2 The second key
Returns:
The data on success, NULL on errors or if data isn't found
int dkhash_insert ( dkhash_table t,
const char *  k1,
const char *  k2,
void *  data 
)

Insert a new entry into the hash table.

Parameters:
t The hash table
k1 The first key
k2 The second key (may be null)
data The data to insert
Returns:
0 on success, < 0 on errors
unsigned int dkhash_num_entries ( dkhash_table t  ) 

Get number of items in the hash table.

Parameters:
t The hash table
Returns:
Number of items currently in 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.

Parameters:
t The hash table
Returns:
The number of items added to the table
unsigned int dkhash_num_entries_max ( dkhash_table t  ) 

Get max number of items stored in the hash table.

Parameters:
t The hash table
Returns:
Max number of items stored in hash-table
unsigned int dkhash_num_entries_removed ( dkhash_table t  ) 

Get number of removed items from hash table.

Parameters:
t The hash table
Returns:
Number of items removed from 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.

Parameters:
t The hash table
k1 The first key
k2 The second key
Returns:
The removed data on success, or NULL on errors
unsigned int dkhash_table_size ( dkhash_table t  ) 

Get actual table size (in number of buckets).

Parameters:
t The hash table
Returns:
Number of bucket-slots in 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.

Parameters:
t The hash table
walker The callback function to send the data to
 All Data Structures Files Functions Variables Typedefs Defines

Generated on 24 Nov 2017 for Nagios by  doxygen 1.6.1