Nagios  4.4.7
Dev docs for Nagios core and neb-module hackers
skiplist.h File Reference

Skiplist library functions. More...

#include "lnag-utils.h"

Go to the source code of this file.

#define SKIPLIST_OK   0
 A ok.
 
#define SKIPLIST_ERROR_ARGS   1
 Bad arguments.
 
#define SKIPLIST_ERROR_MEMORY   2
 Memory error.
 
#define SKIPLIST_ERROR_DUPLICATE   3
 Trying to insert non-unique item.
 
typedef struct skiplist_struct skiplist
 
unsigned long skiplist_num_items (skiplist *list)
 Return number of items currently in the skiplist. More...
 
skiplist * skiplist_new (int max_levels, float level_probability, int allow_duplicates, int append_duplicates, int(*compare_function)(void *, void *))
 Create a new skiplist. More...
 
int skiplist_insert (skiplist *list, void *data)
 Insert an item into a skiplist. More...
 
int skiplist_empty (skiplist *list)
 Empty the skiplist of all data. More...
 
int skiplist_free (skiplist **list)
 Free all nodes (but not all data) in a skiplist This is similar to skiplist_empty(), but also free()'s the head node. More...
 
void * skiplist_peek (skiplist *list)
 Get the first item in the skiplist. More...
 
void * skiplist_pop (skiplist *list)
 Pop the first item from the skiplist. More...
 
void * skiplist_get_first (skiplist *list, void **node_ptr)
 Get first node of skiplist. More...
 
void * skiplist_get_next (void **node_ptr)
 Get next item from node_ptr. More...
 
void * skiplist_find_first (skiplist *list, void *data, void **node_ptr)
 Find first entry in skiplist matching data. More...
 
void * skiplist_find_next (skiplist *list, void *data, void **node_ptr)
 Find next entry in skiplist matching data. More...
 
int skiplist_delete (skiplist *list, void *data)
 Delete all items matching 'data' from skiplist. More...
 
int skiplist_delete_first (skiplist *list, void *data)
 Delete first item matching 'data' from skiplist. More...
 
int skiplist_delete_node (skiplist *list, void *node_ptr)
 Delete a particular node from the skiplist. More...
 

Detailed Description

Skiplist library functions.

http://en.wikipedia.org/wiki/Skiplist

Function Documentation

◆ skiplist_delete()

int skiplist_delete ( skiplist *  list,
void *  data 
)

Delete all items matching 'data' from skiplist.

Parameters
listThe list to delete from
dataComparison object used to find the real node
Returns
OK on success, ERROR on errors

◆ skiplist_delete_first()

int skiplist_delete_first ( skiplist *  list,
void *  data 
)

Delete first item matching 'data' from skiplist.

Parameters
listThe list to delete from
dataComparison object used to search the list
Returns
OK on success, ERROR on errors.

◆ skiplist_delete_node()

int skiplist_delete_node ( skiplist *  list,
void *  node_ptr 
)

Delete a particular node from the skiplist.

Parameters
listThe list to search
node_ptrThe node to delete
Returns
OK on success, ERROR on errors.

◆ skiplist_empty()

int skiplist_empty ( skiplist *  list)

Empty the skiplist of all data.

Parameters
listThe list to empty
Returns
ERROR on failures. OK on success

◆ skiplist_find_first()

void* skiplist_find_first ( skiplist *  list,
void *  data,
void **  node_ptr 
)

Find first entry in skiplist matching data.

Parameters
listThe list to search
dataComparison object used to search
[out]node_ptrState variable for future lookups with skiplist_find_next()
Returns
The first found data-item, of NULL if none could be found

◆ skiplist_find_next()

void* skiplist_find_next ( skiplist *  list,
void *  data,
void **  node_ptr 
)

Find next entry in skiplist matching data.

Parameters
listThe list to search
dataThe data to compare against
[out]node_ptrState var primed from earlier call to skiplist_find_next() or skiplist_find_first()
Returns
The next found data-item, or NULL if none could be found

◆ skiplist_free()

int skiplist_free ( skiplist **  list)

Free all nodes (but not all data) in a skiplist This is similar to skiplist_empty(), but also free()'s the head node.

Parameters
listThe list to free
Returns
OK on success, ERROR on failures

◆ skiplist_get_first()

void* skiplist_get_first ( skiplist *  list,
void **  node_ptr 
)

Get first node of skiplist.

Parameters
listThe list to search
[out]node_ptrState variable for skiplist_get_next()
Returns
The data-item of the first node on success, NULL on errors

◆ skiplist_get_next()

void* skiplist_get_next ( void **  node_ptr)

Get next item from node_ptr.

Parameters
[out]node_ptrState variable primed from an earlier call to skiplist_get_first() or skiplist_get_next()
Returns
The next data-item matching node_ptr on success, NULL on errors

◆ skiplist_insert()

int skiplist_insert ( skiplist *  list,
void *  data 
)

Insert an item into a skiplist.

Parameters
listThe list to insert to
dataThe data to insert
Returns
SKIPLIST_OK on success, or an error code

◆ skiplist_new()

skiplist* skiplist_new ( int  max_levels,
float  level_probability,
int  allow_duplicates,
int  append_duplicates,
int(*)(void *, void *)  compare_function 
)

Create a new skiplist.

Parameters
max_levelsNumber of "ups" we have. This Should be kept close to lg2 of the number of items to store.
level_probabilityIgnored
allow_duplicatesAllow duplicates in this list
append_duplicatesAppend rather than prepend duplicates
compare_functionComparison function for data entries
Returns
pointer to a new skiplist on success, NULL on errors

◆ skiplist_num_items()

unsigned long skiplist_num_items ( skiplist *  list)

Return number of items currently in the skiplist.

Parameters
listThe list to investigate
Returns
number of items in list

◆ skiplist_peek()

void* skiplist_peek ( skiplist *  list)

Get the first item in the skiplist.

Parameters
listThe list to peek into
Returns
The first item, or NULL if there is none

◆ skiplist_pop()

void* skiplist_pop ( skiplist *  list)

Pop the first item from the skiplist.

Parameters
listThe list to pop from