Fix line finding

This commit is contained in:
Matúš Púll 2025-03-28 16:37:45 +01:00
parent 32fecc75ec
commit 1e1a147116

View file

@ -18,6 +18,7 @@ struct line {
// Treap representation of a file
class file {
public:
line* root;
// Get size uf a subtreap
@ -66,12 +67,12 @@ class file {
line* find(line* l, count_type k) {
if(l == nullptr) return nullptr;
if(k >= get_size(l->left))
if(k <= get_size(l->left))
return find(l->left, k);
else if(k > l->size+1)
return find(l->right, k - (1+get_size(l->left)) );
else
else if(k == get_size(l->left)+1)
return l;
else
return find(l->right, k - (1+get_size(l->left)) );
}
public:
@ -97,7 +98,7 @@ public:
}
auto two = split(root, k);
join(two.first, l);
two.first = join(two.first, l);
join(two);
}
// Line removal