/* SPDX-License-Identifier: LGPL-2.1-only */ /* Copyright (C) 2020-2021 Gediminas Jakutis */ #ifndef ALGOS_DEFS_H_INCLUDED #define ALGOS_DEFS_H_INCLUDED #include #include #include #include #include #define try_s(a,l) do {\ if(unlikely(a)) {\ goto l;\ }} while (0); #define try(a,l,e,m,...) do {\ if(unlikely(a)) {\ ret = e;\ rin_err(m __VA_OPT__(,) __VA_ARGS__);\ goto l;\ }} while (0); #if entry_field_size == 8 # ifdef entry_field_signed typedef int8_t field; # else typedef uint8_t field; # endif #elif entry_field_size == 16 # ifdef entry_field_signed typedef int16_t field; # else typedef uint16_t field; # endif #elif entry_field_size == 32 # ifdef entry_field_signed typedef int32_t field; # else typedef uint32_t field; # endif #else # ifdef entry_field_signed typedef int64_t field; # else typedef uint64_t field; # endif #endif #define get(in) (in->settings->access == cached ? in->get_next_element_cache(in) : in->get_next_element_direct(in)) #define put(in, data) (in->settings->access == cached ? in->place_next_element_cache(in, data) : in->place_next_element_direct(in, data)) union nextoff { struct entry_l *next; void *nextaddr; ptrdiff_t offset; int64_t spacer; /* make sure it is 8-byte-alligned on 32 bit pointer systems */ }; union cachewrap { char *cache; struct entry *cache_a; struct entry_l *cache_l; }; /* for array implementation */ struct entry { field val; }; /* for linked list implementation */ struct entry_l { struct entry; union nextoff; }; enum opmode { mode_normal, mode_fetch, mode_generate }; enum accessmode { cached, direct }; enum dataformat { array, list }; enum streamtype { stream_invalid, stream_in, stream_out, stream_outlite, stream_cache, stream_randread }; struct stream { size_t n; int fd; enum streamtype type; char *name; size_t index; struct entry_l *cnode; /* "current" node */ union cachewrap; struct settings *settings; struct entry_l *(*get_next_element_direct)(struct stream * const); struct entry_l *(*get_next_element_cache)(struct stream * const); int (*place_next_element_direct)(struct stream * const, struct entry_l const * const); int (*place_next_element_cache)(struct stream * const, struct entry_l const * const); int (*split)(struct stream * const, struct stream * const, struct stream * const); int (*rewind)(struct stream * const); }; struct settings { size_t ss; size_t to; size_t stride; char *filein; char *fileout; enum opmode opmode; enum dataformat format; enum accessmode access; }; #endif /* ALGOS_DEFS_H_INCLUDED */