cctools
skip_list.h
Go to the documentation of this file.
1/* Copyright (C) 2022 The University of Notre Dame
2This software is distributed under the GNU General Public License.
3See the file COPYING for details.
4*/
5
6#ifndef SKIP_LIST_H
7#define SKIP_LIST_H
8
9#include <stdint.h>
10#include <stdbool.h>
11
54struct skip_list;
55struct skip_list_cursor;
56
64struct skip_list *skip_list_create(unsigned priority_size, double probability);
65
73bool skip_list_delete(struct skip_list *sl);
74
79int skip_list_size(struct skip_list *sl);
80
85const double *skip_list_peek_head_priority(struct skip_list *sl);
86
91const void *skip_list_peek_head(struct skip_list *sl);
92
97void *skip_list_pop_head(struct skip_list *sl);
98
103struct skip_list_cursor *skip_list_cursor_create(struct skip_list *sl);
104
108void skip_list_cursor_delete(struct skip_list_cursor *cur);
109
114struct skip_list_cursor *skip_list_cursor_clone(struct skip_list_cursor *cur);
115
121void skip_list_cursor_move(struct skip_list_cursor *to_move, struct skip_list_cursor *destination);
122
126void skip_list_reset(struct skip_list_cursor *cur);
127
134bool skip_list_seek(struct skip_list_cursor *cur, int index);
135
142bool skip_list_tell(struct skip_list_cursor *cur, unsigned *index);
143
149bool skip_list_next(struct skip_list_cursor *cur);
150
156bool skip_list_prev(struct skip_list_cursor *cur);
157
166bool skip_list_cursor_move_to_priority_arr(struct skip_list_cursor *cur, double *priority);
167
176#define skip_list_cursor_move_to_priority(cur, ...) \
177 skip_list_cursor_move_to_priority_arr(cur, (double[]){__VA_ARGS__})
178
185bool skip_list_get(struct skip_list_cursor *cur, void **item);
186
191const double *skip_list_get_priority(struct skip_list_cursor *cur);
192
199bool skip_list_set(struct skip_list_cursor *cur, void *item);
200
206bool skip_list_remove_here(struct skip_list_cursor *cur);
207
214bool skip_list_remove(struct skip_list *sl, void *data);
215
223bool skip_list_remove_by_priority_arr(struct skip_list *sl, double *priority);
224
232#define skip_list_remove_by_priority(sl, ...) \
233 skip_list_remove_by_priority_arr(sl, (double[]){__VA_ARGS__})
234
242void skip_list_insert_arr(struct skip_list *lst, void *item, double *priority);
243
258#define skip_list_insert(lst, item, ...) \
259 skip_list_insert_arr(lst, item, (double[]){__VA_ARGS__})
260
261
296#define SKIP_LIST_ITERATE(cursor, item) \
297 for(; skip_list_get(cursor, (void **)&item); skip_list_next(cursor))
298
299#endif
bool skip_list_remove_here(struct skip_list_cursor *cur)
Remove the item under the cursor.
bool skip_list_tell(struct skip_list_cursor *cur, unsigned *index)
Get the position of a cursor within a skip list.
const double * skip_list_get_priority(struct skip_list_cursor *cur)
Get the priority tuple of the item under a cursor.
const void * skip_list_peek_head(struct skip_list *sl)
Get the first item in the skip list without removing it.
struct skip_list_cursor * skip_list_cursor_create(struct skip_list *sl)
Create a cursor for traversing a skip list.
void * skip_list_pop_head(struct skip_list *sl)
Remove and return the first item in the skip list.
struct skip_list * skip_list_create(unsigned priority_size, double probability)
Create an empty skip list with priority-based sorting.
bool skip_list_remove(struct skip_list *sl, void *data)
Remove the first node found with the given data pointer.
const double * skip_list_peek_head_priority(struct skip_list *sl)
Get the priority tuple of the first item in the skip list.
void skip_list_reset(struct skip_list_cursor *cur)
Reset the position of a cursor.
int skip_list_size(struct skip_list *sl)
Get the number of items in a skip list.
bool skip_list_seek(struct skip_list_cursor *cur, int index)
Move a cursor to an item by index.
void skip_list_insert_arr(struct skip_list *lst, void *item, double *priority)
Insert an item with priority into the skip list (internal function).
bool skip_list_next(struct skip_list_cursor *cur)
Move a cursor to the next item.
struct skip_list_cursor * skip_list_cursor_clone(struct skip_list_cursor *cur)
Get a copy of an existing cursor.
bool skip_list_remove_by_priority_arr(struct skip_list *sl, double *priority)
Remove the first node found with the given priority tuple.
bool skip_list_set(struct skip_list_cursor *cur, void *item)
Set the value under the cursor.
bool skip_list_prev(struct skip_list_cursor *cur)
Move a cursor to the previous item.
void skip_list_cursor_delete(struct skip_list_cursor *cur)
Delete a previously created cursor.
bool skip_list_cursor_move_to_priority_arr(struct skip_list_cursor *cur, double *priority)
Move a cursor to the first item with the given priority tuple (internal function).
bool skip_list_delete(struct skip_list *sl)
Delete a skip list.
void skip_list_cursor_move(struct skip_list_cursor *to_move, struct skip_list_cursor *destination)
Move a cursor's position to match another cursor.
bool skip_list_get(struct skip_list_cursor *cur, void **item)
Get the item under a cursor.