excit.h 2.45 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
};

15 16
const char * excit_type_name(enum excit_type_e type);

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

27 28
const char * excit_error_name(enum excit_error_e err);

Brice Videau's avatar
Brice Videau committed
29 30 31 32 33
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
34 35
};

Brice Videau's avatar
Brice Videau committed
36 37
typedef struct excit_s *excit_t;

Brice Videau's avatar
Brice Videau committed
38 39 40 41 42 43 44 45 46 47 48 49 50 51
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
52
excit_t excit_alloc(enum excit_type_e type);
53
excit_t excit_alloc_user(const struct excit_func_table_s *functions);
54 55
excit_t excit_dup(const excit_t it);
void excit_free(excit_t it);
Brice Videau's avatar
Brice Videau committed
56

57 58
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
59

60 61 62 63 64 65 66 67
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
68

69 70
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
71

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

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

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

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

80 81 82 83 84
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
85

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