excit.h 2.26 KB
Newer Older
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 11
	EXCIT_SLICE,
	EXCIT_TYPE_MAX
12 13
};

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

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
29 30
};

31 32
typedef struct excit_s *excit_t;

Brice Videau's avatar
Brice Videau committed
33 34 35 36 37 38 39 40 41 42 43 44 45 46
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);
};

47
excit_t excit_alloc(enum excit_type_e type);
48 49
excit_t excit_dup(const excit_t it);
void excit_free(excit_t it);
50

51 52
int excit_type(excit_t it, enum excit_type_e *type);
int excit_dimension(excit_t it, ssize_t *dimension);
53

54 55 56 57 58 59 60 61
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);
62

63 64
int excit_skip(excit_t it);
int excit_cyclic_next(excit_t it, ssize_t *indexes, int *looped);
65

66
int excit_range_init(excit_t it, ssize_t first, ssize_t last, ssize_t step);
67

68
int excit_cons_init(excit_t it, excit_t src, ssize_t n);
69

70
int excit_repeat_init(excit_t it, excit_t src, ssize_t n);
71

72
int excit_hilbert2d_init(excit_t it, ssize_t order);
73

74 75 76 77 78
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);
79

80
int excit_slice_init(excit_t it, excit_t src, excit_t indexer);
81
#endif