summaryrefslogtreecommitdiffstats
path: root/src/defs.h
blob: 3b8f1c13e76d823eded7bd9c1541c205404e47b5 (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
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
/* SPDX-License-Identifier: LGPL-2.1-only */

/* Copyright (C) 2020 Gediminas Jakutis */

#ifndef ALGOS_DEFS_H_INCLUDED
#define ALGOS_DEFS_H_INCLUDED

#include <stddef.h>
#include <stdint.h>
#include <sys/types.h>

#define try_s(a,l) do {\
	if(a) {\
		goto l;\
	}} while (0);

#define try(a,l,e) do {\
	if(a) {\
		ret = e;\
		goto l;\
	}} while (0);

#define get(in, idx, data) (in->cached ? in->get_element_cache(in, idx, data) | in->get_element(in, idx, data))
#define put(in, idx, data) (in->cached ? in->put_element_cache(in, idx, data) | in->put_element(in, idx, data))

/* for array implementation */
struct entry {
	uint64_t val;
};

/* for linked list implementation */
struct entry_l {
	struct entry;
	int32_t next; /* """pointer""" to the next element. */
	int32_t prev; /* """pointer""" to the previous element. */
};

enum opmode {
	mode_normal,
	mode_fetch,
	mode_generate
};

enum accessmode {
	cached,
	direct
};

enum dataformat {
	array,
	list
};

struct stream {
	size_t n;
	ssize_t prev_idx;
	int fd;
	int out;
	int cached;
	char *name;
	struct entry_l *cache;
	int (*get_element)(struct stream * const restrict, size_t, struct entry_l *);
	int (*put_element)(struct stream * const restrict, size_t, struct entry_l *);
	int (*get_element_cache)(struct stream * const restrict, size_t, struct entry_l *);
	int (*put_element_cache)(struct stream * const restrict, size_t, struct entry_l *);
};

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 */