diff --git a/HISTORY b/HISTORY index 8b0a6db..d9f91bd 100644 --- a/HISTORY +++ b/HISTORY @@ -1,5 +1,5 @@ -Version 1.44 2020-03-31 +Version 1.44 2020-04-22 * add test file src/tests/test_pthread_lock.c * add uniq_skiplist.[hc] * add function split_string_ex @@ -25,6 +25,7 @@ Version 1.44 2020-03-31 * add functions getIpAndPort and getPeerIpAndPort * bugfixed: call fast_mblock_destroy in common_blocked_queue_destroy * add function fc_get_file_line_count_ex + * uniq_skiplist add function find_ge and support bidirection Version 1.43 2019-12-25 * replace function call system to getExecResult, diff --git a/src/hash.c b/src/hash.c index c4fdacb..2f8d524 100644 --- a/src/hash.c +++ b/src/hash.c @@ -1300,7 +1300,7 @@ int calc_hashnr1_ex(const void* key, const int key_len, \ \ h = init_value; \ pEnd = (unsigned char *)key + key_len; \ - for (p = (unsigned char *)key; p!= pEnd; p++) \ + for (p = (unsigned char *)key; p != pEnd; p++) \ { \ h = 31 * h + *p; \ } \ diff --git a/src/uniq_skiplist.c b/src/uniq_skiplist.c index b8f3594..78b4b6a 100644 --- a/src/uniq_skiplist.c +++ b/src/uniq_skiplist.c @@ -42,7 +42,7 @@ static void init_best_element_counts() } } -int uniq_skiplist_init_ex(UniqSkiplistFactory *factory, +int uniq_skiplist_init_ex2(UniqSkiplistFactory *factory, const int max_level_count, skiplist_compare_func compare_func, uniq_skiplist_free_func free_func, const int alloc_skiplist_once, const int min_alloc_elements_once, const int delay_free_seconds, diff --git a/src/uniq_skiplist.h b/src/uniq_skiplist.h index c92a320..83550ad 100644 --- a/src/uniq_skiplist.h +++ b/src/uniq_skiplist.h @@ -58,12 +58,19 @@ extern "C" { #define uniq_skiplist_count(sl) (sl)->element_count +#define uniq_skiplist_init_ex(factory, max_level_count, compare_func, \ + free_func, alloc_skiplist_once, min_alloc_elements_once, \ + 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) \ + #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, false) + SKIPLIST_DEFAULT_MIN_ALLOC_ELEMENTS_ONCE, 0) -int uniq_skiplist_init_ex(UniqSkiplistFactory *factory, +int uniq_skiplist_init_ex2(UniqSkiplistFactory *factory, const int max_level_count, skiplist_compare_func compare_func, uniq_skiplist_free_func free_func, const int alloc_skiplist_once, const int min_alloc_elements_once, const int delay_free_seconds, @@ -146,9 +153,16 @@ static inline bool uniq_skiplist_empty(UniqSkiplist *sl) return sl->top->links[0] == sl->factory->tail; } -#define LEVEL0_DOUBLE_CHAIN_PREV_LINK(node) node->links[node->level_index + 1] +#define LEVEL0_DOUBLE_CHAIN_NEXT_LINK(node) node->links[0] +#define LEVEL0_DOUBLE_CHAIN_PREV_LINK(node) node->links[node->level_index + 1] #define LEVEL0_DOUBLE_CHAIN_TAIL(sl) LEVEL0_DOUBLE_CHAIN_PREV_LINK(sl->top) +#define UNIQ_SKIPLIST_LEVEL0_PREV_NODE(node) ((UniqSkiplistNode *) \ + LEVEL0_DOUBLE_CHAIN_PREV_LINK(node)) + +#define UNIQ_SKIPLIST_LEVEL0_NEXT_NODE(node) ((UniqSkiplistNode *) \ + LEVEL0_DOUBLE_CHAIN_NEXT_LINK(node)) + #ifdef __cplusplus } #endif