From b7ac144cd2d242791938b51569effb7a1378a332 Mon Sep 17 00:00:00 2001 From: noodle Date: Mon, 10 Jul 2023 15:40:08 +0300 Subject: Add files --- cycle.h | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 cycle.h (limited to 'cycle.h') diff --git a/cycle.h b/cycle.h new file mode 100644 index 0000000..96d98c1 --- /dev/null +++ b/cycle.h @@ -0,0 +1,34 @@ +#ifndef CYCLE_H +#define CYCLE_H + +// cycle +typedef struct Cycle Cycle; + +/* + * cycle_new: create a new cycling iterator + * parameters: + * base (void *) -> pointer to start of array to cycle through + * memb_n (size_t) -> number of elements of array 'base' + * memb_size (size_t) -> size of an element of array 'base' + * returns: + * Cycle * -> the created cylce + * NULL -> failed to allocate memory for cycle + */ +Cycle *cycle_new(const void *base, size_t memb_n, size_t memb_size); + +/* cycle_free: free the cycle. doesn't free buffer pointed to by cycle->base */ +void cycle_free(Cycle *cycle); + +/* cycle_index: get index of current element of cycle */ +size_t cycle_index(Cycle *cycle); + +/* cycle_current: get current element of cycle */ +const void *cycle_current(Cycle *cycle); + +/* cycle_next: move cycle one element forward */ +const void *cycle_next(Cycle *cycle); + +/* cycle_free: move cycle one element backward*/ +const void *cycle_prev(Cycle *cycle); + +#endif /* CYCLE_H */ -- cgit v1.2.3