9#ifndef SQUID_INCLUDE_SPLAY_H
10#define SQUID_INCLUDE_SPLAY_H
62 template <
class FindValue>
Value const *
find (FindValue
const &,
int( * compare)(FindValue
const &a,
Value const &b))
const;
85 template <
typename ValueVisitor>
void visit(ValueVisitor &)
const;
89 template <
typename NodeVisitor>
void visitEach(NodeVisitor &)
const;
129 if (result->
left ==
nullptr) {
130 newTop = result->
right;
132 newTop = result->
left->splay(dataToRemove, compare);
135 result->
right =
nullptr;
155 newNode->
right = newTop;
156 newTop->
left =
nullptr;
160 newNode->
left = newTop;
161 newTop->
right =
nullptr;
171template<
class FindValue>
189 if (top->
left ==
nullptr)
198 if (top->
left ==
nullptr)
206 if (top->
right ==
nullptr)
215 if (top->
right ==
nullptr)
235template <
class Visitor>
252 auto movedUp =
false;
253 cur->visitThreadUp =
nullptr;
256 if (!
cur->left || movedUp) {
258 const auto old =
cur;
264 else if (
cur->visitThreadUp) {
278 auto rmc =
cur->left;
280 rmc->visitThreadUp =
nullptr;
284 rmc->visitThreadUp =
cur;
294template <
class Visitor>
299 visitEach(internalVisitor);
303template <
class FindValue>
322 if (
const auto similarValue = find(value, compare))
328 head =
head->insert(value, compare);
339 if (find(value, compare) ==
nullptr)
342 head =
head->remove(value, compare);
352 return head->start();
362 return head->finish();
372 visitEach(destroyer);
430 if (toVisit.empty() && right.
toVisit.empty())
432 if (!toVisit.empty() && !right.
toVisit.empty())
433 return toVisit.top() == right.
toVisit.top();
479 addLeftPath(currentNode->
right);
481 toVisit.push(currentNode);
488 if (aNode ==
nullptr)
494 }
while (aNode !=
nullptr);
510 if (toVisit.size() == 0)
511 fatal (
"Attempt to dereference SplayConstIterator past-the-end\n");
513 return toVisit.top()->data;
squidaio_request_t * head
SplayConstIterator(SplayNode< V > *aNode)
V const & operator*() const
std::stack< SplayNode< V > * > toVisit
SplayConstIterator & operator++()
void addLeftPath(SplayNode< V > *aNode)
bool operator==(SplayConstIterator const &right) const
void init(SplayNode< V > *)
SplayNode< V > * visitThreadUp
SplayNode< V > * splay(const FindValue &data, int(*compare)(FindValue const &a, Value const &b)) const
SplayNode< V > * insert(Value data, SPLAYCMP *compare)
SplayNode< V > * remove(const Value data, SPLAYCMP *compare)
int SPLAYCMP(Value const &a, Value const &b)
SplayNode< V > const * finish() const
SplayNode< V > const * start() const
const_iterator begin() const
const SplayConstIterator< V > const_iterator
SplayIterator< V > iterator
Value const * find(FindValue const &, int(*compare)(FindValue const &a, Value const &b)) const
static void DefaultFree(Value &v)
const_iterator end() const
void remove(Value const &, SPLAYCMP *compare)
SplayNode< V > const * start() const
void visitEach(NodeVisitor &) const
left-to-right walk through all nodes
SplayNode< V > const * finish() const
int SPLAYCMP(Value const &a, Value const &b)
void visit(ValueVisitor &) const
left-to-right visit of all stored Values
const Value * insert(const Value &, SPLAYCMP *)
void destroy(SPLAYFREE *=DefaultFree)
void fatal(const char *message)
Comm::AcceptLimiter dummy