Remove unused option not to remember node version after update

This commit is contained in:
Matúš Púll 2025-06-25 16:40:27 +02:00
parent 131a0d3384
commit 02dc2b9d7c
2 changed files with 14 additions and 27 deletions

View file

@ -67,7 +67,7 @@ class Treap {
line* insert(line *l, count_type k, string s, bool new_version); line* insert(line *l, count_type k, string s, bool new_version);
line* remove(line *l, count_type k); line* remove(line *l, count_type k);
line* update(line *l, count_type k, string s, bool new_version); line* update(line *l, count_type k, string s);
line* pick_higher(line *l); line* pick_higher(line *l);
void delete_version(line *l); void delete_version(line *l);
@ -95,7 +95,7 @@ public:
// Line meta-operations // Line meta-operations
void insert(count_type k, string s, bool new_version = true); void insert(count_type k, string s, bool new_version = true);
void remove(count_type k); void remove(count_type k);
void update(count_type k, string s, bool new_version = true); void update(count_type k, string s);
// Other line operations // Other line operations
void split_line(position p, bool should_compress = true); void split_line(position p, bool should_compress = true);

View file

@ -122,29 +122,18 @@ line* Treap::remove(line *l, count_type k) {
return new line(l->priority, l->text, lson, son, son); return new line(l->priority, l->text, lson, son, son);
} }
} }
line* Treap::update(line *l, count_type k, string s, bool new_version) { line* Treap::update(line *l, count_type k, string s) {
if(new_version) {
if(k < get_size(l->left)) { if(k < get_size(l->left)) {
line *son = update(l->left, k, s, new_version); line *son = update(l->left, k, s);
return new line(l->priority, l->text, son, l->right, son); return new line(l->priority, l->text, son, l->right, son);
} }
else if(k == get_size(l->left)) else if(k == get_size(l->left))
return new line(l->priority, s, l->left, l->right, nullptr); return new line(l->priority, s, l->left, l->right, nullptr);
else { else {
line *son = update(l->right, k - (1+get_size(l->left)), s, new_version); line *son = update(l->right, k - (1+get_size(l->left)), s);
return new line(l->priority, l->text, l->left, son, son); return new line(l->priority, l->text, l->left, son, son);
} }
} }
else {
if(k < get_size(l->left))
update(l->left, k, s, new_version);
else if(k == get_size(l->left))
l->text = s;
else
update(l->right, k - (1+get_size(l->left)), s, new_version);
return nullptr;
}
}
// Find k-th line of file // Find k-th line of file
line* Treap::find(line *l, count_type k) { line* Treap::find(line *l, count_type k) {
@ -237,7 +226,7 @@ void Treap::remove(count_type k) {
} }
// Line text update // Line text update
void Treap::update(count_type k, string s, bool new_version) { void Treap::update(count_type k, string s) {
if(k >= size()) { if(k >= size()) {
std::cerr << "Updating out of file range\n"; std::cerr << "Updating out of file range\n";
return; return;
@ -246,13 +235,11 @@ void Treap::update(count_type k, string s, bool new_version) {
if(s == find(get_root(), k)->text) if(s == find(get_root(), k)->text)
return; return;
line *new_root = update(get_root(), k, s, new_version); line *new_root = update(get_root(), k, s);
if(new_version) {
root.push(new_root); root.push(new_root);
changes.push({k, 1}); changes.push({k, 1});
} }
}
// Accessing the file // Accessing the file
string Treap::get_line(count_type r, bool substitute_tab) { string Treap::get_line(count_type r, bool substitute_tab) {