Rizin
unix-like reverse engineering framework and cli tools
rz_skiplist.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2016 Jeffrey Crowell
2 // SPDX-License-Identifier: BSD-3-Clause
3 
4 // Skiplists are a probabilistic datastructure than can be used as a k-v store
5 // with average case O(lg n) lookup time, and worst case O(n).
6 
7 // https://en.wikipedia.org/wiki/Skip_list
8 
9 #ifndef RZ_SKIP_LIST_H
10 #define RZ_SKIP_LIST_H
11 
12 #include <rz_list.h>
13 
14 typedef struct rz_skiplist_node_t {
15  void *data; // pointer to the value
16  struct rz_skiplist_node_t **forward; // forward pointer
18 
19 typedef struct rz_skiplist_t {
20  RzSkipListNode *head; // list header
21  int list_level; // current level of the list.
22  int size;
26 
31 RZ_API bool rz_skiplist_delete(RzSkipList *list, void *data);
39 RZ_API void *rz_skiplist_get_geq(RzSkipList *list, void *data);
40 RZ_API void *rz_skiplist_get_leq(RzSkipList *list, void *data);
43 
44 #define rz_skiplist_islast(list, el) (el->forward[0] == list->head)
45 
46 #define rz_skiplist_length(list) (list->size)
47 
48 #define rz_skiplist_foreach(list, it, pos) \
49  if (list) \
50  for (it = list->head->forward[0]; it != list->head && ((pos = it->data) || 1); it = it->forward[0])
51 
52 #define rz_skiplist_foreach_safe(list, it, tmp, pos) \
53  if (list) \
54  for (it = list->head->forward[0]; it != list->head && ((pos = it->data) || 1) && ((tmp = it->forward[0]) || 1); it = tmp)
55 
56 #endif // RZ_SKIP_LIST_H
#define RZ_API
static void freefn(HtName_(Ht) *ht, HT_(Kv) *kv)
Definition: ht_inc.c:46
static void list(RzEgg *egg)
Definition: rz-gg.c:52
int n
Definition: mipsasm.c:19
void(* RzListFree)(void *ptr)
Definition: rz_list.h:11
int(* RzListComparator)(const void *value, const void *list_data)
Definition: rz_list.h:33
RZ_API void * rz_skiplist_get_n(RzSkipList *list, int n)
Definition: skiplist.c:257
RZ_API bool rz_skiplist_delete_node(RzSkipList *list, RzSkipListNode *node)
Definition: skiplist.c:206
RZ_API void * rz_skiplist_get_geq(RzSkipList *list, void *data)
Definition: skiplist.c:273
RZ_API RzSkipListNode * rz_skiplist_find(RzSkipList *list, void *data)
Definition: skiplist.c:210
RZ_API bool rz_skiplist_delete(RzSkipList *list, void *data)
Definition: skiplist.c:201
RZ_API void * rz_skiplist_get_first(RzSkipList *list)
Definition: skiplist.c:248
RZ_API void rz_skiplist_purge(RzSkipList *list)
Definition: skiplist.c:128
RZ_API void * rz_skiplist_get_leq(RzSkipList *list, void *data)
Definition: skiplist.c:278
RZ_API RzList * rz_skiplist_to_list(RzSkipList *list)
Definition: skiplist.c:292
RZ_API RzSkipList * rz_skiplist_new(RzListFree freefn, RzListComparator comparefn)
Definition: skiplist.c:107
RZ_API void rz_skiplist_join(RzSkipList *l1, RzSkipList *l2)
Definition: skiplist.c:236
RZ_API RzSkipListNode * rz_skiplist_find_geq(RzSkipList *list, void *data)
Definition: skiplist.c:218
RZ_API RzSkipListNode * rz_skiplist_find_leq(RzSkipList *list, void *data)
Definition: skiplist.c:223
struct rz_skiplist_node_t RzSkipListNode
RZ_API bool rz_skiplist_empty(RzSkipList *list)
Definition: skiplist.c:284
RZ_API void rz_skiplist_free(RzSkipList *list)
Definition: skiplist.c:145
RZ_API RzSkipListNode * rz_skiplist_insert(RzSkipList *list, void *data)
Definition: skiplist.c:156
struct rz_skiplist_t RzSkipList
struct rz_skiplist_node_t ** forward
Definition: rz_skiplist.h:16
RzListComparator compare
Definition: rz_skiplist.h:24
RzSkipListNode * head
Definition: rz_skiplist.h:20
RzListFree freefn
Definition: rz_skiplist.h:23