libUTL++
RBtreeNode.h
1 #pragma once
2 
4 
5 #include <libutl/BinTreeNode.h>
6 
8 
9 UTL_NS_BEGIN;
10 
12 
27 
29 class RBtreeNode : public BinTreeNode
30 {
31 public:
32  RBtreeNode()
33  {
34  init();
35  }
36 
37  RBtreeNode(const Object* object, uint_t color = RED)
38  : BinTreeNode(object)
39  {
40  init(color);
41  }
42 
43  RBtreeNode*
44  left() const
45  {
46  return static_cast<RBtreeNode*>(_left);
47  }
48  RBtreeNode*
49  next() const
50  {
51  return static_cast<RBtreeNode*>(BinTreeNode::next());
52  }
53  RBtreeNode*
54  parent() const
55  {
56  return static_cast<RBtreeNode*>(_parent);
57  }
58  RBtreeNode*
59  prev() const
60  {
61  return static_cast<RBtreeNode*>(BinTreeNode::prev());
62  }
63  RBtreeNode*
64  right() const
65  {
66  return static_cast<RBtreeNode*>(_right);
67  }
68  virtual void addFixup();
69  virtual void removeFixup(const BinTreeNode* removedNode);
70  virtual void swapWith(BinTreeNode* rhs);
71 
73  uint_t
74  getColor() const
75  {
76  return (uint_t)_color;
77  }
78 
80  void
82  {
83  _color = color;
84  }
85 
87  RBtreeNode*
88  sibling() const
89  {
90  return (RBtreeNode*)(BinTreeNode::sibling());
91  }
92 
94  enum color_t
95  {
97  RED
98  };
99 
100 private:
101  void init(uint_t color = RED);
102  void
103  deInit()
104  {
105  }
106 
107 private:
108  enum flg_t
109  {
110  flg_color
111  };
112  byte_t _color;
113 };
114 
116 
117 UTL_NS_END;
void deInit()
De-initialize UTL++.
uint_t getColor() const
Get the color (RED or BLACK).
Definition: RBtreeNode.h:74
unsigned char byte_t
Unsigned character.
Definition: types.h:31
Binary tree node.
Definition: BinTreeNode.h:31
unsigned int uint_t
Unsigned integer.
Definition: types.h:59
void setColor(uint_t color)
Set the color (RED or BLACK).
Definition: RBtreeNode.h:81
RBtreeNode * sibling() const
Return self&#39;s sibling (nullptr if none).
Definition: RBtreeNode.h:88
Root of UTL++ class hierarchy.
Definition: Object.h:52
color_t
A node in a red/black tree is colored red or black.
Definition: RBtreeNode.h:94
void init()
Initialize UTL++.
Red/black tree node.
Definition: RBtreeNode.h:29