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