| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- #ifndef TOOLBOX_ARRAY_H
- #define TOOLBOX_ARRAY_H
- #include "toolbox/vptr.h"
- #include "toolbox/return_codes.h"
- #include <stdint.h>
- #include <stddef.h>
- #include <string.h>
- #ifdef TOOLBOX_TYPEDEF
- typedef struct array array_st;
- #endif
- struct array {
- size_t item_size;
- size_t size;
- size_t alloc_size;
- void **data;
- };
- /**
- * @brief Create dynamic array pointer
- *
- * @details Creates an pointer to an array with an allocated size of arr_size
- * and with item size of item_size
- *
- * @param arr_size The size to be pre-allocated
- * @param item_size The size of the array item in bytes
- *
- * @return return struct array *
- */
- __attribute__((__pure__))
- struct array *
- array_create(size_t arr_size, size_t item_size);
- RET_TYPE
- array_clear(struct array *self);
- RET_TYPE
- array_destroy(struct array **self);
- __attribute__((__pure__))
- size_t
- array_index_of(const struct array *self
- , const void *item);
- __attribute__((__pure__))
- _Bool
- array_contain(const struct array *self
- , const void *item);
- __attribute__((__pure__))
- size_t
- array_count(const struct array *self, const void *item);
- RET_TYPE
- array_set(struct array *self, const size_t p_index
- , const void *item);
- RET_TYPE
- array_insert(struct array *self, const size_t p_index
- , const void *item);
- RET_TYPE
- array_append(struct array *self, const void *item);
- RET_TYPE
- array_prepend(struct array *self, const void *item);
- RET_TYPE
- array_delete(struct array *self, const size_t p_index);
- RET_TYPE
- array_remove(struct array *self, const void *item);
- RET_TYPE
- array_for_each(struct array *self, void (*for_each)(void *item));
- #endif
|