Update treap root on insert
This commit is contained in:
parent
e5bed9f8fe
commit
1582e7e7cb
1 changed files with 2 additions and 3 deletions
5
file.hpp
5
file.hpp
|
@ -30,7 +30,6 @@ public:
|
||||||
// Hopefully with sizes
|
// Hopefully with sizes
|
||||||
two_lines split(line *l, count_type k) {
|
two_lines split(line *l, count_type k) {
|
||||||
if(l == nullptr) return {nullptr, nullptr};
|
if(l == nullptr) return {nullptr, nullptr};
|
||||||
// TODO ??????? sizes dont add up
|
|
||||||
|
|
||||||
if(get_size(l->left) >= k) {
|
if(get_size(l->left) >= k) {
|
||||||
// In the left subtree
|
// In the left subtree
|
||||||
|
@ -103,12 +102,12 @@ public:
|
||||||
|
|
||||||
auto two = split(root, k);
|
auto two = split(root, k);
|
||||||
two.first = join(two.first, l);
|
two.first = join(two.first, l);
|
||||||
join(two);
|
root = join(two);
|
||||||
}
|
}
|
||||||
// Line removal
|
// Line removal
|
||||||
void remove(count_type k) {
|
void remove(count_type k) {
|
||||||
auto two = split(root, k+1);
|
auto two = split(root, k+1);
|
||||||
two.first = split(two.first, k).first;
|
two.first = split(two.first, k).first;
|
||||||
join(two);
|
root = join(two);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue