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 // 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);
} }
}; };