2 Bacula® - The Network Backup Solution
4 Copyright (C) 2005-2007 Free Software Foundation Europe e.V.
6 The main author of Bacula is Kern Sibbald, with contributions from
7 many others, a complete list can be found in the file AUTHORS.
8 This program is Free Software; you can redistribute it and/or
9 modify it under the terms of version two of the GNU General Public
10 License as published by the Free Software Foundation and included
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 Bacula® is a registered trademark of John Walker.
24 The licensor of Bacula is the Free Software Foundation Europe
25 (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
26 Switzerland, email:ftf@fsfeurope.org.
33 /* ========================================================================
35 * red-black binary tree routines -- rblist.h
44 * There is a lot of extra casting here to work around the fact
45 * that some compilers (Sun and Visual C++) do not accept
46 * (bnode *) as an lvalue on the left side of an equal.
48 * Loop var through each member of list
51 #define foreach_rblist(var, tree) \
52 for (((var)=(typeof(var))(tree)->first()); (var); ((var)=(typeof(var))(tree)->next(var)))
54 #define foreach_rblist(var, tree) \
55 for ((*((void **)&(var))=(void*)((tree)->first())); (var); (*((void **)&(var))=(void*)((tree)->next(var))))
65 class rblist : public SMARTALLOC {
70 void left_rotate(void *item);
71 void right_rotate(void *item);
73 rblist(void *item, rblink *link);
75 ~rblist(void) { destroy(); }
76 void init(void *item, rblink *link);
77 void set_parent(void *item, void *parent);
78 void set_left(void *item, void *left);
79 void set_right(void *item, void *right);
80 void set_red(void *item, bool red);
81 void *parent(const void *item) const;
82 void *left(const void *item) const;
83 void *right(const void *item) const;
84 bool red(const void *item) const;
85 void *insert(void *item, int compare(void *item1, void *item2));
86 void *search(void *item, int compare(void *item1, void *item2));
88 void *next(void *item);
89 void *any(void *item);
90 void remove(void *item);
91 bool empty(void) const;
96 inline rblist::rblist(void *item, rblink *link)
101 /* Constructor with link at head of item */
102 inline rblist::rblist(void): head(0), loffset(0), num_items(0)
107 * This allows us to do explicit initialization,
108 * allowing us to mix C++ classes inside malloc'ed
109 * C structures. Define before called in constructor.
111 inline void rblist::init(void *item, rblink *link)
114 loffset = (int)((char *)link - (char *)item);
115 if (loffset < 0 || loffset > 5000) {
116 Emsg0(M_ABORT, 0, "Improper rblist initialization.\n");
121 inline void rblist::set_parent(void *item, void *parent)
123 ((rblink *)(((char *)item)+loffset))->parent = parent;
126 inline void rblist::set_left(void *item, void *left)
128 ((rblink *)(((char *)item)+loffset))->left = left;
131 inline void rblist::set_right(void *item, void *right)
133 ((rblink *)(((char *)item)+loffset))->right = right;
136 inline void rblist::set_red(void *item, bool red)
138 ((rblink *)(((char *)item)+loffset))->red = red;
141 inline bool rblist::empty(void) const
146 inline int rblist::size() const
151 inline void *rblist::parent(const void *item) const
153 return ((rblink *)(((char *)item)+loffset))->parent;
156 inline void *rblist::left(const void *item) const
158 return ((rblink *)(((char *)item)+loffset))->left;
161 inline void *rblist::right(const void *item) const
163 return ((rblink *)(((char *)item)+loffset))->right;
166 inline bool rblist::red(const void *item) const
168 return ((rblink *)(((char *)item)+loffset))->red;