2022-10-09 05:13:17 +00:00
|
|
|
#ifndef _RSTL_RED_BLACK_TREE
|
|
|
|
#define _RSTL_RED_BLACK_TREE
|
2022-08-14 18:38:41 +00:00
|
|
|
|
|
|
|
#include "types.h"
|
|
|
|
|
2022-10-03 04:49:11 +00:00
|
|
|
#include "rstl/rmemory_allocator.hpp"
|
|
|
|
|
2022-08-14 18:38:41 +00:00
|
|
|
namespace rstl {
|
|
|
|
template < typename P >
|
|
|
|
struct select1st {};
|
|
|
|
|
|
|
|
template < typename T >
|
|
|
|
struct less {};
|
|
|
|
|
2022-10-03 04:49:11 +00:00
|
|
|
enum node_color {
|
|
|
|
kNC_Red,
|
|
|
|
kNC_Black,
|
|
|
|
};
|
|
|
|
|
2022-10-16 00:03:19 +00:00
|
|
|
void* rbtree_traverse_forward(const void*, void*);
|
|
|
|
|
2022-10-03 04:49:11 +00:00
|
|
|
template < typename T, typename P, int U, typename S = select1st< P >, typename Cmp = less< T >,
|
|
|
|
typename Alloc = rmemory_allocator >
|
|
|
|
class red_black_tree {
|
|
|
|
private:
|
|
|
|
struct node {
|
|
|
|
node_color mColor;
|
|
|
|
node* mParent;
|
|
|
|
node* mLeft;
|
|
|
|
node* mRight;
|
|
|
|
P mValue;
|
2022-10-05 00:16:03 +00:00
|
|
|
|
|
|
|
P& get_value() { return mValue; }
|
2022-10-03 04:49:11 +00:00
|
|
|
};
|
|
|
|
struct header {};
|
|
|
|
|
|
|
|
public:
|
|
|
|
struct const_iterator {
|
|
|
|
node* mNode;
|
|
|
|
const header* mHeader;
|
|
|
|
|
2022-10-05 00:16:03 +00:00
|
|
|
const P* operator->() const { return &mNode->get_value(); }
|
2022-10-03 04:49:11 +00:00
|
|
|
bool operator==(const const_iterator& other) const {
|
|
|
|
return mNode == other.mNode && mHeader == other.mHeader;
|
|
|
|
}
|
|
|
|
bool operator!=(const const_iterator& other) const {
|
2022-10-16 00:03:19 +00:00
|
|
|
// return !(*this == other);
|
|
|
|
return mNode != other.mNode || mHeader != other.mHeader;
|
|
|
|
}
|
|
|
|
|
|
|
|
const_iterator& operator++() {
|
|
|
|
mNode = static_cast<node*>(rbtree_traverse_forward(static_cast<const void*>(mHeader), static_cast<void*>(mNode)));
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
const_iterator operator++(int) {
|
|
|
|
const_iterator result = *this;
|
|
|
|
mNode = static_cast<node*>(rbtree_traverse_forward(static_cast<const void*>(mHeader), static_cast<void*>(mNode)));
|
|
|
|
return result;
|
2022-10-03 04:49:11 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
2022-10-09 05:37:23 +00:00
|
|
|
uchar x0_;
|
|
|
|
uchar x1_;
|
2022-10-03 04:49:11 +00:00
|
|
|
uint x4_;
|
|
|
|
uint x8_;
|
|
|
|
uint xc_;
|
|
|
|
uint x10_;
|
|
|
|
};
|
2022-08-14 18:38:41 +00:00
|
|
|
}; // namespace rstl
|
2022-10-09 05:13:17 +00:00
|
|
|
|
|
|
|
#endif // _RSTL_RED_BLACK_TREE
|