28#ifndef LIBDICT_SKIPLIST_H__
29#define LIBDICT_SKIPLIST_H__
113 size_t counts[],
size_t ncounts);
int(* dict_compare_func)(const void *, const void *)
A pointer to a function that compares two keys.
void(* dict_delete_func)(void *, void *)
A pointer to a function that is called when a key-value pair gets removed from a dictionary.
bool(* dict_visit_func)(const void *, void *, void *)
A pointer to a function used for iterating over dictionary contents.
bool skiplist_itor_search_le(skiplist_itor *itor, const void *key)
Position |itor| on the greatest key less than or equal to |key| and return true, or unposition it and...
size_t skiplist_traverse(skiplist *list, dict_visit_func visit, void *user_data)
Call |visit|(key, datum, |user_data|) for each element in key order, stopping early if |visit| return...
skiplist * skiplist_new(dict_compare_func cmp_func, unsigned max_link)
Create an empty skip list that orders keys with |cmp_func| (must not be NULL).
bool skiplist_itor_search_gt(skiplist_itor *itor, const void *key)
Position |itor| on the least key greater than |key| and return true, or unposition it and return fals...
bool skiplist_itor_remove(skiplist_itor *itor)
Remove the element |itor| is positioned on and unposition |itor|; return false if it was not position...
void ** skiplist_search_le(skiplist *list, const void *key)
Return the address of the datum of the greatest key less than or equal to |key|, or NULL if there is ...
void ** skiplist_search(skiplist *list, const void *key)
Return the address of the datum stored for |key|, or NULL if |key| is not present.
bool skiplist_itor_search(skiplist_itor *itor, const void *key)
Position |itor| on |key| and return true, or unposition it and return false if |key| is not present.
bool skiplist_verify(const skiplist *list)
Check the internal invariants of the list and return true if they hold, or print the first failed che...
bool skiplist_itor_first(skiplist_itor *itor)
Position |itor| on the first element in key order and return true, or unposition it and return false ...
int skiplist_itor_compare(const skiplist_itor *it1, const skiplist_itor *it2)
Compare the positions of two iterators over the same list: return a negative value,...
bool skiplist_itor_next(skiplist_itor *itor)
Move |itor| to the next element in key order and return true, or unposition it and return false if th...
bool skiplist_itor_prevn(skiplist_itor *itor, size_t count)
Move |itor| |count| elements back and return whether it is still positioned.
size_t skiplist_free(skiplist *list, dict_delete_func delete_func)
Remove every element, calling |delete_func|(key, datum) for each unless |delete_func| is NULL,...
void skiplist_itor_invalidate(skiplist_itor *itor)
Unposition |itor|, so that it is not positioned on any element.
const void * skiplist_itor_key(const skiplist_itor *itor)
Return the key |itor| is positioned on, or NULL if it is not positioned.
void ** skiplist_search_gt(skiplist *list, const void *key)
Return the address of the datum of the least key greater than |key|, or NULL if there is none.
bool skiplist_itor_search_lt(skiplist_itor *itor, const void *key)
Position |itor| on the greatest key less than |key| and return true, or unposition it and return fals...
bool skiplist_itor_valid(const skiplist_itor *itor)
Return whether |itor| is positioned on an element.
dict * skiplist_dict_new(dict_compare_func cmp_func, unsigned max_link)
Like skiplist_new(), but wrapped in a generic dict for use with the dict_* macros.
void ** skiplist_search_ge(skiplist *list, const void *key)
Return the address of the datum of the least key greater than or equal to |key|, or NULL if there is ...
bool skiplist_itor_search_ge(skiplist_itor *itor, const void *key)
Position |itor| on the least key greater than or equal to |key| and return true, or unposition it and...
void ** skiplist_itor_datum(skiplist_itor *itor)
Return the address of the datum |itor| is positioned on, through which it can be read or replaced,...
dict_itor * skiplist_dict_itor_new(skiplist *list)
Like skiplist_itor_new(), but wrapped in a generic dict_itor for use with the dict_itor_* macros.
void ** skiplist_search_lt(skiplist *list, const void *key)
Return the address of the datum of the greatest key less than |key|, or NULL if there is none.
void skiplist_itor_free(skiplist_itor *itor)
Free an iterator.
dict_insert_result skiplist_insert(skiplist *list, void *key)
Insert |key| unless an equal key is present.
bool skiplist_itor_nextn(skiplist_itor *itor, size_t count)
Move |itor| |count| elements forward and return whether it is still positioned.
skiplist_itor * skiplist_itor_new(skiplist *list)
Create an iterator over |list| that is not positioned on any element yet.
size_t skiplist_clear(skiplist *list, dict_delete_func delete_func)
Remove every element, calling |delete_func|(key, datum) for each unless |delete_func| is NULL.
size_t skiplist_count(const skiplist *list)
Return the number of elements.
dict_remove_result skiplist_remove(skiplist *list, const void *key)
Remove the element with key |key|.
bool skiplist_itor_last(skiplist_itor *itor)
Position |itor| on the last element in key order and return true, or unposition it and return false i...
size_t skiplist_link_count_histogram(const skiplist *list, size_t counts[], size_t ncounts)
Compute the histogram of link counts of the skiplist.
bool skiplist_itor_prev(skiplist_itor *itor)
Move |itor| to the previous element in key order and return true, or unposition it and return false i...
dict_compare_func cmp_func