diff options
author | Ekaitz Zarraga <ekaitz@elenq.tech> | 2024-02-28 22:03:04 +0100 |
---|---|---|
committer | Ekaitz Zarraga <ekaitz@elenq.tech> | 2024-02-28 22:08:20 +0100 |
commit | a1f6afa69bb25191d4b206e4ecba1557629330bc (patch) | |
tree | 3041324b6f0932ef036e9de230e965a4400f2b08 /src/piece-table.c |
First commit with project structure
Diffstat (limited to 'src/piece-table.c')
-rw-r--r-- | src/piece-table.c | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/src/piece-table.c b/src/piece-table.c new file mode 100644 index 0000000..490950b --- /dev/null +++ b/src/piece-table.c @@ -0,0 +1,54 @@ +#include "piece-table.h" + +static piece *make_piece() { + return malloc(sizeof(piece)); +} + +static piece *make_sentinel() { + piece *p = make_piece(); + p->length = 0; + p->next = NULL; + p->prev = NULL; + p->start = NULL; + return p; +} + +bool init_piece_table(piece_table *pt, char *orig) { + piece *pc, *sentinel; + + init_growable_buffer(&pt->add); + init_fixed_buffer(&pt->orig, orig); + + pt->length = pt->orig.size; + + pc = make_piece(); + if(pc == NULL){ + return false; + } + sentinel = make_sentinel(); + if(sentinel == NULL){ + return false; + } + pc->start = pt->orig.content; + pc->length = pt->orig.size; + pc->prev = sentinel; + pc->next = sentinel; + + pt->cached_offset = 0; + pt->cached = pc; + return true; +} + +void free_piece_table(piece_table *pt) { + free_growable_buffer(&pt->add); + free_fixed_buffer(&pt->orig); + free_piece_list(pt->sentinel); + pt->sentinel = NULL; + pt->cached = NULL; + pt->cached_offset = 0; + pt->length = 0; +} + +void free_piece_list(piece *pt) { + // TODO +} |