add uniq_skiplist_pair struct and init function
parent
04226e28fc
commit
88aa31df07
3
HISTORY
3
HISTORY
|
|
@ -1,6 +1,7 @@
|
|||
|
||||
Version 1.49 2021-03-10
|
||||
Version 1.49 2021-03-15
|
||||
* add macros: FC_ABS and FC_NEGATIVE
|
||||
* uniq_skiplist.c: add uniq_skiplist_pair struct and init function
|
||||
|
||||
Version 1.48 2021-02-01
|
||||
* fast_buffer.[hc]: add function fast_buffer_append_binary
|
||||
|
|
|
|||
|
|
@ -117,7 +117,7 @@ int uniq_skiplist_init_ex2(UniqSkiplistFactory *factory,
|
|||
if ((result=fast_mblock_init_ex1(&factory->skiplist_allocator,
|
||||
"skiplist", sizeof(UniqSkiplist),
|
||||
alloc_skiplist_once > 0 ? alloc_skiplist_once :
|
||||
16 * 1024, alloc_elements_limit, NULL, NULL, false)) != 0)
|
||||
4 * 1024, alloc_elements_limit, NULL, NULL, false)) != 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,6 +54,11 @@ typedef struct uniq_skiplist
|
|||
UniqSkiplistNode *top; //the top node
|
||||
} UniqSkiplist;
|
||||
|
||||
typedef struct uniq_skiplist_pair {
|
||||
UniqSkiplistFactory factory;
|
||||
struct uniq_skiplist *skiplist;
|
||||
} UniqSkiplistPair;
|
||||
|
||||
typedef struct uniq_skiplist_iterator {
|
||||
volatile UniqSkiplistNode *current;
|
||||
volatile UniqSkiplistNode *tail;
|
||||
|
|
@ -70,13 +75,19 @@ extern "C" {
|
|||
delay_free_seconds) \
|
||||
uniq_skiplist_init_ex2(factory, max_level_count, compare_func, \
|
||||
free_func, alloc_skiplist_once, min_alloc_elements_once, \
|
||||
delay_free_seconds, false) \
|
||||
delay_free_seconds, false)
|
||||
|
||||
#define uniq_skiplist_init(factory, max_level_count, compare_func, free_func) \
|
||||
uniq_skiplist_init_ex(factory, max_level_count, \
|
||||
compare_func, free_func, 64 * 1024, \
|
||||
SKIPLIST_DEFAULT_MIN_ALLOC_ELEMENTS_ONCE, 0)
|
||||
|
||||
#define uniq_skiplist_init_pair(pair, init_level_count, max_level_count, \
|
||||
compare_func, free_func, min_alloc_elements_once, delay_free_seconds) \
|
||||
uniq_skiplist_init_pair_ex(pair, init_level_count, max_level_count, \
|
||||
compare_func, free_func, min_alloc_elements_once, \
|
||||
delay_free_seconds, false)
|
||||
|
||||
#define uniq_skiplist_delete(sl, data) \
|
||||
uniq_skiplist_delete_ex(sl, data, true)
|
||||
|
||||
|
|
@ -100,6 +111,33 @@ UniqSkiplist *uniq_skiplist_new(UniqSkiplistFactory *factory,
|
|||
|
||||
void uniq_skiplist_free(UniqSkiplist *sl);
|
||||
|
||||
static inline int uniq_skiplist_init_pair_ex(UniqSkiplistPair *pair,
|
||||
const int init_level_count, const int max_level_count,
|
||||
skiplist_compare_func compare_func, uniq_skiplist_free_func
|
||||
free_func, const int min_alloc_elements_once,
|
||||
const int delay_free_seconds, const bool bidirection)
|
||||
{
|
||||
const int alloc_skiplist_once = 1;
|
||||
int result;
|
||||
|
||||
if ((result=uniq_skiplist_init_ex2(&pair->factory, max_level_count,
|
||||
compare_func, free_func, alloc_skiplist_once,
|
||||
min_alloc_elements_once, delay_free_seconds,
|
||||
bidirection)) != 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
if ((pair->skiplist=uniq_skiplist_new(&pair->factory,
|
||||
init_level_count)) == NULL)
|
||||
{
|
||||
uniq_skiplist_destroy(&pair->factory);
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int uniq_skiplist_insert(UniqSkiplist *sl, void *data);
|
||||
int uniq_skiplist_delete_ex(UniqSkiplist *sl, void *data,
|
||||
const bool need_free);
|
||||
|
|
|
|||
Loading…
Reference in New Issue