- Added balanced tree management stuff as well. (It is not finished yet.)
[tinc] / 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.1 2000/11/16 09:18:38 guus Exp $
21 */
22
23 typedef int (*rbl_compare_t) (const void *, const void *);
24 typedef void (*rbl_delete_t) (const void *);
25
26 typedef struct rbl_t
27 {
28   /* 'red-black tree' part */
29
30   struct rbltree_t *tree;
31
32   int color;
33
34   rbl_t *parent;
35   rbl_t *left;
36   rbl_t *right;
37   
38   /* 'linked list' part */
39   
40   rbl_t *prev;
41   rbl_t *next;
42   
43   /* payload */
44   
45   void *data;
46    
47 } rbl_t;
48
49 typedef struct rbltree_t
50 {
51   rbl_compare_t *compare;
52   rbl_delete_t *delete;
53   struct rbl_t *head;
54 } rbltree_t;
55
56 enum
57 {
58   RBL_RED;
59   RBL_BLACK;
60 };
61
62 extern rbl_t rbl_search(rbltree_t *, void *);
63 extern rbl_t rbl_search_closest(rbltree_t *, void *);
64 extern rbl_t rbl_insert(rbltree_t *, void *);
65 extern rbl_t rbl_unlink(rbltree_t *, void *);
66 extern rbl_t rbl_delete(rbltree_t *, void *);
67 extern rbl_t rbl_insert_rbl(rbltree_t *, rbl_t *);
68 extern rbl_t rbl_unlink_rbl(rbltree_t *, rbl_t *);
69 extern rbl_t rbl_delete_rbl(rbltree_t *, rbl_t *);
70 extern rbl_t rbl_prev(rbl_t *);
71 extern rbl_t rbl_next(rbl_t *);