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 Kern Sibbald.
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;
98 * This allows us to do explicit initialization,
99 * allowing us to mix C++ classes inside malloc'ed
100 * C structures. Define before called in constructor.
102 inline void rblist::init(void *item, rblink *link)
105 loffset = (int)((char *)link - (char *)item);
106 if (loffset < 0 || loffset > 5000) {
107 Emsg0(M_ABORT, 0, "Improper rblist initialization.\n");
112 inline rblist::rblist(void *item, rblink *link)
117 /* Constructor with link at head of item */
118 inline rblist::rblist(void): head(0), loffset(0), num_items(0)
122 inline void rblist::set_parent(void *item, void *parent)
124 ((rblink *)(((char *)item)+loffset))->parent = parent;
127 inline void rblist::set_left(void *item, void *left)
129 ((rblink *)(((char *)item)+loffset))->left = left;
132 inline void rblist::set_right(void *item, void *right)
134 ((rblink *)(((char *)item)+loffset))->right = right;
137 inline void rblist::set_red(void *item, bool red)
139 ((rblink *)(((char *)item)+loffset))->red = red;
142 inline bool rblist::empty(void) const
147 inline int rblist::size() const
152 inline void *rblist::parent(const void *item) const
154 return ((rblink *)(((char *)item)+loffset))->parent;
157 inline void *rblist::left(const void *item) const
159 return ((rblink *)(((char *)item)+loffset))->left;
162 inline void *rblist::right(const void *item) const
164 return ((rblink *)(((char *)item)+loffset))->right;
167 inline bool rblist::red(const void *item) const
169 return ((rblink *)(((char *)item)+loffset))->red;