summaryrefslogtreecommitdiff
path: root/cycle.h
diff options
context:
space:
mode:
authornoodle <shawtynoodle@gmail.com>2023-07-10 15:40:08 +0300
committernoodle <shawtynoodle@gmail.com>2023-07-10 15:40:08 +0300
commitb7ac144cd2d242791938b51569effb7a1378a332 (patch)
tree0db39dc6d72a96697707c662c32f4dcdb99372b7 /cycle.h
parent35eacac40f265aad47bf25d10f3ecd3670b79b2f (diff)
Add files
Diffstat (limited to 'cycle.h')
-rw-r--r--cycle.h34
1 files changed, 34 insertions, 0 deletions
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 */