11template <
typename T,
typename TCompare>
12template <
class InputIterator>
16 for (
auto it = first; it != last; ++it)
20template <
typename T,
typename TCompare>
23 return (T*)InternalLowest();
26template <
typename T,
typename TCompare>
29 return InternalLowest();
32template <
typename T,
typename TCompare>
35 const T* result = _root;
36 if (result !=
nullptr)
37 while (result->left !=
nullptr)
38 result = result->left;
42template <
typename T,
typename TCompare>
45 return (T*)InternalHighest();
48template <
typename T,
typename TCompare>
51 return InternalHighest();
54template <
typename T,
typename TCompare>
57 const T* result = _root;
58 if (result !=
nullptr)
59 while (result->right !=
nullptr)
60 result = result->right;
64template <
typename T,
typename TCompare>
70template <
typename T,
typename TCompare>
76template <
typename T,
typename TCompare>
82template <
typename T,
typename TCompare>
88template <
typename T,
typename TCompare>
94template <
typename T,
typename TCompare>
100template <
typename T,
typename TCompare>
106template <
typename T,
typename TCompare>
112template <
typename T,
typename TCompare>
118template <
typename T,
typename TCompare>
124template <
typename T,
typename TCompare>
130template <
typename T,
typename TCompare>
136template <
typename T,
typename TCompare>
139 return iterator(
this, (T*)InternalFind(item));
142template <
typename T,
typename TCompare>
148template <
typename T,
typename TCompare>
152 const T* current = _root;
154 while (current !=
nullptr)
157 if (compare(item, *current))
159 current = current->left;
164 if (compare(*current, item))
166 current = current->right;
178template <
typename T,
typename TCompare>
181 return iterator(
this, (T*)InternalLowerBound(item));
184template <
typename T,
typename TCompare>
190template <
typename T,
typename TCompare>
194 const T* current = _root;
195 const T* previous =
nullptr;
197 while (current !=
nullptr)
200 if (compare(item, *current))
203 current = current->left;
208 if (compare(*current, item))
210 current = current->right;
222template <
typename T,
typename TCompare>
225 return iterator(
this, (T*)InternalUpperBound(item));
228template <
typename T,
typename TCompare>
234template <
typename T,
typename TCompare>
238 const T* current = _root;
239 const T* previous =
nullptr;
241 while (current !=
nullptr)
244 if (compare(item, *current))
247 current = current->left;
252 current = current->right;
259template <
typename T,
typename TCompare>
265template <
typename T,
typename TCompare>
269 T* current = (T*)position.operator->();
271 while (current !=
nullptr)
274 if (compare(item, *current))
276 if (current->left !=
nullptr)
278 current = current->left;
284 current->left = &item;
290 if (compare(*current, item))
292 if (current->right !=
nullptr)
294 current = current->right;
300 current->right = &item;
306 return std::make_pair(
iterator(
this, current),
false);
309 item.parent = current;
311 item.right =
nullptr;
312 if (_root ==
nullptr)
316 return std::make_pair(
iterator(
this, &item),
true);
319template <
typename T,
typename TCompare>
322 return erase(find(item)).operator->();
325template <
typename T,
typename TCompare>
328 T* result = ((
iterator&)it).operator->();
329 if (result ==
nullptr)
332 T* parent = result->parent;
333 T* left = result->left;
334 T* right = result->right;
340 if (parent !=
nullptr)
342 if (parent->left == result)
343 parent->left = right;
345 parent->right = right;
349 if (right !=
nullptr)
350 right->parent = parent;
353 else if (right ==
nullptr)
356 if (parent !=
nullptr)
358 if (parent->left == result)
361 parent->right = left;
366 left->parent = parent;
372 if (parent !=
nullptr)
374 if (parent->left == result)
377 parent->right = left;
381 left->parent = parent;
385 while (temp->right !=
nullptr)
388 right->parent = temp;
391 result->parent =
nullptr;
392 result->left =
nullptr;
393 result->right =
nullptr;
398template <
typename T,
typename TCompare>
405template <
typename T,
typename TCompare>
409 swap(_compare, bintree._compare);
410 swap(_size, bintree._size);
411 swap(_root, bintree._root);
414template <
typename T,
typename TCompare>
417 bintree1.swap(bintree2);
420template <
class TContainer,
typename T>
423 if (_node !=
nullptr)
425 if (_node->right !=
nullptr)
427 _node = _node->right;
428 while (_node->left !=
nullptr)
433 while ((_node->parent !=
nullptr) && compare(*_node->parent, *_node))
434 _node = _node->parent;
435 _node = _node->parent;
441template <
class TContainer,
typename T>
449template <
class TContainer,
typename T>
452 assert((_node !=
nullptr) &&
"Iterator must be valid!");
457template <
class TContainer,
typename T>
463template <
class TContainer,
typename T>
467 swap(_container, it._container);
468 swap(_node, it._node);
471template <
class TContainer,
typename T>
477template <
class TContainer,
typename T>
480 if (_node !=
nullptr)
482 if (_node->right !=
nullptr)
484 _node = _node->right;
485 while (_node->left !=
nullptr)
490 while ((_node->parent !=
nullptr) && compare(*_node->parent, *_node))
491 _node = _node->parent;
492 _node = _node->parent;
498template <
class TContainer,
typename T>
506template <
class TContainer,
typename T>
509 assert((_node !=
nullptr) &&
"Iterator must be valid!");
514template <
class TContainer,
typename T>
520template <
class TContainer,
typename T>
524 swap(_container, it._container);
525 swap(_node, it._node);
528template <
class TContainer,
typename T>
534template <
class TContainer,
typename T>
537 if (_node !=
nullptr)
539 if (_node->left !=
nullptr)
542 while (_node->right !=
nullptr)
543 _node = _node->right;
547 while ((_node->parent !=
nullptr) && compare(*_node, *_node->parent))
548 _node = _node->parent;
549 _node = _node->parent;
555template <
class TContainer,
typename T>
563template <
class TContainer,
typename T>
566 assert((_node !=
nullptr) &&
"Iterator must be valid!");
571template <
class TContainer,
typename T>
577template <
class TContainer,
typename T>
581 swap(_container, it._container);
582 swap(_node, it._node);
585template <
class TContainer,
typename T>
591template <
class TContainer,
typename T>
594 if (_node !=
nullptr)
596 if (_node->left !=
nullptr)
599 while (_node->right !=
nullptr)
600 _node = _node->right;
604 while ((_node->parent !=
nullptr) && compare(*_node, *_node->parent))
605 _node = _node->parent;
606 _node = _node->parent;
612template <
class TContainer,
typename T>
620template <
class TContainer,
typename T>
623 assert((_node !=
nullptr) &&
"Iterator must be valid!");
628template <
class TContainer,
typename T>
634template <
class TContainer,
typename T>
638 swap(_container, it._container);
639 swap(_node, it._node);
642template <
class TContainer,
typename T>
Intrusive binary tree constant iterator.
BinTreeConstIterator & operator++() noexcept
const value_type & const_reference
const_pointer operator->() const noexcept
friend void swap(BinTreeConstIterator< UContainer, U > &it1, BinTreeConstIterator< UContainer, U > &it2) noexcept
const value_type * const_pointer
const_reference operator*() const noexcept
Intrusive binary tree constant reverse iterator.
BinTreeConstReverseIterator & operator++() noexcept
const value_type * const_pointer
const_reference operator*() const noexcept
friend void swap(BinTreeConstReverseIterator< UContainer, U > &it1, BinTreeConstReverseIterator< UContainer, U > &it2) noexcept
const value_type & const_reference
const_pointer operator->() const noexcept
Intrusive non balanced binary tree container.
std::pair< iterator, bool > insert(T &item) noexcept
Insert a new item into the binary tree.
iterator upper_bound(const T &item) noexcept
Find the iterator which points to the first item that greater than the given item in the binary tree ...
void clear() noexcept
Clear the binary tree.
iterator lower_bound(const T &item) noexcept
Find the iterator which points to the first item that not less than the given item in the binary tree...
reverse_iterator rend() noexcept
Get the reverse end binary tree iterator.
iterator find(const T &item) noexcept
Find the iterator which points to the first equal item in the binary tree or return end iterator.
iterator end() noexcept
Get the end binary tree iterator.
BinTree(const TCompare &compare=TCompare()) noexcept
iterator begin() noexcept
Get the begin binary tree iterator.
T * highest() noexcept
Get the highest binary tree item.
const_reverse_iterator crend() const noexcept
T * lowest() noexcept
Get the lowest binary tree item.
T * erase(const T &item) noexcept
Erase the given item from the binary tree.
const_iterator cbegin() const noexcept
const_iterator cend() const noexcept
reverse_iterator rbegin() noexcept
Get the reverse begin binary tree iterator.
const_reverse_iterator crbegin() const noexcept
friend void swap(BinTree< U, UCompare > &bintree1, BinTree< U, UCompare > &bintree2) noexcept
Intrusive binary tree iterator.
reference operator*() noexcept
pointer operator->() noexcept
friend void swap(BinTreeIterator< UContainer, U > &it1, BinTreeIterator< UContainer, U > &it2) noexcept
BinTreeIterator & operator++() noexcept
Intrusive binary tree reverse iterator.
pointer operator->() noexcept
reference operator*() noexcept
BinTreeReverseIterator & operator++() noexcept
friend void swap(BinTreeReverseIterator< UContainer, U > &it1, BinTreeReverseIterator< UContainer, U > &it2) noexcept
C++ Common project definitions.
void swap(FileCache &cache1, FileCache &cache2) noexcept