Update treap root on insert

This commit is contained in:
Matúš Púll 2025-03-30 17:01:40 +02:00
parent e5bed9f8fe
commit 1582e7e7cb

View file

@ -30,7 +30,6 @@ public:
// Hopefully with sizes
two_lines split(line *l, count_type k) {
if(l == nullptr) return {nullptr, nullptr};
// TODO ??????? sizes dont add up
if(get_size(l->left) >= k) {
// In the left subtree
@ -103,12 +102,12 @@ public:
auto two = split(root, k);
two.first = join(two.first, l);
join(two);
root = join(two);
}
// Line removal
void remove(count_type k) {
auto two = split(root, k+1);
two.first = split(two.first, k).first;
join(two);
root = join(two);
}
};