diff --git a/HISTORY b/HISTORY index 295c743..4291d65 100644 --- a/HISTORY +++ b/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 diff --git a/src/flat_skiplist.h b/src/flat_skiplist.h index 4d0adc8..8a064e2 100644 --- a/src/flat_skiplist.h +++ b/src/flat_skiplist.h @@ -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; diff --git a/src/multi_skiplist.h b/src/multi_skiplist.h index 3cf7acd..8ae9d7d 100644 --- a/src/multi_skiplist.h +++ b/src/multi_skiplist.h @@ -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; diff --git a/src/skiplist_common.h b/src/skiplist_common.h index d5d5a79..4b2df68 100644 --- a/src/skiplist_common.h +++ b/src/skiplist_common.h @@ -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 diff --git a/src/skiplist_set.h b/src/skiplist_set.h index abe23f2..a48e074 100644 --- a/src/skiplist_set.h +++ b/src/skiplist_set.h @@ -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;