Apache Portable Runtime
Typedefs | Functions
Skip list implementation

Typedefs

typedef int(* apr_skiplist_compare) (void *, void *)
 
typedef void(* apr_skiplist_freefunc) (void *)
 
typedef struct apr_skiplist apr_skiplist
 
typedef struct apr_skiplistnode apr_skiplistnode
 

Functions

void * apr_skiplist_alloc (apr_skiplist *sl, size_t size)
 
void apr_skiplist_free (apr_skiplist *sl, void *mem)
 
apr_status_t apr_skiplist_init (apr_skiplist **sl, apr_pool_t *p)
 
void apr_skiplist_set_compare (apr_skiplist *sl, apr_skiplist_compare XXX1, apr_skiplist_compare XXX2)
 
void apr_skiplist_add_index (apr_skiplist *sl, apr_skiplist_compare XXX1, apr_skiplist_compare XXX2)
 
apr_skiplistnodeapr_skiplist_getlist (apr_skiplist *sl)
 
void * apr_skiplist_find_compare (apr_skiplist *sl, void *data, apr_skiplistnode **iter, apr_skiplist_compare func)
 
void * apr_skiplist_find (apr_skiplist *sl, void *data, apr_skiplistnode **iter)
 
void * apr_skiplist_last_compare (apr_skiplist *sli, void *data, apr_skiplistnode **iter, apr_skiplist_compare comp)
 
void * apr_skiplist_last (apr_skiplist *sl, void *data, apr_skiplistnode **iter)
 
void * apr_skiplist_next (apr_skiplist *sl, apr_skiplistnode **iter)
 
void * apr_skiplist_previous (apr_skiplist *sl, apr_skiplistnode **iter)
 
void * apr_skiplist_element (apr_skiplistnode *iter)
 
apr_skiplistnodeapr_skiplist_insert_compare (apr_skiplist *sl, void *data, apr_skiplist_compare comp)
 
apr_skiplistnodeapr_skiplist_insert (apr_skiplist *sl, void *data)
 
apr_skiplistnodeapr_skiplist_add_compare (apr_skiplist *sl, void *data, apr_skiplist_compare comp)
 
apr_skiplistnodeapr_skiplist_add (apr_skiplist *sl, void *data)
 
apr_skiplistnodeapr_skiplist_replace_compare (apr_skiplist *sl, void *data, apr_skiplist_freefunc myfree, apr_skiplist_compare comp)
 
apr_skiplistnodeapr_skiplist_replace (apr_skiplist *sl, void *data, apr_skiplist_freefunc myfree)
 
int apr_skiplist_remove_node (apr_skiplist *sl, apr_skiplistnode *iter, apr_skiplist_freefunc myfree)
 
int apr_skiplist_remove_compare (apr_skiplist *sl, void *data, apr_skiplist_freefunc myfree, apr_skiplist_compare comp)
 
int apr_skiplist_remove (apr_skiplist *sl, void *data, apr_skiplist_freefunc myfree)
 
void apr_skiplist_remove_all (apr_skiplist *sl, apr_skiplist_freefunc myfree)
 
void apr_skiplist_destroy (apr_skiplist *sl, apr_skiplist_freefunc myfree)
 
void * apr_skiplist_pop (apr_skiplist *sl, apr_skiplist_freefunc myfree)
 
void * apr_skiplist_peek (apr_skiplist *sl)
 
size_t apr_skiplist_size (const apr_skiplist *sl)
 
int apr_skiplist_height (const apr_skiplist *sl)
 
int apr_skiplist_preheight (const apr_skiplist *sl)
 
void apr_skiplist_set_preheight (apr_skiplist *sl, int to)
 
apr_skiplistapr_skiplist_merge (apr_skiplist *sl1, apr_skiplist *sl2)
 

Detailed Description

Refer to http://en.wikipedia.org/wiki/Skip_list for information about the purpose of and ideas behind skip lists.

Typedef Documentation

typedef struct apr_skiplist apr_skiplist

Opaque structure used to represent the skip list

typedef int(* apr_skiplist_compare) (void *, void *)

apr_skiplist_compare is the function type that must be implemented per object type that is used in a skip list for comparisons to maintain order

typedef void(* apr_skiplist_freefunc) (void *)

apr_skiplist_freefunc is the function type that must be implemented to handle elements as they are removed from a skip list.

Opaque structure

Function Documentation

apr_skiplistnode* apr_skiplist_add ( apr_skiplist sl,
void *  data 
)

Add an element into the skip list using the existing comparison function allowing for duplicates.

Parameters
slThe skip list
dataThe element to insert
Remarks
If no comparison function has been set for the skip list, the element will not be inserted and NULL will be returned.
apr_skiplistnode* apr_skiplist_add_compare ( apr_skiplist sl,
void *  data,
apr_skiplist_compare  comp 
)

Add an element into the skip list using the specified comparison function allowing for duplicates.

Parameters
slThe skip list
dataThe element to add
compThe comparison function to use for placement into the skip list
void apr_skiplist_add_index ( apr_skiplist sl,
apr_skiplist_compare  XXX1,
apr_skiplist_compare  XXX2 
)

Set the indexing functions to the specified comparison functions and rebuild the index.

Parameters
slThe skip list
XXX1FIXME
XXX2FIXME
Remarks
If an index already exists, it will not be replaced and the comparison functions will not be changed.
void* apr_skiplist_alloc ( apr_skiplist sl,
size_t  size 
)

Allocate memory using the same mechanism as the skip list.

Parameters
slThe skip list
sizeThe amount to allocate
Remarks
If a pool was provided to apr_skiplist_init(), memory will be allocated from the pool or from a free list maintained with the skip list. Otherwise, memory will be allocated using the C standard library heap functions.
void apr_skiplist_destroy ( apr_skiplist sl,
apr_skiplist_freefunc  myfree 
)

Remove each element from the skip list.

Parameters
slThe skip list
myfreeA function to be called for each removed element
void* apr_skiplist_element ( apr_skiplistnode iter)

Return the element of the skip list node

Parameters
iterThe skip list node
void* apr_skiplist_find ( apr_skiplist sl,
void *  data,
apr_skiplistnode **  iter 
)

Return the next matching element in the skip list using the current comparison function.

Parameters
slThe skip list
dataThe value to search for
iterA pointer to the returned skip list node representing the element found
void* apr_skiplist_find_compare ( apr_skiplist sl,
void *  data,
apr_skiplistnode **  iter,
apr_skiplist_compare  func 
)

Return the next matching element in the skip list using the specified comparison function.

Parameters
slThe skip list
dataThe value to search for
iterA pointer to the returned skip list node representing the element found
funcThe comparison function to use
void apr_skiplist_free ( apr_skiplist sl,
void *  mem 
)

Free memory using the same mechanism as the skip list.

Parameters
slThe skip list
memThe object to free
Remarks
If a pool was provided to apr_skiplist_init(), memory will be added to a free list maintained with the skip list and be available to operations on the skip list or to other calls to apr_skiplist_alloc(). Otherwise, memory will be freed using the C standard library heap functions.
apr_skiplistnode* apr_skiplist_getlist ( apr_skiplist sl)

Return the list maintained by the skip list abstraction.

Parameters
slThe skip list
int apr_skiplist_height ( const apr_skiplist sl)

Return the height of the list (number of skip paths), in O(1).

Parameters
slThe skip list
apr_status_t apr_skiplist_init ( apr_skiplist **  sl,
apr_pool_t p 
)

Allocate a new skip list

Parameters
slThe pointer in which to return the newly created skip list
pThe pool from which to allocate the skip list (optional).
Remarks
Unlike most APR functions, a pool is optional. If no pool is provided, the C standard library heap functions will be used instead.
apr_skiplistnode* apr_skiplist_insert ( apr_skiplist sl,
void *  data 
)

Insert an element into the skip list using the existing comparison function if it does not already exist.

Parameters
slThe skip list
dataThe element to insert
Remarks
If no comparison function has been set for the skip list, the element will not be inserted and NULL will be returned.
apr_skiplistnode* apr_skiplist_insert_compare ( apr_skiplist sl,
void *  data,
apr_skiplist_compare  comp 
)

Insert an element into the skip list using the specified comparison function if it does not already exist.

Parameters
slThe skip list
dataThe element to insert
compThe comparison function to use for placement into the skip list
void* apr_skiplist_last ( apr_skiplist sl,
void *  data,
apr_skiplistnode **  iter 
)

Return the last matching element in the skip list using the current comparison function.

Parameters
slThe skip list
dataThe value to search for
iterA pointer to the returned skip list node representing the element found
void* apr_skiplist_last_compare ( apr_skiplist sli,
void *  data,
apr_skiplistnode **  iter,
apr_skiplist_compare  comp 
)

Return the last matching element in the skip list using the specified comparison function.

Parameters
slThe skip list
dataThe value to search for
iterA pointer to the returned skip list node representing the element found
funcThe comparison function to use
apr_skiplist* apr_skiplist_merge ( apr_skiplist sl1,
apr_skiplist sl2 
)

Merge two skip lists. XXX SEMANTICS

Parameters
sl1One of two skip lists to be merged
sl2The other of two skip lists to be merged
void* apr_skiplist_next ( apr_skiplist sl,
apr_skiplistnode **  iter 
)

Return the next element in the skip list.

Parameters
slThe skip list
iterOn entry, a pointer to the skip list node to start with; on return, a pointer to the skip list node representing the element returned
Remarks
If iter points to a NULL value on entry, NULL will be returned.
void* apr_skiplist_peek ( apr_skiplist sl)

Return the first element in the skip list, leaving the element in the skip list.

Parameters
slThe skip list
Remarks
NULL will be returned if there are no elements
void* apr_skiplist_pop ( apr_skiplist sl,
apr_skiplist_freefunc  myfree 
)

Return the first element in the skip list, removing the element from the skip list.

Parameters
slThe skip list
myfreeA function to be called for the removed element
Remarks
NULL will be returned if there are no elements
int apr_skiplist_preheight ( const apr_skiplist sl)

Return the predefined maximum height of the skip list.

Parameters
slThe skip list
void* apr_skiplist_previous ( apr_skiplist sl,
apr_skiplistnode **  iter 
)

Return the previous element in the skip list.

Parameters
slThe skip list
iterOn entry, a pointer to the skip list node to start with; on return, a pointer to the skip list node representing the element returned
Remarks
If iter points to a NULL value on entry, NULL will be returned.
int apr_skiplist_remove ( apr_skiplist sl,
void *  data,
apr_skiplist_freefunc  myfree 
)

Remove an element from the skip list using the existing comparison function for locating the element. In the case of duplicates, the 1st entry will be removed.

Parameters
slThe skip list
dataThe element to remove
myfreeA function to be called for each removed element
Remarks
If the element is not found, 0 will be returned. Otherwise, the heightXXX will be returned.
If no comparison function has been set for the skip list, the element will not be removed and 0 will be returned.
void apr_skiplist_remove_all ( apr_skiplist sl,
apr_skiplist_freefunc  myfree 
)

Remove all elements from the skip list.

Parameters
slThe skip list
myfreeA function to be called for each removed element
int apr_skiplist_remove_compare ( apr_skiplist sl,
void *  data,
apr_skiplist_freefunc  myfree,
apr_skiplist_compare  comp 
)

Remove an element from the skip list using the specified comparison function for locating the element. In the case of duplicates, the 1st entry will be removed.

Parameters
slThe skip list
dataThe element to remove
myfreeA function to be called for each removed element
compThe comparison function to use for placement into the skip list
Remarks
If the element is not found, 0 will be returned. Otherwise, the heightXXX will be returned.
int apr_skiplist_remove_node ( apr_skiplist sl,
apr_skiplistnode iter,
apr_skiplist_freefunc  myfree 
)

Remove a node from the skip list.

Parameters
slThe skip list
iterThe skip list node to remove
myfreeA function to be called for the removed element
apr_skiplistnode* apr_skiplist_replace ( apr_skiplist sl,
void *  data,
apr_skiplist_freefunc  myfree 
)

Add an element into the skip list using the existing comparison function removing the existing duplicates.

Parameters
slThe skip list
dataThe element to insert
myfreeA function to be called for each removed duplicate
Remarks
If no comparison function has been set for the skip list, the element will not be inserted, none will be replaced, and NULL will be returned.
apr_skiplistnode* apr_skiplist_replace_compare ( apr_skiplist sl,
void *  data,
apr_skiplist_freefunc  myfree,
apr_skiplist_compare  comp 
)

Add an element into the skip list using the specified comparison function removing the existing duplicates.

Parameters
slThe skip list
dataThe element to insert
compThe comparison function to use for placement into the skip list
myfreeA function to be called for each removed duplicate
Remarks
If no comparison function has been set for the skip list, the element will not be inserted, none will be replaced, and NULL will be returned.
void apr_skiplist_set_compare ( apr_skiplist sl,
apr_skiplist_compare  XXX1,
apr_skiplist_compare  XXX2 
)

Set the comparison functions to be used for searching the skip list.

Parameters
slThe skip list
XXX1FIXME
XXX2FIXME
Remarks
If existing comparison functions are being replaced, the index will be replaced during this call. That is a potentially expensive operation.
void apr_skiplist_set_preheight ( apr_skiplist sl,
int  to 
)

Set a predefined maximum height for the skip list.

Parameters
slThe skip list
toThe preheight to set, or a nul/negative value to disable.
Remarks
When a preheight is used, the height of each inserted element is computed randomly up to this preheight instead of the current skip list's height plus one used by the default implementation. Using a preheight can probably ensure more fairness with long living elements (since with an adaptative height, former elements may have been created with a low height, hence a longest path to reach them while the skip list grows). On the other hand, the default behaviour (preheight <= 0) with a growing and decreasing maximum height is more adaptative/suitable for short living values.
Note
Should be called before any insertion/add.
size_t apr_skiplist_size ( const apr_skiplist sl)

Return the size of the list (number of elements), in O(1).

Parameters
slThe skip list