libxr 1.0
Want to be the best embedded framework
|
红黑树实现,支持泛型键和值,并提供线程安全操作 (Red-Black Tree implementation supporting generic keys and values with thread-safe operations). More...
#include <rbt.hpp>
Data Structures | |
class | BaseNode |
红黑树的基本节点结构 (Base node structure of the Red-Black Tree). More... | |
class | Node |
红黑树的泛型数据节点,继承自 BaseNode (Generic data node for Red-Black Tree, inheriting from BaseNode ). More... | |
Public Types | |
enum class | RbtColor : uint8_t { RED , BLACK } |
定义红黑树节点的颜色 (Enumeration for node colors in Red-Black Tree). More... | |
Public Member Functions | |
RBTree (int(*compare_fun)(const Key &, const Key &)) | |
构造函数,初始化红黑树 (Constructor initializing the Red-Black Tree). | |
template<typename Data , SizeLimitMode LimitMode = SizeLimitMode::MORE> | |
Node< Data > * | Search (const Key &key) |
搜索红黑树中的节点 (Search for a node in the Red-Black Tree). | |
void | Delete (BaseNode &node) |
从树中删除指定节点 (Delete a specified node from the tree). | |
template<typename KeyType > | |
void | Insert (BaseNode &node, KeyType &&key) |
在树中插入新节点 (Insert a new node into the tree). | |
uint32_t | GetNum () |
获取树中的节点数量 (Get the number of nodes in the tree). | |
template<typename Data , typename Func , SizeLimitMode LimitMode = SizeLimitMode::MORE> | |
ErrorCode | Foreach (Func func) |
遍历红黑树并执行用户提供的操作 (Traverse the Red-Black Tree and apply a user-defined function). | |
template<typename Data > | |
Node< Data > * | ForeachDisc (Node< Data > *node) |
获取红黑树的下一个中序遍历节点 (Get the next node in in-order traversal). | |
Private Member Functions | |
void | RbtreeInsert (BaseNode &node) |
void | RbtreeInsertFixup (BaseNode *node) |
void | RbtreeLeftRotate (BaseNode *x) |
void | RbtreeRightRotate (BaseNode *y) |
void | RbtreeDeleteFixup (BaseNode *node, BaseNode *parent) |
template<typename Data , typename Func > | |
ErrorCode | RbtreeForeachStart (BaseNode *node, Func func) |
template<typename Data , typename Func > | |
ErrorCode | RbtreeForeach (BaseNode *node, Func func) |
void | RbtreeGetNum (BaseNode *node, uint32_t *count) |
BaseNode * | Search (BaseNode *x, const Key &key) |
Static Private Member Functions | |
template<typename Data , SizeLimitMode LimitMode> | |
static Node< Data > * | ToDerivedType (BaseNode *node) |
Private Attributes | |
BaseNode * | root_ = nullptr |
红黑树的根节点 (Root node of the Red-Black Tree). | |
LibXR::Mutex | mutex_ |
互斥锁,确保线程安全 (Mutex for thread-safety). | |
int(* | compare_fun_ )(const Key &, const Key &) |
键值比较函数 (Function for key comparison). | |
红黑树实现,支持泛型键和值,并提供线程安全操作 (Red-Black Tree implementation supporting generic keys and values with thread-safe operations).
This class implements a self-balancing binary search tree (Red-Black Tree) to provide efficient insert, delete, and search operations. 该类实现了自平衡二叉查找树(红黑树),以提供高效的插入、删除和查找操作。
Key | 用作节点键的类型 (Type used as node key). |
|
strong |
|
inlineexplicit |
构造函数,初始化红黑树 (Constructor initializing the Red-Black Tree).
compare_fun | 比较函数指针,用于键值比较 (Comparison function pointer for key comparison). |
Definition at line 107 of file rbt.hpp.
|
inline |
从树中删除指定节点 (Delete a specified node from the tree).
node | 要删除的节点 (Node to be deleted). |
Definition at line 141 of file rbt.hpp.
|
inline |
遍历红黑树并执行用户提供的操作 (Traverse the Red-Black Tree and apply a user-defined function).
Data | 存储的数据类型 (Type of data stored in the node). |
Func | 用户定义的操作函数 (User-defined function to apply). |
LimitMode | 结构大小检查模式 (Size limit check mode). |
func | 作用于每个节点的函数 (Function applied to each node). |
ErrorCode::OK
(Operation result: ErrorCode::OK
on success).
|
inline |
获取红黑树的下一个中序遍历节点 (Get the next node in in-order traversal).
Data | 存储的数据类型 (Type of data stored in the node). |
node | 当前节点 (Current node). |
Definition at line 291 of file rbt.hpp.
|
inline |
|
inline |
在树中插入新节点 (Insert a new node into the tree).
KeyType | 插入键的类型 (Type of the key to insert). |
node | 要插入的节点 (Node to insert). |
key | 节点键 (Key of the node). |
|
inlineprivate |
Definition at line 485 of file rbt.hpp.
|
inlineprivate |
|
inlineprivate |
|
inlineprivate |
|
inlineprivate |
|
inlineprivate |
Definition at line 351 of file rbt.hpp.
|
inlineprivate |
|
inlineprivate |
|
inlineprivate |
|
inline |
搜索红黑树中的节点 (Search for a node in the Red-Black Tree).
Data | 存储的数据类型 (Type of data stored in the node). |
LimitMode | 结构大小检查模式 (Size limit check mode). |
key | 要搜索的键 (Key to search for). |
nullptr
(Pointer to the found node, or nullptr
if not found). Definition at line 122 of file rbt.hpp.
|
private |
|
private |
|
private |