Struct representation of the treap.
More...
|
| Treap () |
| Initialization.
|
|
void | update (int x) |
| Update the subtree size of the node.
|
|
void | rotate (int &x, int t) |
| Rotate without breaking the property of BST.
|
|
void | _insert (int &x, int k) |
| Insert a value into the specified subtree (internal method)
|
|
void | _erase (int &x, int k) |
| Erase a value from the specified subtree (internal method)
|
|
int | _get_k_th (int &x, int k) |
| Find the KTH largest value (internal method)
|
|
int | _get_rank (int x, int k) |
| Query the rank of specified element (internal method)
|
|
int | get_predecessor (int k) |
| Get the predecessor node of element k.
|
|
int | get_next (int k) |
| Get the successor node of element k.
|
|
void | insert (int k) |
| Insert element (External method)
|
|
void | erase (int k) |
| Erase element (External method)
|
|
int | get_k_th (int k) |
| Get the KTH largest value (External method)
|
|
int | get_rank (int k) |
| Get the rank of specified element (External method)
|
|
|
int | root = 0 |
| root of the treap
|
|
int | treapCnt = 0 |
| Total number of current nodes in the treap.
|
|
std::array< int, maxNode > | key = {} |
| Node identifier.
|
|
std::array< int, maxNode > | priority = {} |
| Random priority.
|
|
std::array< std::array< int, 2 >, maxNode > | childs |
|
std::array< int, maxNode > | cnt |
| Maintains the subtree size for ranking query.
|
|
std::array< int, maxNode > | size = {} |
| The number of copies per node.
|
|
Struct representation of the treap.
Definition at line 40 of file treap.cpp.
◆ Treap()
data_structures::treap::Treap::Treap |
( |
| ) |
|
|
inline |
Initialization.
Definition at line 55 of file treap.cpp.
58 }
int treapCnt
Total number of current nodes in the treap.
std::array< int, maxNode > priority
Random priority.
std::array< int, maxNode > size
The number of copies per node.
◆ _erase()
void data_structures::treap::Treap::_erase |
( |
int & | x, |
|
|
int | k ) |
|
inline |
Erase a value from the specified subtree (internal method)
- Parameters
-
x | Erase from the subtree of node x (Usually x=root) |
k | Key to erase |
Definition at line 112 of file treap.cpp.
112 {
116 }
117 else {
119 x = 0;
120 return;
121 }
122
123
127 }
128 } else {
130 }
132 }
std::array< int, maxNode > key
Node identifier.
void rotate(int &x, int t)
Rotate without breaking the property of BST.
void update(int x)
Update the subtree size of the node.
std::array< std::array< int, 2 >, maxNode > childs
void _erase(int &x, int k)
Erase a value from the specified subtree (internal method)
std::array< int, maxNode > cnt
Maintains the subtree size for ranking query.
◆ _get_k_th()
int data_structures::treap::Treap::_get_k_th |
( |
int & | x, |
|
|
int | k ) |
|
inline |
Find the KTH largest value (internal method)
- Parameters
-
x | Query the subtree of node x (Usually x=root) |
k | The queried rank |
- Returns
- The element ranked number k
Definition at line 139 of file treap.cpp.
139 {
142 }
144 if (k <= 0) {
146 }
148 }
double k(double x)
Another test function.
int _get_k_th(int &x, int k)
Find the KTH largest value (internal method)
◆ _get_rank()
int data_structures::treap::Treap::_get_rank |
( |
int | x, |
|
|
int | k ) |
|
inline |
Query the rank of specified element (internal method)
- Parameters
-
x | Query the subtree of node x (Usually x=root) |
k | The queried element |
- Returns
- The rank of element k
Definition at line 155 of file treap.cpp.
155 {
156 if (!x) {
157 return 0;
158 }
161 }
else if (k <
key[x]) {
163 } else {
165 }
166 }
int _get_rank(int x, int k)
Query the rank of specified element (internal method)
◆ _insert()
void data_structures::treap::Treap::_insert |
( |
int & | x, |
|
|
int | k ) |
|
inline |
Insert a value into the specified subtree (internal method)
- Parameters
-
x | Insert into the subtree of node x (Usually x=root) |
k | Key to insert |
Definition at line 85 of file treap.cpp.
85 {
86 if (x) {
89 }
90 else {
93
96 }
97 }
98 } else {
104 }
106 }
void _insert(int &x, int k)
Insert a value into the specified subtree (internal method)
◆ erase()
void data_structures::treap::Treap::erase |
( |
int | k | ) |
|
|
inline |
Erase element (External method)
- Parameters
-
Definition at line 208 of file treap.cpp.
int root
root of the treap
◆ get_k_th()
int data_structures::treap::Treap::get_k_th |
( |
int | k | ) |
|
|
inline |
Get the KTH largest value (External method)
- Parameters
-
- Returns
- The element ranked number x
Definition at line 214 of file treap.cpp.
◆ get_next()
int data_structures::treap::Treap::get_next |
( |
int | k | ) |
|
|
inline |
Get the successor node of element k.
- Parameters
-
- Returns
- The successor
Definition at line 188 of file treap.cpp.
188 {
189 int x =
root, next = -1;
190 while (x) {
193 } else {
195 }
196 }
197 return next;
198 }
◆ get_predecessor()
int data_structures::treap::Treap::get_predecessor |
( |
int | k | ) |
|
|
inline |
Get the predecessor node of element k.
- Parameters
-
- Returns
- The predecessor
Definition at line 172 of file treap.cpp.
172 {
173 int x =
root, pre = -1;
174 while (x) {
177 } else {
179 }
180 }
181 return pre;
182 }
◆ get_rank()
int data_structures::treap::Treap::get_rank |
( |
int | k | ) |
|
|
inline |
Get the rank of specified element (External method)
- Parameters
-
- Returns
- The rank of element k
Definition at line 220 of file treap.cpp.
◆ insert()
void data_structures::treap::Treap::insert |
( |
int | k | ) |
|
|
inline |
Insert element (External method)
- Parameters
-
Definition at line 203 of file treap.cpp.
◆ rotate()
void data_structures::treap::Treap::rotate |
( |
int & | x, |
|
|
int | t ) |
|
inline |
Rotate without breaking the property of BST.
- Parameters
-
x | The node to rotate |
t | 0 represent left hand, while 1 right hand |
Definition at line 71 of file treap.cpp.
◆ update()
void data_structures::treap::Treap::update |
( |
int | x | ) |
|
|
inline |
Update the subtree size of the node.
- Parameters
-
Definition at line 63 of file treap.cpp.
◆ childs
std::array<std::array<int, 2>, maxNode> data_structures::treap::Treap::childs |
Initial value:[i][0] represents the left child of node i, and [i][1] represents the right
Definition at line 45 of file treap.cpp.
◆ cnt
std::array<int, maxNode> data_structures::treap::Treap::cnt |
Initial value:
Maintains the subtree size for ranking query.
Definition at line 49 of file treap.cpp.
◆ key
std::array<int, maxNode> data_structures::treap::Treap::key = {} |
◆ priority
std::array<int, maxNode> data_structures::treap::Treap::priority = {} |
Random priority.
Definition at line 44 of file treap.cpp.
◆ root
int data_structures::treap::Treap::root = 0 |
root of the treap
Definition at line 41 of file treap.cpp.
◆ size
std::array<int, maxNode> data_structures::treap::Treap::size = {} |
The number of copies per node.
Definition at line 51 of file treap.cpp.
◆ treapCnt
int data_structures::treap::Treap::treapCnt = 0 |
Total number of current nodes in the treap.
Definition at line 42 of file treap.cpp.
The documentation for this struct was generated from the following file: