HAllocator
A Simple C++ Memory Allocator
Loading...
Searching...
No Matches
RBTreeDriver.hpp
Go to the documentation of this file.
1
10#pragma once
11
12#include "../../rb-tree/rb-tree.hpp"
13
14namespace hh::halloc {
27template <typename T>
29private:
30 T* root;
31
32public:
37 explicit RBTreeDriver() : root(nullptr) {}
38
47 explicit RBTreeDriver(T* node) : root(node) {}
48
52 RBTreeDriver(const RBTreeDriver&) = delete;
53
58
66 RBTreeDriver(RBTreeDriver&& other) : root(other.root) { other.root = nullptr; }
67
77 if (this != &other) {
78 root = other.root;
79 other.root = nullptr;
80 }
81 return *this;
82 }
83
101 void insert(T* node) { hh::rb_tree::insert(root, node); }
102
121 void remove(T* node) { hh::rb_tree::remove(root, node); }
122
138 T* lower_bound(std::size_t key, bool (*cmp)(std::size_t, std::size_t)) {
139 return hh::rb_tree::lower_bound(root, key, cmp);
140 }
141};
142} // namespace hh::halloc
Template wrapper for managing a Red-Black tree.
Definition RBTreeDriver.hpp:28
void insert(T *node)
Inserts a node into the RB-tree.
Definition RBTreeDriver.hpp:101
T * lower_bound(std::size_t key, bool(*cmp)(std::size_t, std::size_t))
Finds the smallest node with value >= key using custom comparison.
Definition RBTreeDriver.hpp:138
RBTreeDriver(const RBTreeDriver &)=delete
Copy constructor - deleted (move-only semantics).
RBTreeDriver(T *node)
Constructor with existing root node.
Definition RBTreeDriver.hpp:47
RBTreeDriver()
Default constructor - creates an empty tree.
Definition RBTreeDriver.hpp:37
RBTreeDriver & operator=(const RBTreeDriver &)=delete
Copy assignment - deleted (move-only semantics).
RBTreeDriver(RBTreeDriver &&other)
Move constructor - transfers ownership of tree.
Definition RBTreeDriver.hpp:66
RBTreeDriver & operator=(RBTreeDriver &&other)
Move assignment - transfers ownership of tree.
Definition RBTreeDriver.hpp:76
void remove(T *node)
Removes a node from the RB-tree.
Definition RBTreeDriver.hpp:121
Definition Block.hpp:35
RbNode * lower_bound(RbNode *root, std::size_t key, bool(*cmp)(std::size_t, std::size_t))
Finds the smallest node with value >= key.
Definition rb-tree.hpp:592
void insert(RbNode *&root, RbNode *new_node)
Inserts a new node into the Red-Black tree.
Definition rb-tree.hpp:318
void remove(RbNode *&root, RbNode *node)
Removes a node from the Red-Black tree.
Definition rb-tree.hpp:499