excit.h 2.34 KB
Newer Older
Brice Videau's avatar
Brice Videau committed
1 2 3 4 5 6 7 8 9
#ifndef EXCIT_H
#define EXCIT_H 1

enum excit_type_e {
	EXCIT_RANGE,
	EXCIT_CONS,
	EXCIT_REPEAT,
	EXCIT_HILBERT2D,
	EXCIT_PRODUCT,
Brice Videau's avatar
Brice Videau committed
10
	EXCIT_SLICE,
11
	EXCIT_USER,
Brice Videau's avatar
Brice Videau committed
12
	EXCIT_TYPE_MAX
Brice Videau's avatar
Brice Videau committed
13 14
};

Brice Videau's avatar
Brice Videau committed
15 16 17 18 19 20
enum excit_error_e {
	EXCIT_SUCCESS,
	EXCIT_STOPIT,
	EXCIT_ENOMEM,
	EXCIT_EINVAL,
	EXCIT_EDOM,
Brice Videau's avatar
Brice Videau committed
21 22 23
	EXCIT_ENOTSUP,
	EXCIT_ERROR_MAX
};
Brice Videau's avatar
Brice Videau committed
24 25 26 27 28 29

struct excit_s {
	const struct excit_func_table_s *functions;
	ssize_t dimension;
	enum excit_type_e type;
	void *data;
Brice Videau's avatar
Brice Videau committed
30 31
};

Brice Videau's avatar
Brice Videau committed
32 33
typedef struct excit_s *excit_t;

Brice Videau's avatar
Brice Videau committed
34 35 36 37 38 39 40 41 42 43 44 45 46 47
struct excit_func_table_s {
	int (*alloc)(excit_t it);
	void (*free)(excit_t it);
	int (*copy)(excit_t dst_it, const excit_t src_it);
	int (*next)(excit_t it, ssize_t *indexes);
	int (*peek)(const excit_t it, ssize_t *indexes);
	int (*size)(const excit_t it, ssize_t *size);
	int (*rewind)(excit_t it);
	int (*split)(const excit_t it, ssize_t n, excit_t *results);
	int (*nth)(const excit_t it, ssize_t n, ssize_t *indexes);
	int (*n)(const excit_t it, const ssize_t *indexes, ssize_t *n);
	int (*pos)(const excit_t it, ssize_t *n);
};

Brice Videau's avatar
Brice Videau committed
48
excit_t excit_alloc(enum excit_type_e type);
49
excit_t excit_alloc_user(const struct excit_func_table_s *functions);
50 51
excit_t excit_dup(const excit_t it);
void excit_free(excit_t it);
Brice Videau's avatar
Brice Videau committed
52

53 54
int excit_type(excit_t it, enum excit_type_e *type);
int excit_dimension(excit_t it, ssize_t *dimension);
Brice Videau's avatar
Brice Videau committed
55

56 57 58 59 60 61 62 63
int excit_next(excit_t it, ssize_t *indexes);
int excit_peek(const excit_t it, ssize_t *indexes);
int excit_size(const excit_t it, ssize_t *size);
int excit_rewind(excit_t it);
int excit_split(const excit_t it, ssize_t n, excit_t *results);
int excit_nth(const excit_t it, ssize_t n, ssize_t *indexes);
int excit_n(const excit_t it, const ssize_t *indexes, ssize_t *n);
int excit_pos(const excit_t it, ssize_t *n);
Brice Videau's avatar
Brice Videau committed
64

65 66
int excit_skip(excit_t it);
int excit_cyclic_next(excit_t it, ssize_t *indexes, int *looped);
Brice Videau's avatar
Brice Videau committed
67

68
int excit_range_init(excit_t it, ssize_t first, ssize_t last, ssize_t step);
Brice Videau's avatar
Brice Videau committed
69

70
int excit_cons_init(excit_t it, excit_t src, ssize_t n);
Brice Videau's avatar
Brice Videau committed
71

72
int excit_repeat_init(excit_t it, excit_t src, ssize_t n);
Brice Videau's avatar
Brice Videau committed
73

74
int excit_hilbert2d_init(excit_t it, ssize_t order);
Brice Videau's avatar
Brice Videau committed
75

76 77 78 79 80
int excit_product_add(excit_t it, excit_t added_it);
int excit_product_add_copy(excit_t it, excit_t added_it);
int excit_product_count(const excit_t it, ssize_t *count);
int excit_product_split_dim(const excit_t it, ssize_t dim, ssize_t n,
			    excit_t *results);
Brice Videau's avatar
Brice Videau committed
81

82
int excit_slice_init(excit_t it, excit_t src, excit_t indexer);
Brice Videau's avatar
Brice Videau committed
83
#endif