- Deletion also works now.
[oweals/tinc.git] / lib / rbl.h
1 /*
2     rbl.h -- header file for rbl.c
3     Copyright (C) 2000 Ivo Timmermans <itimmermans@bigfoot.com>,
4                   2000 Guus Sliepen <guus@sliepen.warande.net>
5
6     This program is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     This program is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with this program; if not, write to the Free Software
18     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19
20     $Id: rbl.h,v 1.1.2.5 2000/11/19 11:05:59 guus Exp $
21 */
22
23 typedef int (*rbl_compare_t) (const void *, const void *);
24 typedef void (*rbl_action_t) (const void *);
25 typedef void (*rbl_action_rbl_t) (const struct rbl_t *);
26
27 typedef struct rbl_t
28 {
29   /* 'red-black tree' part */
30
31   struct rbltree_t *tree;
32
33   int color;
34
35   struct rbl_t *parent;
36   struct rbl_t *left;
37   struct rbl_t *right;
38   
39   /* 'linked list' part */
40   
41   struct rbl_t *prev;
42   struct rbl_t *next;
43   
44   /* payload */
45   
46   void *data;
47    
48 } rbl_t;
49
50 typedef struct rbltree_t
51 {
52   /* callback functions */
53
54   rbl_compare_t compare;
55   rbl_action_t delete;
56
57   /* tree part */
58
59   struct rbl_t *top;
60
61   /* linked list */
62
63   struct rbl_t *head;
64   struct rbl_t *tail;
65
66 } rbltree_t;
67
68 enum color
69 {
70   RBL_RED,
71   RBL_BLACK
72 } color;
73
74 extern rbltree_t *new_rbltree(rbl_compare_t, rbl_action_t);
75 extern void free_rbltree(rbltree_t *);
76 extern rbl_t *new_rbl(void);
77 extern void free_rbl(rbl_t *);
78
79 extern rbl_t *rbl_search(rbltree_t *, void *);
80 extern rbl_t *rbl_search_closest(rbltree_t *, void *);
81 extern rbl_t *rbl_insert(rbltree_t *, void *);
82 extern rbl_t *rbl_unlink(rbltree_t *, void *);
83 extern void rbl_delete(rbltree_t *, void *);
84 extern rbl_t *rbl_insert_rbl(rbltree_t *, rbl_t *);
85 extern rbl_t *rbl_unlink_rbl(rbl_t *);
86 extern void rbl_delete_rbl(rbl_t *);
87 extern void rbl_unlink_rbltree(rbltree_t *);
88 extern void rbl_delete_rbltree(rbltree_t *);
89
90 extern void rbl_foreach(rbltree_t *, rbl_action_t);
91 extern void rbl_foreach_rbl(rbltree_t *, rbl_action_rbl_t);