xref: /openbsd/usr.sbin/smtpd/tree.h (revision d415bd75)
1 /*	$OpenBSD: tree.h,v 1.1 2018/12/23 16:06:24 gilles Exp $	*/
2 
3 /*
4  * Copyright (c) 2013 Eric Faurot <eric@openbsd.org>
5  * Copyright (c) 2011 Gilles Chehade <gilles@poolp.org>
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 #ifndef	_TREE_H_
21 #define	_TREE_H_
22 
23 SPLAY_HEAD(_tree, treeentry);
24 
25 struct tree {
26 	struct _tree	tree;
27 	size_t		count;
28 };
29 
30 
31 /* tree.c */
32 #define tree_init(t) do { SPLAY_INIT(&((t)->tree)); (t)->count = 0; } while(0)
33 #define tree_empty(t) SPLAY_EMPTY(&((t)->tree))
34 #define tree_count(t) ((t)->count)
35 int tree_check(struct tree *, uint64_t);
36 void *tree_set(struct tree *, uint64_t, void *);
37 void tree_xset(struct tree *, uint64_t, void *);
38 void *tree_get(struct tree *, uint64_t);
39 void *tree_xget(struct tree *, uint64_t);
40 void *tree_pop(struct tree *, uint64_t);
41 void *tree_xpop(struct tree *, uint64_t);
42 int tree_poproot(struct tree *, uint64_t *, void **);
43 int tree_root(struct tree *, uint64_t *, void **);
44 int tree_iter(struct tree *, void **, uint64_t *, void **);
45 int tree_iterfrom(struct tree *, void **, uint64_t, uint64_t *, void **);
46 void tree_merge(struct tree *, struct tree *);
47 
48 #endif
49