From a35ef2f031eb0c842060953fc0e3038352dcc6dc Mon Sep 17 00:00:00 2001 From: pcrsmk28o <2295746105@qq.com> Date: Sat, 18 Feb 2023 21:43:38 +0800 Subject: [PATCH] ADD file via upload --- skiplist.h | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 skiplist.h diff --git a/skiplist.h b/skiplist.h new file mode 100644 index 0000000..da1db7c --- /dev/null +++ b/skiplist.h @@ -0,0 +1,69 @@ +#ifndef __SKIPLIST_H__ + +#define __SKIPLIST_H__ + +#include + +#define SKIPLIST_ALLOC_MEM(size) malloc((size)) + +#define SKIPLIST_FREE_MEM(ptr) free((ptr)) + +#define SKIPLIST_RAND() rand() + +#define SKIPLIST_RAND_MAX RAND_MAX + +enum SKIPLIST_ELOG{ + SKIPLISTOK, + SKIPLISTOK_EXIST = SKIPLISTOK, + SKIPLISTERR, + SKIPLISTERR_PARAM, + SKIPLISTERR_POINTR, + SKIPLISTERR_REEXIST, + SKIPLISTERR_NOEXIST, +}; + +typedef struct skiplist_t skiplist_t; +typedef struct skiplist_node_t skiplist_node_t; +typedef struct skiplist_level_t skiplist_level_t; +typedef double skiplist_probability_t; +typedef skiplist_node_t* skiplist_iterator_t; + +typedef int (*skiplist_cmp)(void* key,void* skiplist_data); + +typedef unsigned int skiplist_size_t; + +int skiplist_create(skiplist_t** sl,skiplist_probability_t probability,skiplist_cmp cmp); + +int skiplist_size(skiplist_t* sl,skiplist_size_t* size); + +int skiplist_getcmp(skiplist_t* sl,skiplist_cmp* cmp); + +int skiplist_insert(skiplist_t* sl,void* key,void* data); + +int skiplist_erase(skiplist_t* sl,void* key,void** retdata); + +int skiplist_exist(skiplist_t* sl,void* key,void** retdata); + +int skiplist_update(skiplist_t* sl,void* oldkey,void* newkey,void* newdata,void** retdata); + +int skiplist_destroy(skiplist_t** sl); + +int skiplist_begin(skiplist_t* sl,skiplist_iterator_t* it); + +int skiplist_end(skiplist_t* sl,skiplist_iterator_t* it); + +int skiplist_iterator_create(skiplist_iterator_t* it); + +int skiplist_iterator_equal(skiplist_iterator_t* it1,skiplist_iterator_t* it2); + +void skiplist_iterator_assign(skiplist_iterator_t* dit,const skiplist_iterator_t* sit); + +const void* skiplist_iterator_value(skiplist_iterator_t* it); + +void skiplist_iterator_next(skiplist_iterator_t* it); + +void skiplist_iterator_prev(skiplist_iterator_t* it); + +void skiplist_iterator_destroy(skiplist_iterator_t* it); + +#endif