7 #include "unihashtree.h" 23 UniHashTreeBase::~UniHashTreeBase()
27 Container *oldchildren = xchildren;
38 xparent->unlink(
this);
44 if (xparent == parent)
47 xparent->unlink(
this);
69 while (node != ancestor)
73 assert(node != NULL ||
74 !
"ancestor was not a node in the tree");
97 node = node->_findchild(it());
108 return const_cast<UniHashTreeBase*>(
this);
110 return xchildren ? (*xchildren)[key] : NULL;
116 return xchildren && !xchildren->isempty();
125 xchildren->add(node);
134 xchildren->remove(node);
135 if (xchildren->count() == 0)
148 void UniHashTreeBase::_recursive_unsorted_visit(
150 const UniHashTreeBaseVisitor &visitor,
void *userdata,
151 bool preorder,
bool postorder)
154 visitor(a, userdata);
156 for (i.rewind(); i.next();)
157 _recursive_unsorted_visit(i.ptr(), visitor, userdata,
158 preorder, postorder);
160 visitor(a, userdata);
163 bool UniHashTreeBase::_recursivecompare(
165 const UniHashTreeBaseComparator &comparator)
174 if (!comparator(a, b))
178 Container::Sorter *ait = NULL, *bit = NULL;
181 ait =
new Container::Sorter(*const_cast<Container*>(a->
xchildren),
184 a = ait->next() ? ait->ptr() : NULL;
188 bit =
new Container::Sorter(*const_cast<Container*>(b->
xchildren),
191 b = bit->next() ? bit->ptr() : NULL;
195 while (a != NULL && b != NULL)
201 _recursivecompare(a, NULL, comparator);
202 a = ait->next() ? ait->ptr() : NULL;
207 _recursivecompare(NULL, b, comparator);
208 b = bit->next() ? bit->ptr() : NULL;
212 if (!_recursivecompare(a, b, comparator))
214 a = ait->next() ? ait->ptr() : NULL;
215 b = bit->next() ? bit->ptr() : NULL;
223 _recursivecompare(a, NULL, comparator);
224 a = ait->next() ? ait->ptr() : NULL;
229 _recursivecompare(NULL, b, comparator);
230 b = bit->next() ? bit->ptr() : NULL;
UniHashTreeBase * xparent
bool isempty() const
Returns true if this path has zero segments (also known as root).
Represents a UniConf key which is a path in a hierarchy structured much like the traditional Unix fil...
const UniConfKey & key() const
Returns the key field.
int compareto(const UniConfKey &other) const
Compares two paths lexicographically.
void prepend(const UniConfKey &other)
Prepends a path to this path.
An iterator over the segments of a key.
bool haschildren() const
Returns true if the node has children.