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.
skiplist * skiplist_new (int max_levels, float level_probability, int allow_duplicates, int append_duplicates, int(*compare_function)(void *, void *))
 Create a new skiplist.
int skiplist_insert (skiplist *list, void *data)
 Insert an item into a skiplist.
int skiplist_empty (skiplist *list)
 Empty the skiplist of all data.
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.
void * skiplist_peek (skiplist *list)
 Get the first item in the skiplist.
void * skiplist_pop (skiplist *list)
 Pop the first item from the skiplist.
void * skiplist_get_first (skiplist *list, void **node_ptr)
 Get first node of skiplist.
void * skiplist_get_next (void **node_ptr)
 Get next item from node_ptr.
void * skiplist_find_first (skiplist *list, void *data, void **node_ptr)
 Find first entry in skiplist matching data.
void * skiplist_find_next (skiplist *list, void *data, void **node_ptr)
 Find next entry in skiplist matching data.
int skiplist_delete (skiplist *list, void *data)
 Delete all items matching 'data' from skiplist.
int skiplist_delete_first (skiplist *list, void *data)
 Delete first item matching 'data' from skiplist.
int skiplist_delete_node (skiplist *list, void *node_ptr)
 Delete a particular node from the skiplist.

Detailed Description

Skiplist library functions.

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


Function Documentation

int skiplist_delete ( skiplist *  list,
void *  data 
)

Delete all items matching 'data' from skiplist.

Parameters:
list The list to delete from
data Comparison object used to find the real node
Returns:
OK on success, ERROR on errors
int skiplist_delete_first ( skiplist *  list,
void *  data 
)

Delete first item matching 'data' from skiplist.

Parameters:
list The list to delete from
data Comparison object used to search the list
Returns:
OK on success, ERROR on errors.
int skiplist_delete_node ( skiplist *  list,
void *  node_ptr 
)

Delete a particular node from the skiplist.

Parameters:
list The list to search
node_ptr The node to delete
Returns:
OK on success, ERROR on errors.
int skiplist_empty ( skiplist *  list  ) 

Empty the skiplist of all data.

Parameters:
list The list to empty
Returns:
ERROR on failures. OK on success
void* skiplist_find_first ( skiplist *  list,
void *  data,
void **  node_ptr 
)

Find first entry in skiplist matching data.

Parameters:
list The list to search
data Comparison object used to search
[out] node_ptr State variable for future lookups with skiplist_find_next()
Returns:
The first found data-item, of NULL if none could be found
void* skiplist_find_next ( skiplist *  list,
void *  data,
void **  node_ptr 
)

Find next entry in skiplist matching data.

Parameters:
list The list to search
data The data to compare against
[out] node_ptr State 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
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:
list The list to free
Returns:
OK on success, ERROR on failures
void* skiplist_get_first ( skiplist *  list,
void **  node_ptr 
)

Get first node of skiplist.

Parameters:
list The list to search
[out] node_ptr State variable for skiplist_get_next()
Returns:
The data-item of the first node on success, NULL on errors
void* skiplist_get_next ( void **  node_ptr  ) 

Get next item from node_ptr.

Parameters:
[out] node_ptr State 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
int skiplist_insert ( skiplist *  list,
void *  data 
)

Insert an item into a skiplist.

Parameters:
list The list to insert to
data The data to insert
Returns:
SKIPLIST_OK on success, or an error code
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_levels Number of "ups" we have. This Should be kept close to lg2 of the number of items to store.
level_probability Ignored
allow_duplicates Allow duplicates in this list
append_duplicates Append rather than prepend duplicates
compare_function Comparison function for data entries
Returns:
pointer to a new skiplist on success, NULL on errors
unsigned long skiplist_num_items ( skiplist *  list  ) 

Return number of items currently in the skiplist.

Parameters:
list The list to investigate
Returns:
number of items in list
void* skiplist_peek ( skiplist *  list  ) 

Get the first item in the skiplist.

Parameters:
list The list to peek into
Returns:
The first item, or NULL if there is none
void* skiplist_pop ( skiplist *  list  ) 

Pop the first item from the skiplist.

Parameters:
list The list to pop from
 All Data Structures Files Functions Variables Typedefs Defines

Generated on 5 Feb 2019 for Nagios by  doxygen 1.6.1