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;
153 const T* previous =
nullptr;
155 while (current !=
nullptr)
158 if (compare(item, *current))
161 current = current->left;
166 if (compare(*current, item))
169 current = current->right;
174 if (current !=
nullptr)
182 if (previous !=
nullptr)
189 template <
typename T,
typename TCompare>
192 return iterator(
this, (T*)InternalLowerBound(item));
195 template <
typename T,
typename TCompare>
201 template <
typename T,
typename TCompare>
205 const T* current = _root;
206 const T* previous =
nullptr;
208 while (current !=
nullptr)
211 if (compare(item, *current))
214 current = current->left;
219 if (compare(*current, item))
221 current = current->right;
226 if (current !=
nullptr)
234 if (previous !=
nullptr)
241 template <
typename T,
typename TCompare>
244 return iterator(
this, (T*)InternalUpperBound(item));
247 template <
typename T,
typename TCompare>
253 template <
typename T,
typename TCompare>
257 const T* current = _root;
258 const T* previous =
nullptr;
260 while (current !=
nullptr)
263 if (compare(item, *current))
266 current = current->left;
271 current = current->right;
275 if (previous !=
nullptr)
282 template <
typename T,
typename TCompare>
285 return insert(find(item), item);
288 template <
typename T,
typename TCompare>
292 T* current = (T*)position.operator->();
293 if (current !=
nullptr)
296 return std::make_pair(
iterator(
this, current),
false);
299 item.parent =
nullptr;
301 item.right =
nullptr;
302 if (_root !=
nullptr)
304 if (compare(item, *_root))
306 item.left = _root->left;
308 _root->parent = &item;
309 if (_root->left !=
nullptr)
310 _root->left->parent = &item;
311 _root->left =
nullptr;
315 item.right = _root->right;
317 _root->parent = &item;
318 if (_root->right !=
nullptr)
319 _root->right->parent = &item;
320 _root->right =
nullptr;
326 return std::make_pair(
iterator(
this, &item),
true);
329 template <
typename T,
typename TCompare>
332 return erase(find(item)).operator->();
335 template <
typename T,
typename TCompare>
338 T* result = ((
iterator&)it).operator->();
339 if (result ==
nullptr)
342 if (result->left ==
nullptr)
344 _root = result->right;
345 if (_root !=
nullptr)
346 _root->parent =
nullptr;
348 else if (result->right ==
nullptr)
350 _root = result->left;
351 if (_root !=
nullptr)
352 _root->parent =
nullptr;
356 _root = result->left;
357 _root->parent =
nullptr;
358 T* highest = result->left;
359 while (highest->right !=
nullptr)
360 highest = highest->right;
361 highest->right = result->right;
362 if (highest->right !=
nullptr)
363 highest->right->parent = highest;
366 result->parent =
nullptr;
367 result->left =
nullptr;
368 result->right =
nullptr;
373 template <
typename T,
typename TCompare>
376 while (x->parent !=
nullptr)
382 else if ((g->left == p) && (p->left == x))
384 else if ((g->right == p) && (p->right == x))
392 template <
typename T,
typename TCompare>
393 inline void BinTreeSplay<T, TCompare>::Zig(T* x)
const
398 [[maybe_unused]] T* a = x->left;
399 [[maybe_unused]] T* b = x->right;
400 [[maybe_unused]] T* c = p->right;
413 [[maybe_unused]] T* a = p->left;
414 [[maybe_unused]] T* b = x->left;
415 [[maybe_unused]] T* c = x->right;
428 template <
typename T,
typename TCompare>
429 inline void BinTreeSplay<T, TCompare>::ZigZig(T* x)
const
435 [[maybe_unused]] T* a = x->left;
436 [[maybe_unused]] T* b = x->right;
437 [[maybe_unused]] T* c = p->right;
438 [[maybe_unused]] T* d = g->right;
440 x->parent = g->parent;
450 if (x->parent !=
nullptr)
452 if (x->parent->left == g)
455 x->parent->right = x;
466 [[maybe_unused]] T* a = g->left;
467 [[maybe_unused]] T* b = p->left;
468 [[maybe_unused]] T* c = x->left;
469 [[maybe_unused]] T* d = x->right;
471 x->parent = g->parent;
481 if (x->parent !=
nullptr)
483 if (x->parent->left == g)
486 x->parent->right = x;
497 template <
typename T,
typename TCompare>
498 inline void BinTreeSplay<T, TCompare>::ZigZag(T* x)
const
504 [[maybe_unused]] T* a = p->left;
505 [[maybe_unused]] T* b = x->left;
506 [[maybe_unused]] T* c = x->right;
507 [[maybe_unused]] T* d = g->right;
509 x->parent = g->parent;
519 if (x->parent !=
nullptr)
521 if (x->parent->left == g)
524 x->parent->right = x;
535 [[maybe_unused]] T* a = g->left;
536 [[maybe_unused]] T* b = x->left;
537 [[maybe_unused]] T* c = x->right;
538 [[maybe_unused]] T* d = p->right;
540 x->parent = g->parent;
550 if (x->parent !=
nullptr)
552 if (x->parent->left == g)
555 x->parent->right = x;
566 template <
typename T,
typename TCompare>
573 template <
typename T,
typename TCompare>
577 swap(_compare, bintree._compare);
578 swap(_size, bintree._size);
579 swap(_root, bintree._root);
582 template <
typename T,
typename TCompare>
585 bintree1.swap(bintree2);
Intrusive binary tree constant iterator.
Intrusive binary tree constant reverse iterator.
Intrusive binary tree iterator.
Intrusive binary tree reverse iterator.
Intrusive balanced Splay binary tree container.
reverse_iterator rend() noexcept
Get the reverse end binary tree iterator.
BinTreeSplay(const TCompare &compare=TCompare()) noexcept
const_iterator cbegin() const noexcept
iterator end() noexcept
Get the end binary tree iterator.
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 ...
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...
const_reverse_iterator crbegin() const noexcept
void clear() noexcept
Clear the binary tree.
T * highest() noexcept
Get the highest binary tree item.
iterator find(const T &item) noexcept
Find the iterator which points to the first equal item in the binary tree or return end iterator.
const_iterator cend() const noexcept
std::pair< iterator, bool > insert(T &item) noexcept
Insert a new item into the binary tree.
reverse_iterator rbegin() noexcept
Get the reverse begin binary tree iterator.
T * lowest() noexcept
Get the lowest binary tree item.
iterator begin() noexcept
Get the begin binary tree iterator.
const_reverse_iterator crend() const noexcept
T * erase(const T &item) noexcept
Erase the given item from the binary tree.
void swap(BinTreeSplay &bintree) noexcept
Swap two instances.
C++ Common project definitions.
void swap(FileCache &cache1, FileCache &cache2) noexcept
void swap(BinTreeSplay< T, TCompare > &bintree1, BinTreeSplay< T, TCompare > &bintree2) noexcept