mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-02-10 18:05:41 +08:00
Added experimental red-black tree output iterator. Fixed compoundfile Delete()
This commit is contained in:
@ -423,12 +423,40 @@ void RBTree::DoVisitTreeNodes(Action<PIRBNode> action, PIRBNode walker)
|
||||
}
|
||||
}
|
||||
|
||||
RBTree::iterator::iterator(RBTree &tree, bool end)
|
||||
RBTree::iterator::iterator(RBTree *tree) : tree(tree)
|
||||
{
|
||||
Action<PIRBNode> inserter = [&] (PIRBNode pNode)
|
||||
if (tree == nullptr)
|
||||
return;
|
||||
|
||||
auto walker = tree->getRoot();
|
||||
while (walker != nullptr)
|
||||
{
|
||||
heap.push_back(pNode);
|
||||
};
|
||||
tree.VisitTreeNodes(inserter);
|
||||
current = end ? heap.end() : heap.begin();
|
||||
current = walker;
|
||||
walker = walker->getLeft();
|
||||
}
|
||||
}
|
||||
|
||||
RBTree::iterator &RBTree::iterator::operator++()
|
||||
{
|
||||
if (current->getRight())
|
||||
{
|
||||
current = current->getRight();
|
||||
auto walker = tree->getRoot();
|
||||
while (walker != nullptr)
|
||||
{
|
||||
current = walker;
|
||||
walker = walker->getLeft();
|
||||
}
|
||||
}
|
||||
else if (current->getParent())
|
||||
{
|
||||
current = current->getParent();
|
||||
return *this;
|
||||
}
|
||||
else
|
||||
{
|
||||
current.reset();
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@ -52,23 +52,21 @@ private:
|
||||
void DoVisitTreeNodes(Action<PIRBNode> action, PIRBNode walker);
|
||||
|
||||
public:
|
||||
// todo this from C# and it's weak realization
|
||||
class iterator : public std::iterator<std::bidirectional_iterator_tag, std::ptrdiff_t, IRBNode, IRBNode*, PIRBNode>
|
||||
|
||||
class iterator : public std::iterator<std::output_iterator_tag, std::ptrdiff_t, IRBNode, IRBNode*, PIRBNode>
|
||||
{
|
||||
std::list<WPIRBNode> heap;
|
||||
std::list<WPIRBNode>::iterator current;
|
||||
PIRBNode current;
|
||||
RBTree* tree;
|
||||
public:
|
||||
iterator(RBTree &tree, bool end = false);
|
||||
inline iterator& operator++() {++current; return *this;}
|
||||
inline iterator& operator--() {--current; return *this;}
|
||||
iterator(RBTree *tree);
|
||||
iterator& operator++();
|
||||
inline bool operator==(const iterator &other) const {return current == other.current;}
|
||||
inline bool operator!=(const iterator &other) const {return current != other.current;}
|
||||
inline PIRBNode operator*() {return current->lock();}
|
||||
inline iterator end() {current = heap.end(); return *this;}
|
||||
inline PIRBNode operator*() {return current;}
|
||||
};
|
||||
|
||||
iterator&& begin() {return std::move(iterator(*this));}
|
||||
iterator&& end() {return std::move(iterator(*this).end());}
|
||||
iterator begin() {return iterator(this);}
|
||||
iterator end() {return iterator(nullptr);}
|
||||
|
||||
private:
|
||||
PIRBNode root;
|
||||
|
||||
Reference in New Issue
Block a user