From 1b2c93b2afdbe96a797e240f227d7f75603ebabb Mon Sep 17 00:00:00 2001 From: Matuush Date: Sun, 20 Apr 2025 18:24:23 +0200 Subject: [PATCH] Remove external treap access --- main.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/main.cpp b/main.cpp index 9ac2d22..220b4af 100644 --- a/main.cpp +++ b/main.cpp @@ -47,6 +47,7 @@ void insert(position p, char ch) { insert(p, string{ch}); } void remove(position p, count_type len=1) { file.find(p.r)->text.erase(p.c,len); } void remove(count_type r) { file.remove(r); } void append(string t) { file.append(t); } +count_type get_size() { return file.size(); } // Load file to buffer @@ -66,7 +67,7 @@ bool save(string filename) { if(!outfile.good()) return 1; - for(count_type i = 0; i < file.size(); ++i) + for(count_type i = 0; i < get_size(); ++i) outfile << get_line(i, 0) << std::endl; return 0; } @@ -86,7 +87,7 @@ void print_line(count_type r) { // Print file content void print_file(count_type start = 0) { for(count_type i = start; i < file_offset + LINES; i++) - if(i < file.size()) + if(i < get_size()) print_line(i); else clear_line(i); @@ -215,7 +216,7 @@ void move_cursor(char ch) { break; case 'j': - if(file_offset + cur.r >= file.size()-1) break; + if(file_offset + cur.r >= get_size()-1) break; if(cur.r < LINES-1) { cur.r += 1; move(cur); @@ -265,7 +266,7 @@ void jump(position p) { // Find next string appearance std::pair find(string text) { count_type len = text.size(); - count_type file_size = file.size(); + count_type file_size = get_size(); for(count_type _r = 0; _r < file_size; ++_r) { count_type r = (file_offset + cur.r + _r) % file_size;