summaryrefslogtreecommitdiff
path: root/src/piece-table.h
blob: 94ab072a79f555e47ea2944004ef0ec91c02f12e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#ifndef PIECE_TABLE_H
#define PIECE_TABLE_H

#include <malloc.h>
#include <stddef.h>
#include "buffer.h"

struct piece {
    char *start;
    size_t length;
    struct piece *next;
    struct piece *prev;
};

typedef struct piece piece;

typedef struct {
    fixed_buffer orig;
    growable_buffer add;
    piece *sentinel;
    size_t length;

    piece *cached;
    size_t cached_offset;
} piece_table;

bool init_piece_table(piece_table *pt, char *orig);
void free_piece_table(piece_table *pt);

void free_piece_list(piece *pt);

#endif // PIECE_TABLE_H