Major changes to api and structure.

- Remove newline caching
- limit petal sizes
- make public facing api use points only
- fix iterators (chunk & line)
This commit is contained in:
2026-08-02 11:07:04 +01:00
parent 89b24a7488
commit 51e193d28b
16 changed files with 355 additions and 422 deletions
+2 -18
View File
@@ -12,31 +12,15 @@ struct AppendBuffer : Buffer {
uint32_t current_offset{0};
uint32_t t_offset{0};
using LChunk = uint32_t[CHUNK_SIZE];
std::vector<LChunk *> newlines;
LChunk *l_current;
uint32_t l_offset{0};
AppendBuffer();
~AppendBuffer();
uint32_t key(char c);
uint32_t append(const char *text, uint32_t length, uint32_t *line_count);
uint32_t append(const char *text, uint32_t length);
const char *read(uint32_t pos, uint32_t *out_len);
uint32_t count_lines(uint32_t pos, uint32_t length);
uint32_t next_newline(uint32_t pos);
uint32_t nth_newline(uint32_t pos, uint32_t n);
private:
inline uint32_t newline_value_at(uint32_t flat_index);
inline uint32_t length();
inline void new_text_chunk();
inline void new_line_chunk();
inline uint32_t find_newline(uint32_t target, uint32_t low, uint32_t high);
inline uint32_t _append(const char *text, uint32_t length);
};
+1 -3
View File
@@ -4,8 +4,6 @@
struct Buffer {
virtual const char *read(uint32_t pos, uint32_t *out_len) = 0;
virtual uint32_t count_lines(uint32_t pos, uint32_t length) = 0;
virtual uint32_t next_newline(uint32_t pos) = 0;
virtual uint32_t nth_newline(uint32_t pos, uint32_t n) = 0;
virtual inline uint32_t length() = 0;
virtual ~Buffer() = default;
};
+3 -6
View File
@@ -5,16 +5,13 @@
struct OriginalBuffer : Buffer {
char *buf;
uint32_t length;
std::vector<uint32_t> newlines;
uint32_t len;
// TODO: replace with file io or even lazy loaded file io for large files/logs etc. later.
OriginalBuffer(char *buf, uint32_t length);
OriginalBuffer(char *buf, uint32_t len);
~OriginalBuffer();
const char *read(uint32_t pos, uint32_t *out_len);
uint32_t count_lines(uint32_t pos, uint32_t length);
uint32_t next_newline(uint32_t pos);
uint32_t nth_newline(uint32_t pos, uint32_t n);
uint32_t length();
};