Implement bulk_get_line for faster file printing
This commit is contained in:
parent
d7f45730c2
commit
69f45fe50c
3 changed files with 46 additions and 13 deletions
15
editor.cpp
15
editor.cpp
|
@ -25,9 +25,14 @@ void Editor::print_line(count_type r) {
|
||||||
}
|
}
|
||||||
// Print file content
|
// Print file content
|
||||||
void Editor::print_file(count_type start) {
|
void Editor::print_file(count_type start) {
|
||||||
for(count_type i = start; i < file_offset + LINES; i++)
|
auto lines = file.bulk_get_line(start, LINES);
|
||||||
if(i < file.size())
|
for(count_type i = 0; i < LINES; i++)
|
||||||
print_line(i);
|
if(i < lines.size()) {
|
||||||
|
::move(i, 0);
|
||||||
|
clrtoeol();
|
||||||
|
::move(i, 0);
|
||||||
|
adds(lines[i]);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
clear_line(i);
|
clear_line(i);
|
||||||
}
|
}
|
||||||
|
@ -92,7 +97,7 @@ void Editor::move_cursor(char ch) {
|
||||||
else if(cur.r == LINES-1) {
|
else if(cur.r == LINES-1) {
|
||||||
file_offset++;
|
file_offset++;
|
||||||
jump_line_end();
|
jump_line_end();
|
||||||
print_file();
|
print_file(file_offset);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -105,7 +110,7 @@ void Editor::move_cursor(char ch) {
|
||||||
else if(file_offset > 0) {
|
else if(file_offset > 0) {
|
||||||
file_offset--;
|
file_offset--;
|
||||||
jump_line_end();
|
jump_line_end();
|
||||||
print_file();
|
print_file(file_offset);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,14 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <ncurses.h>
|
#include <ncurses.h>
|
||||||
#include <curses.h>
|
#include <curses.h>
|
||||||
|
#include <vector>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#define TAB_SIZE 2
|
#define TAB_SIZE 2
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
|
using std::vector;
|
||||||
typedef unsigned long long count_type;
|
typedef unsigned long long count_type;
|
||||||
|
|
||||||
// Position
|
// Position
|
||||||
|
|
42
treap.cpp
42
treap.cpp
|
@ -106,19 +106,45 @@ void Treap::remove(count_type k) {
|
||||||
|
|
||||||
// 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) {
|
||||||
string line = get(r);
|
string line = find(r)->text;
|
||||||
if(!substitute_tab)
|
if(substitute_tab)
|
||||||
|
return substitute_tabs(line);
|
||||||
|
else
|
||||||
return line;
|
return line;
|
||||||
string ret = "";
|
}
|
||||||
for(count_type i = 0; i < line.size(); ++i) {
|
// Get multiple adjacent vertices
|
||||||
if(line[i] == '\t')
|
count_type Treap::bulk_find(vector<string> *vec, line *l, count_type k, count_type count) {
|
||||||
for(int j = 0; j < TAB_SIZE; j++)
|
if(l == nullptr) return count;
|
||||||
ret += ' ';
|
|
||||||
|
// Wanted vertex is on the left
|
||||||
|
if(k <= get_size(l->left)) {
|
||||||
|
count_type r = bulk_find(vec, l->left, k, count);
|
||||||
|
if(r > 0)
|
||||||
|
vec->push_back(substitute_tabs(l->text));
|
||||||
|
if(r > 1)
|
||||||
|
return bulk_find(vec, l->right, 0, r-1);
|
||||||
else
|
else
|
||||||
ret += line[i];
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This is the wanted vertex
|
||||||
|
else if(k == get_size(l->left)+1) {
|
||||||
|
vec->push_back(substitute_tabs(l->text));
|
||||||
|
if(count > 1)
|
||||||
|
return bulk_find(vec, l->right, 0, count-1);
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return bulk_find(vec, l->right, k - (1+get_size(l->left)), count);
|
||||||
|
}
|
||||||
|
// Access multiple adjacent vertices
|
||||||
|
vector<string> Treap::bulk_get_line(count_type r, count_type count) {
|
||||||
|
vector<string> ret(0);
|
||||||
|
bulk_find(&ret, root, r+1, count);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO tabs are a grid, not just N tabs
|
// TODO tabs are a grid, not just N tabs
|
||||||
count_type Treap::get_tab_offset(position p) {
|
count_type Treap::get_tab_offset(position p) {
|
||||||
count_type tab_offset = 0;
|
count_type tab_offset = 0;
|
||||||
|
|
Loading…
Reference in a new issue