diff --git a/everything.hpp b/everything.hpp index b61a983..d0c188a 100644 --- a/everything.hpp +++ b/everything.hpp @@ -67,7 +67,7 @@ class Treap { line* insert(line *l, count_type k, string s, bool new_version); 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); void delete_version(line *l); @@ -95,7 +95,7 @@ public: // Line meta-operations void insert(count_type k, string s, bool new_version = true); 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 void split_line(position p, bool should_compress = true); diff --git a/treap.cpp b/treap.cpp index e71d101..3ba5f35 100644 --- a/treap.cpp +++ b/treap.cpp @@ -122,27 +122,16 @@ line* Treap::remove(line *l, count_type k) { return new line(l->priority, l->text, lson, son, son); } } -line* Treap::update(line *l, count_type k, string s, bool new_version) { - if(new_version) { - if(k < get_size(l->left)) { - line *son = update(l->left, k, s, new_version); - return new line(l->priority, l->text, son, l->right, son); - } - else if(k == get_size(l->left)) - return new line(l->priority, s, l->left, l->right, nullptr); - else { - line *son = update(l->right, k - (1+get_size(l->left)), s, new_version); - return new line(l->priority, l->text, l->left, son, son); - } +line* Treap::update(line *l, count_type k, string s) { + if(k < get_size(l->left)) { + line *son = update(l->left, k, s); + return new line(l->priority, l->text, son, l->right, son); } + else if(k == get_size(l->left)) + return new line(l->priority, s, l->left, l->right, nullptr); 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; + line *son = update(l->right, k - (1+get_size(l->left)), s); + return new line(l->priority, l->text, l->left, son, son); } } @@ -237,7 +226,7 @@ void Treap::remove(count_type k) { } // 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()) { std::cerr << "Updating out of file range\n"; return; @@ -246,12 +235,10 @@ void Treap::update(count_type k, string s, bool new_version) { if(s == find(get_root(), k)->text) 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); - changes.push({k, 1}); - } + root.push(new_root); + changes.push({k, 1}); } // Accessing the file