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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
/* SPDX-License-Identifier: LGPL-2.1-only */
/* Copyright (C) 2020-2021 Gediminas Jakutis */
#ifndef ALGOS_DEFS_H_INCLUDED
#define ALGOS_DEFS_H_INCLUDED
#include <stddef.h>
#include <stdint.h>
#include <sys/types.h>
#include <rin/diagnostic.h>
#include <rin/definitions.h>
#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);
/* 8 to 64 bits fit into basic types */
#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
#elif entry_field_size == 64
# ifdef entry_field_signed
typedef int64_t field;
# else
typedef uint64_t field;
# endif
/* 128 bit and up do not fit in basic types; building composites */
#elif entry_field_size == 128
# ifdef entry_field_signed
typedef struct field {
uint64_t low;
int64_t high;
} field;
# else
typedef struct field {
uint64_t low;
uint64_t high;
} field;
# endif
#elif entry_field_size == 256
# ifdef entry_field_signed
typedef struct field {
uint64_t low;
uint64_t midlow;
uint64_t midhigh;
int64_t high;
} field;
# else
typedef struct field {
uint64_t low;
uint64_t midlow;
uint64_t midhigh;
uint64_t high;
} field;
# endif
#endif
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_lite,
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)(struct stream * const);
int (*put)(struct stream * const, struct entry_l const * const);
int (*split)(struct stream * const, struct stream * const, struct stream * const);
int (*rewind)(struct stream * restrict const);
int (*copy)(struct stream * restrict const, struct stream * restrict 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 */
|