]>
git.proxmox.com Git - mirror_frr.git/blob - lib/skiplist.h
2 * Copyright 1990 William Pugh
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted.
7 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS''
8 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
9 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
10 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR
11 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
12 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
13 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
14 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
15 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
16 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
17 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
20 * Permission to include in quagga provide on March 31, 2016
24 * Skip List implementation based on code from William Pugh.
25 * ftp://ftp.cs.umd.edu/pub/skipLists/
31 #ifndef _ZEBRA_SKIPLIST_H
32 #define _ZEBRA_SKIPLIST_H
38 #define SKIPLIST_0TIMER_DEBUG 1
41 * skiplistnodes must always contain data to be valid. Adding an
42 * empty node to a list is invalid
47 #if SKIPLIST_0TIMER_DEBUG
49 #define SKIPLIST_NODE_FLAG_INSERTED 0x00000001
52 struct skiplistnode
*forward
[1]; /* variable sized */
58 #define SKIPLIST_FLAG_ALLOW_DUPLICATES 0x00000001
60 int level
; /* max lvl (1 + current # of levels in list) */
62 struct skiplistnode
*header
;
65 *last
; /* last real list item (NULL if empty list) */
68 * Returns -1 if val1 < val2, 0 if equal?, 1 if val1 > val2.
69 * Used as definition of sorted for listnode_add_sort
71 int (*cmp
)(const void *val1
, const void *val2
);
73 /* callback to free user-owned data when listnode is deleted. supplying
74 * this callback is very much encouraged!
76 void (*del
)(void *val
);
81 extern struct skiplist
*
82 skiplist_new(/* encouraged: set list.del callback on new lists */
84 int (*cmp
)(const void *key1
,
85 const void *key2
), /* NULL => default cmp */
86 void (*del
)(void *val
)); /* NULL => no auto val free */
88 extern void skiplist_free(struct skiplist
*);
90 extern int skiplist_insert(register struct skiplist
*l
, register void *key
,
91 register void *value
);
93 extern int skiplist_delete(register struct skiplist
*l
, register void *key
,
94 register void *value
);
96 extern int skiplist_search(register struct skiplist
*l
, register void *key
,
99 extern int skiplist_first_value(register struct skiplist
*l
, /* in */
100 register const void *key
, /* in */
101 void **valuePointer
, /* in/out */
102 void **cursor
); /* out */
104 extern int skiplist_next_value(register struct skiplist
*l
, /* in */
105 register const void *key
, /* in */
106 void **valuePointer
, /* in/out */
107 void **cursor
); /* in/out */
109 extern int skiplist_first(register struct skiplist
*l
, void **keyPointer
,
110 void **valuePointer
);
112 extern int skiplist_last(register struct skiplist
*l
, void **keyPointer
,
113 void **valuePointer
);
115 extern int skiplist_delete_first(register struct skiplist
*l
);
117 extern int skiplist_next(register struct skiplist
*l
, /* in */
118 void **keyPointer
, /* out */
119 void **valuePointer
, /* out */
120 void **cursor
); /* in/out */
122 extern int skiplist_empty(register struct skiplist
*l
); /* in */
124 extern unsigned int skiplist_count(register struct skiplist
*l
); /* in */
127 extern void skiplist_debug(struct vty
*vty
, struct skiplist
*l
);
129 extern void skiplist_test(struct vty
*vty
);
135 #endif /* _ZEBRA_SKIPLIST_H */