diff --git a/include/ordinary.h b/include/ordinary.h index 76741c0..043cab8 100644 --- a/include/ordinary.h +++ b/include/ordinary.h @@ -1,35 +1,9 @@ #ifndef __ORDINARY_H_ #define __ORDINARY_H_ -#include - -struct ordinary_node { - struct ordinary_node *prev; - struct ordinary_node *next; - void *val; -}; - -struct ordinary_list { - struct ordinary_node *head; - struct ordinary_node *tail; - uint32_t count; - uint32_t limit; -}; - -typedef uint8_t (*callback)(struct ordinary_node *node, uint32_t idx); - -void ordinary_list_new(struct ordinary_list *list, uint32_t limit); -void ordinary_list_delete(struct ordinary_list *list); - -uint8_t ordinary_list_empty(struct ordinary_list *list); -uint8_t ordinary_list_full(struct ordinary_list *list); -struct ordinary_node *ordinary_list_at(struct ordinary_list *list, uint32_t idx); -struct ordinary_node *ordinary_list_find(struct ordinary_list *list, callback cb); -uint8_t ordinary_list_for(struct ordinary_list *list, callback cb); - -struct ordinary_node *ordinary_list_add(struct ordinary_list *list, void *val); -void ordinary_list_move(struct ordinary_list *dst, struct ordinary_list *src, struct ordinary_node *node); -struct ordinary_node *ordinary_list_pop(struct ordinary_list *list); -void ordinary_list_drop(struct ordinary_list *list, struct ordinary_node *node); +#include +#include +#include +#include #endif diff --git a/include/ordinary/build.h b/include/ordinary/build.h new file mode 100644 index 0000000..d1adde5 --- /dev/null +++ b/include/ordinary/build.h @@ -0,0 +1,9 @@ +#ifndef __ORDINARY_BUILD_H_ +#define __ORDINARY_BUILD_H_ + +#include + +void ordinary_list_new(struct ordinary_list *list, uint32_t limit); +void ordinary_list_delete(struct ordinary_list *list); + +#endif diff --git a/include/ordinary/idx.h b/include/ordinary/idx.h new file mode 100644 index 0000000..f5cf503 --- /dev/null +++ b/include/ordinary/idx.h @@ -0,0 +1,11 @@ +#ifndef __ORDINARY_IDX_H_ +#define __ORDINARY_IDX_H_ + +#include + +typedef uint8_t (*ordinary_cb)(struct ordinary_node *node, uint32_t idx); + +struct ordinary_node *ordinary_list_find(struct ordinary_list *list, ordinary_cb cb); +uint8_t ordinary_list_for(struct ordinary_list *list, ordinary_cb cb); + +#endif diff --git a/include/ordinary/inspect.h b/include/ordinary/inspect.h new file mode 100644 index 0000000..c2d1c03 --- /dev/null +++ b/include/ordinary/inspect.h @@ -0,0 +1,10 @@ +#ifndef __ORDINARY_INSPECT_H_ +#define __ORDINARY_INSPECT_H_ + +#include + +uint8_t ordinary_list_empty(struct ordinary_list *list); +uint8_t ordinary_list_full(struct ordinary_list *list); +struct ordinary_node *ordinary_list_at(struct ordinary_list *list, uint32_t idx); + +#endif diff --git a/include/ordinary/list.h b/include/ordinary/list.h new file mode 100644 index 0000000..0d56f53 --- /dev/null +++ b/include/ordinary/list.h @@ -0,0 +1,19 @@ +#ifndef __ORDINARY_LIST_H_ +#define __ORDINARY_LIST_H_ + +#include + +struct ordinary_node { + struct ordinary_node *prev; + struct ordinary_node *next; + void *val; +}; + +struct ordinary_list { + struct ordinary_node *head; + struct ordinary_node *tail; + uint32_t count; + uint32_t limit; +}; + +#endif diff --git a/include/ordinary/maint.h b/include/ordinary/maint.h new file mode 100644 index 0000000..07b5741 --- /dev/null +++ b/include/ordinary/maint.h @@ -0,0 +1,11 @@ +#ifndef __ORDINARY_MAINT_H_ +#define __ORDINARY_MAINT_H_ + +#include + +struct ordinary_node *ordinary_list_add(struct ordinary_list *list, void *val); +void ordinary_list_move(struct ordinary_list *dst, struct ordinary_list *src, struct ordinary_node *node); +struct ordinary_node *ordinary_list_pop(struct ordinary_list *list); +void ordinary_list_drop(struct ordinary_list *list, struct ordinary_node *node); + +#endif diff --git a/src/build.c b/src/build.c index f44777b..9d934cb 100644 --- a/src/build.c +++ b/src/build.c @@ -1,4 +1,4 @@ -#include +#include #include void ordinary_list_new(struct ordinary_list *list, uint32_t limit) { diff --git a/src/idx.c b/src/idx.c index 94d3c45..8998962 100644 --- a/src/idx.c +++ b/src/idx.c @@ -1,20 +1,7 @@ -#include +#include +#include -struct ordinary_node *ordinary_list_at(struct ordinary_list *list, uint32_t idx) { - struct ordinary_node *node = list->head; - - for(; node; node = node->next) { - idx -= 1; - - if(!idx) { - return node; - } - } - - return NULL; -} - -struct ordinary_node *ordinary_list_find(struct ordinary_list *list, callback cb) { +struct ordinary_node *ordinary_list_find(struct ordinary_list *list, ordinary_cb cb) { struct ordinary_node *node = list->head; uint32_t idx = 0; @@ -31,7 +18,7 @@ struct ordinary_node *ordinary_list_find(struct ordinary_list *list, callback cb return NULL; } -uint8_t ordinary_list_for(struct ordinary_list *list, callback cb) { +uint8_t ordinary_list_for(struct ordinary_list *list, ordinary_cb cb) { struct ordinary_node *node = list->head; uint32_t idx = 0, res = 0; diff --git a/src/inspect.c b/src/inspect.c index 2449369..08dd135 100644 --- a/src/inspect.c +++ b/src/inspect.c @@ -1,4 +1,5 @@ -#include +#include +#include uint8_t ordinary_list_empty(struct ordinary_list *list) { return !list->head; @@ -7,3 +8,17 @@ uint8_t ordinary_list_empty(struct ordinary_list *list) { uint8_t ordinary_list_full(struct ordinary_list *list) { return !list->limit || list->count == list->limit; } + +struct ordinary_node *ordinary_list_at(struct ordinary_list *list, uint32_t idx) { + struct ordinary_node *node = list->head; + + for(; node; node = node->next) { + idx -= 1; + + if(!idx) { + return node; + } + } + + return NULL; +} diff --git a/src/maint.c b/src/maint.c index a109eca..108b0a0 100644 --- a/src/maint.c +++ b/src/maint.c @@ -1,4 +1,6 @@ -#include +#include +#include +#include static void ordinary_list_insert(struct ordinary_list *list, struct ordinary_node *node) { if(!list->head) {