Made treap size comparisons inclusive
This commit is contained in:
parent
1e1a147116
commit
d6e22b641b
1 changed files with 3 additions and 1 deletions
4
file.hpp
4
file.hpp
|
@ -32,7 +32,7 @@ public:
|
||||||
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};
|
||||||
|
|
||||||
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->size -= get_size(two.first);
|
l->size -= get_size(two.first);
|
||||||
|
@ -45,6 +45,7 @@ public:
|
||||||
return {l, two.second};
|
return {l, two.second};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Join two treaps
|
// Join two treaps
|
||||||
// Hopefully with working sizes
|
// Hopefully with working sizes
|
||||||
line* join(line *a, line *b) {
|
line* join(line *a, line *b) {
|
||||||
|
@ -63,6 +64,7 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
line* join(two_lines two) { return join(two.first, two.second); }
|
line* join(two_lines two) { return join(two.first, two.second); }
|
||||||
|
|
||||||
// Find k-th line of file
|
// Find k-th line of 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;
|
||||||
|
|
Loading…
Reference in a new issue