Fix subtree size accessing
This commit is contained in:
parent
02bdb353a4
commit
32fecc75ec
1 changed files with 4 additions and 4 deletions
8
file.hpp
8
file.hpp
|
@ -4,7 +4,6 @@
|
|||
|
||||
using std::string;
|
||||
typedef unsigned long long count_type;
|
||||
#define RAND_MAX (1 << 62)
|
||||
class line;
|
||||
typedef std::pair<line*, line*> two_lines;
|
||||
|
||||
|
@ -35,13 +34,13 @@ class file {
|
|||
if(get_size(l->left) > k) {
|
||||
// In the left subtree
|
||||
auto two = split(l->left, k);
|
||||
l->size -= two.first->size;
|
||||
l->size -= get_size(two.first);
|
||||
return {two.first, l};
|
||||
}
|
||||
else {
|
||||
// In the right subtree
|
||||
auto two = split(l->right, k - (1+get_size(l->left)));
|
||||
l->size -= two.second->size;
|
||||
l->size -= get_size(two.second);
|
||||
return {l, two.second};
|
||||
}
|
||||
}
|
||||
|
@ -80,6 +79,7 @@ public:
|
|||
srand(120);
|
||||
root = nullptr;
|
||||
}
|
||||
// File access
|
||||
// Don't find index k, but k-th line -> +1
|
||||
line* find(count_type k) {
|
||||
if(k >= root->size)
|
||||
|
@ -87,7 +87,7 @@ public:
|
|||
return find(root, k+1);
|
||||
}
|
||||
|
||||
// File access
|
||||
// Line insert
|
||||
void insert(int k, string s) {
|
||||
line *l = new line(rand(), s);
|
||||
|
||||
|
|
Loading…
Reference in a new issue