master
h 85 lines 2.32 KB
Raw
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 #ifndef GORILLA_H
4 #define GORILLA_H
5
6 #include <stdbool.h>
7 #include <stdint.h>
8 #include <stddef.h>
9
10 #ifdef __cplusplus
11 extern "C" {
12 #endif
13
14 struct gorilla_buffer;
15
16 typedef struct {
17 struct gorilla_buffer *next;
18 uint32_t entries;
19 uint32_t nbits;
20 } gorilla_header_t;
21
22 typedef struct gorilla_buffer {
23 gorilla_header_t header;
24 uint32_t data[];
25 } gorilla_buffer_t;
26
27 typedef struct {
28 gorilla_buffer_t *head_buffer;
29 gorilla_buffer_t *last_buffer;
30
31 uint32_t prev_number;
32 uint32_t prev_xor_lzc;
33
34 // in bits
35 uint32_t capacity;
36 } gorilla_writer_t;
37
38 typedef struct {
39 const gorilla_buffer_t *buffer;
40
41 // number of values
42 size_t entries;
43 size_t index;
44
45 // in bits
46 size_t capacity; // FIXME: this not needed on the reader's side
47 size_t position;
48
49 uint32_t prev_number;
50 uint32_t prev_xor_lzc;
51 uint32_t prev_xor;
52 } gorilla_reader_t;
53
54 gorilla_writer_t gorilla_writer_init(gorilla_buffer_t *gbuf, size_t n);
55 void gorilla_writer_add_buffer(gorilla_writer_t *gw, gorilla_buffer_t *gbuf, size_t n);
56 bool gorilla_writer_write(gorilla_writer_t *gw, uint32_t number);
57 uint32_t gorilla_writer_entries(const gorilla_writer_t *gw);
58
59 struct aral;
60 void gorilla_writer_aral_unmark(const gorilla_writer_t *gw, struct aral *ar);
61
62 gorilla_reader_t gorilla_writer_get_reader(const gorilla_writer_t *gw);
63
64 gorilla_buffer_t *gorilla_writer_drop_head_buffer(gorilla_writer_t *gw);
65
66 uint32_t gorilla_writer_actual_nbytes(const gorilla_writer_t *gw);
67 uint32_t gorilla_writer_optimal_nbytes(const gorilla_writer_t *gw);
68 bool gorilla_writer_serialize(const gorilla_writer_t *gw, uint8_t *dst, uint32_t dst_size);
69
70 uint32_t gorilla_buffer_patch(gorilla_buffer_t *buf);
71 size_t gorilla_buffer_unpatched_nbuffers(const gorilla_buffer_t *gbuf);
72 size_t gorilla_buffer_unpatched_nbytes(const gorilla_buffer_t *gbuf);
73 gorilla_reader_t gorilla_reader_init(gorilla_buffer_t *buf);
74 bool gorilla_reader_read(gorilla_reader_t *gr, uint32_t *number);
75
76 #define RRDENG_GORILLA_32BIT_SLOT_BYTES sizeof(uint32_t)
77 #define RRDENG_GORILLA_32BIT_SLOT_BITS (RRDENG_GORILLA_32BIT_SLOT_BYTES * CHAR_BIT)
78 #define RRDENG_GORILLA_32BIT_BUFFER_SLOTS 128
79 #define RRDENG_GORILLA_32BIT_BUFFER_SIZE (RRDENG_GORILLA_32BIT_BUFFER_SLOTS * RRDENG_GORILLA_32BIT_SLOT_BYTES)
80
81 #ifdef __cplusplus
82 }
83 #endif
84
85 #endif /* GORILLA_H */