gorilla.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // SPDX-License-Identifier: GPL-3.0-or-later
  2. #ifndef GORILLA_H
  3. #define GORILLA_H
  4. #include <stdbool.h>
  5. #include <stdint.h>
  6. #include <stddef.h>
  7. #ifdef __cplusplus
  8. extern "C" {
  9. #endif
  10. struct gorilla_buffer;
  11. typedef struct {
  12. struct gorilla_buffer *next;
  13. uint32_t entries;
  14. uint32_t nbits;
  15. } gorilla_header_t;
  16. typedef struct gorilla_buffer {
  17. gorilla_header_t header;
  18. uint32_t data[];
  19. } gorilla_buffer_t;
  20. typedef struct {
  21. gorilla_buffer_t *head_buffer;
  22. gorilla_buffer_t *last_buffer;
  23. uint32_t prev_number;
  24. uint32_t prev_xor_lzc;
  25. // in bits
  26. uint32_t capacity;
  27. } gorilla_writer_t;
  28. typedef struct {
  29. const gorilla_buffer_t *buffer;
  30. // number of values
  31. size_t entries;
  32. size_t index;
  33. // in bits
  34. size_t capacity; // FIXME: this not needed on the reader's side
  35. size_t position;
  36. uint32_t prev_number;
  37. uint32_t prev_xor_lzc;
  38. uint32_t prev_xor;
  39. } gorilla_reader_t;
  40. gorilla_writer_t gorilla_writer_init(gorilla_buffer_t *gbuf, size_t n);
  41. void gorilla_writer_add_buffer(gorilla_writer_t *gw, gorilla_buffer_t *gbuf, size_t n);
  42. bool gorilla_writer_write(gorilla_writer_t *gw, uint32_t number);
  43. uint32_t gorilla_writer_entries(const gorilla_writer_t *gw);
  44. gorilla_reader_t gorilla_writer_get_reader(const gorilla_writer_t *gw);
  45. gorilla_buffer_t *gorilla_writer_drop_head_buffer(gorilla_writer_t *gw);
  46. uint32_t gorilla_writer_nbytes(const gorilla_writer_t *gw);
  47. bool gorilla_writer_serialize(const gorilla_writer_t *gw, uint8_t *dst, uint32_t dst_size);
  48. uint32_t gorilla_buffer_patch(gorilla_buffer_t *buf);
  49. gorilla_reader_t gorilla_reader_init(gorilla_buffer_t *buf);
  50. bool gorilla_reader_read(gorilla_reader_t *gr, uint32_t *number);
  51. #define GORILLA_BUFFER_SLOTS 128
  52. #define GORILLA_BUFFER_SIZE (GORILLA_BUFFER_SLOTS * sizeof(uint32_t))
  53. #ifdef __cplusplus
  54. }
  55. #endif
  56. #endif /* GORILLA_H */