11 template <
typename T,
typename TCompare>
12 template <
class InputIterator>
16 for (
auto it = first; it != last; ++it)
20 template <
typename T,
typename TCompare>
23 return (T*)InternalLowest();
26 template <
typename T,
typename TCompare>
29 return InternalLowest();
32 template <
typename T,
typename TCompare>
35 const T* result = _root;
36 if (result !=
nullptr)
37 while (result->left !=
nullptr)
38 result = result->left;
42 template <
typename T,
typename TCompare>
45 return (T*)InternalHighest();
48 template <
typename T,
typename TCompare>
51 return InternalHighest();
54 template <
typename T,
typename TCompare>
57 const T* result = _root;
58 if (result !=
nullptr)
59 while (result->right !=
nullptr)
60 result = result->right;
64 template <
typename T,
typename TCompare>
70 template <
typename T,
typename TCompare>
76 template <
typename T,
typename TCompare>
82 template <
typename T,
typename TCompare>
88 template <
typename T,
typename TCompare>
94 template <
typename T,
typename TCompare>
100 template <
typename T,
typename TCompare>
106 template <
typename T,
typename TCompare>
112 template <
typename T,
typename TCompare>
118 template <
typename T,
typename TCompare>
124 template <
typename T,
typename TCompare>
130 template <
typename T,
typename TCompare>
136 template <
typename T,
typename TCompare>
139 return iterator(
this, (T*)InternalFind(item));
142 template <
typename T,
typename TCompare>
148 template <
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;
178 template <
typename T,
typename TCompare>
181 return iterator(
this, (T*)InternalLowerBound(item));
184 template <
typename T,
typename TCompare>
190 template <
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;
222 template <
typename T,
typename TCompare>
225 return iterator(
this, (T*)InternalUpperBound(item));
228 template <
typename T,
typename TCompare>
234 template <
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;
259 template <
typename T,
typename TCompare>
265 template <
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);
319 template <
typename T,
typename TCompare>
322 return erase(find(item)).operator->();
325 template <
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;
398 template <
typename T,
typename TCompare>
405 template <
typename T,
typename TCompare>
409 swap(_compare, bintree._compare);
410 swap(_size, bintree._size);
411 swap(_root, bintree._root);
414 template <
typename T,
typename TCompare>
417 bintree1.swap(bintree2);
420 template <
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;
441 template <
class TContainer,
typename T>
449 template <
class TContainer,
typename T>
452 assert((_node !=
nullptr) &&
"Iterator must be valid!");
457 template <
class TContainer,
typename T>
463 template <
class TContainer,
typename T>
467 swap(_container, it._container);
468 swap(_node, it._node);
471 template <
class TContainer,
typename T>
477 template <
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;
498 template <
class TContainer,
typename T>
506 template <
class TContainer,
typename T>
509 assert((_node !=
nullptr) &&
"Iterator must be valid!");
514 template <
class TContainer,
typename T>
520 template <
class TContainer,
typename T>
524 swap(_container, it._container);
525 swap(_node, it._node);
528 template <
class TContainer,
typename T>
534 template <
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;
555 template <
class TContainer,
typename T>
563 template <
class TContainer,
typename T>
566 assert((_node !=
nullptr) &&
"Iterator must be valid!");
571 template <
class TContainer,
typename T>
577 template <
class TContainer,
typename T>
581 swap(_container, it._container);
582 swap(_node, it._node);
585 template <
class TContainer,
typename T>
591 template <
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;
612 template <
class TContainer,
typename T>
620 template <
class TContainer,
typename T>
623 assert((_node !=
nullptr) &&
"Iterator must be valid!");
628 template <
class TContainer,
typename T>
634 template <
class TContainer,
typename T>
638 swap(_container, it._container);
639 swap(_node, it._node);
642 template <
class TContainer,
typename T>
Intrusive binary tree constant iterator.
BinTreeConstIterator & operator++() noexcept
const value_type & const_reference
const_pointer operator->() const noexcept
const value_type * const_pointer
const_reference operator*() const noexcept
void swap(BinTreeConstIterator &it) noexcept
Swap two instances.
Intrusive binary tree constant reverse iterator.
BinTreeConstReverseIterator & operator++() noexcept
const value_type * const_pointer
const_reference operator*() const noexcept
void swap(BinTreeConstReverseIterator &it) noexcept
Swap two instances.
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.
void swap(BinTree &bintree) noexcept
Swap two instances.
const_reverse_iterator crbegin() const noexcept
Intrusive binary tree iterator.
reference operator*() noexcept
void swap(BinTreeIterator &it) noexcept
Swap two instances.
pointer operator->() noexcept
BinTreeIterator & operator++() noexcept
Intrusive binary tree reverse iterator.
void swap(BinTreeReverseIterator &it) noexcept
Swap two instances.
pointer operator->() noexcept
reference operator*() noexcept
BinTreeReverseIterator & operator++() noexcept
C++ Common project definitions.
void swap(FileCache &cache1, FileCache &cache2) noexcept
void swap(BinTreeConstReverseIterator< TContainer, T > &it1, BinTreeConstReverseIterator< TContainer, T > &it2) noexcept