Correct some mistakes in treap functions

This commit is contained in:
Matúš Púll 2025-03-28 18:17:43 +01:00
parent 734588316d
commit e5bed9f8fe

View file

@ -30,16 +30,19 @@ 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
auto two = split(l->left, k); auto two = split(l->left, k);
l->left = two.second;
l->size -= get_size(two.first); l->size -= get_size(two.first);
return {two.first, l}; return {two.first, l};
} }
else { else {
// In the right subtree // In the right subtree
auto two = split(l->right, k - (1+get_size(l->left))); auto two = split(l->right, k - (1+get_size(l->left)));
l->right = two.first;
l->size -= get_size(two.second); l->size -= get_size(two.second);
return {l, two.second}; return {l, two.second};
} }
@ -104,8 +107,8 @@ public:
} }
// Line removal // Line removal
void remove(count_type k) { void remove(count_type k) {
auto two = split(root, k); auto two = split(root, k+1);
two.first = split(two.first, k-1).first; two.first = split(two.first, k).first;
join(two); join(two);
} }
}; };