|
libxr
Embedded C++ framework for bare-metal, RTOS and Linux
|
红黑树实现,支持泛型键和值,并提供线程安全操作 Red-Black Tree implementation supporting generic keys and values with thread-safe operations. More...
#include <rbt.hpp>
Classes | |
| 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. | |
红黑树实现,支持泛型键和值,并提供线程安全操作 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 |
|
inline |
从树中删除指定节点 / Delete a specified node from the tree.
| node | 要删除的节点 / Node to be deleted. |
Definition at line 139 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. Definition at line 271 of file rbt.hpp.
|
inline |
获取红黑树的下一个中序遍历节点 Get the next node in in-order traversal.
| Data | 存储的数据类型 / Type of data stored in the node. |
| node | 当前节点 / Current node. |
Definition at line 287 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. |
Definition at line 235 of file rbt.hpp.
|
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 120 of file rbt.hpp.