Fix line finding
This commit is contained in:
parent
32fecc75ec
commit
1e1a147116
1 changed files with 6 additions and 5 deletions
11
file.hpp
11
file.hpp
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue