add function skiplist_get_proper_level
parent
0aab6a0531
commit
fa8f93b018
2
HISTORY
2
HISTORY
|
|
@ -1,5 +1,5 @@
|
|||
|
||||
Version 1.44 2020-09-30
|
||||
Version 1.44 2020-10-10
|
||||
* add test file src/tests/test_pthread_lock.c
|
||||
* add uniq_skiplist.[hc]
|
||||
* add function split_string_ex
|
||||
|
|
|
|||
|
|
@ -85,6 +85,15 @@ static inline void *flat_skiplist_next(FlatSkiplistIterator *iterator)
|
|||
return data;
|
||||
}
|
||||
|
||||
static inline void *flat_skiplist_get_first(FlatSkiplist *sl)
|
||||
{
|
||||
if (sl->top->links[0] != sl->tail) {
|
||||
return sl->top->links[0]->data;
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static inline bool flat_skiplist_empty(FlatSkiplist *sl)
|
||||
{
|
||||
return sl->top->links[0] == sl->tail;
|
||||
|
|
|
|||
|
|
@ -110,6 +110,15 @@ static inline void *multi_skiplist_next(MultiSkiplistIterator *iterator)
|
|||
return data;
|
||||
}
|
||||
|
||||
static inline void *multi_skiplist_get_first(MultiSkiplist *sl)
|
||||
{
|
||||
if (sl->top->links[0] != sl->tail) {
|
||||
return sl->top->links[0]->head->data;
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static inline bool multi_skiplist_empty(MultiSkiplist *sl)
|
||||
{
|
||||
return sl->top->links[0] == sl->tail;
|
||||
|
|
|
|||
|
|
@ -21,6 +21,31 @@
|
|||
typedef int (*skiplist_compare_func)(const void *p1, const void *p2);
|
||||
typedef void (*skiplist_free_func)(void *ptr);
|
||||
|
||||
static inline int skiplist_get_proper_level(const int target_count)
|
||||
{
|
||||
if (target_count < 8) {
|
||||
return 2;
|
||||
} else if (target_count < 64) {
|
||||
return 4;
|
||||
} else if (target_count < 256) {
|
||||
return 6;
|
||||
} else if (target_count < 1024) {
|
||||
return 8;
|
||||
} else if (target_count < 4096) {
|
||||
return 10;
|
||||
} else if (target_count < 16 * 1024) {
|
||||
return 12;
|
||||
} else if (target_count < 64 * 1024) {
|
||||
return 14;
|
||||
} else if (target_count < 256 * 1024) {
|
||||
return 16;
|
||||
} else if (target_count < 1024 * 1024) {
|
||||
return 18;
|
||||
} else {
|
||||
return 20;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -81,6 +81,15 @@ static inline void *skiplist_set_next(SkiplistSetIterator *iterator)
|
|||
return data;
|
||||
}
|
||||
|
||||
static inline void *skiplist_set_get_first(SkiplistSet *sl)
|
||||
{
|
||||
if (sl->top->links[0] != sl->tail) {
|
||||
return sl->top->links[0]->data;
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static inline bool skiplist_set_empty(SkiplistSet *sl)
|
||||
{
|
||||
return sl->top->links[0] == sl->tail;
|
||||
|
|
|
|||
Loading…
Reference in New Issue