2 splay_tree.h -- header file for splay_tree.c
3 Copyright (C) 2004-2006 Guus Sliepen <guus@tinc-vpn.org>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 $Id: splay_tree.h 1374 2004-03-21 14:21:22Z guus $
23 #ifndef __SPLAY_TREE_H__
24 #define __SPLAY_TREE_H__
26 typedef struct splay_node_t {
28 /* Linked list part */
30 struct splay_node_t *next;
31 struct splay_node_t *prev;
35 struct splay_node_t *parent;
36 struct splay_node_t *left;
37 struct splay_node_t *right;
45 typedef int (*splay_compare_t)(const void *, const void *);
46 typedef void (*splay_action_t)(const void *);
47 typedef void (*splay_action_node_t)(const splay_node_t *);
49 typedef struct splay_tree_t {
51 /* Linked list part */
60 splay_compare_t compare;
61 splay_action_t delete;
65 /* (De)constructors */
67 extern splay_tree_t *splay_alloc_tree(splay_compare_t, splay_action_t);
68 extern void splay_free_tree(splay_tree_t *);
70 extern splay_node_t *splay_alloc_node(void);
71 extern void splay_free_node(splay_tree_t *tree, splay_node_t *);
73 /* Insertion and deletion */
75 extern splay_node_t *splay_insert(splay_tree_t *, void *);
76 extern splay_node_t *splay_insert_node(splay_tree_t *, splay_node_t *);
78 extern void splay_insert_top(splay_tree_t *, splay_node_t *);
79 extern void splay_insert_before(splay_tree_t *, splay_node_t *, splay_node_t *);
80 extern void splay_insert_after(splay_tree_t *, splay_node_t *, splay_node_t *);
82 extern splay_node_t *splay_unlink(splay_tree_t *, void *);
83 extern void splay_unlink_node(splay_tree_t *tree, splay_node_t *);
84 extern void splay_delete(splay_tree_t *, void *);
85 extern void splay_delete_node(splay_tree_t *, splay_node_t *);
87 /* Fast tree cleanup */
89 extern void splay_delete_tree(splay_tree_t *);
93 extern void *splay_search(splay_tree_t *, const void *);
94 extern void *splay_search_closest(splay_tree_t *, const void *, int *);
95 extern void *splay_search_closest_smaller(splay_tree_t *, const void *);
96 extern void *splay_search_closest_greater(splay_tree_t *, const void *);
98 extern splay_node_t *splay_search_node(splay_tree_t *, const void *);
99 extern splay_node_t *splay_search_closest_node(splay_tree_t *, const void *, int *);
100 extern splay_node_t *splay_search_closest_node_nosplay(const splay_tree_t *, const void *, int *);
101 extern splay_node_t *splay_search_closest_smaller_node(splay_tree_t *, const void *);
102 extern splay_node_t *splay_search_closest_greater_node(splay_tree_t *, const void *);
106 extern void splay_foreach(const splay_tree_t *, splay_action_t);
107 extern void splay_foreach_node(const splay_tree_t *, splay_action_t);