2018-01-17 19:22:57 +01:00
|
|
|
#ifndef VECTOR_H
|
|
|
|
#define VECTOR_H
|
|
|
|
|
2018-05-06 15:36:53 +02:00
|
|
|
#include "fort_utils.h"
|
2018-01-17 19:22:57 +01:00
|
|
|
|
|
|
|
|
|
|
|
#define INVALID_VEC_INDEX ((size_t) -1)
|
|
|
|
|
2018-09-01 18:42:57 +02:00
|
|
|
FT_INTERNAL
|
|
|
|
vector_t *create_vector(size_t item_size, size_t capacity);
|
|
|
|
|
|
|
|
FT_INTERNAL
|
|
|
|
void destroy_vector(vector_t *);
|
|
|
|
|
|
|
|
FT_INTERNAL
|
|
|
|
size_t vector_size(const vector_t *);
|
|
|
|
|
|
|
|
FT_INTERNAL
|
|
|
|
size_t vector_capacity(const vector_t *);
|
2018-01-17 19:22:57 +01:00
|
|
|
|
2018-09-01 18:42:57 +02:00
|
|
|
FT_INTERNAL
|
|
|
|
int vector_push(vector_t *, const void *item);
|
2018-01-17 19:22:57 +01:00
|
|
|
|
2018-09-01 18:42:57 +02:00
|
|
|
FT_INTERNAL
|
|
|
|
const void *vector_at_c(const vector_t *vector, size_t index);
|
|
|
|
|
|
|
|
FT_INTERNAL
|
|
|
|
void *vector_at(vector_t *, size_t index);
|
|
|
|
|
|
|
|
FT_INTERNAL
|
|
|
|
fort_status_t vector_swap(vector_t *cur_vec, vector_t *mv_vec, size_t pos);
|
2018-01-17 19:22:57 +01:00
|
|
|
|
|
|
|
|
|
|
|
#define FOR_EACH_(type, item, vector, index_name) \
|
2018-03-09 10:44:16 +01:00
|
|
|
size_t index_name = 0; \
|
|
|
|
for (index_name = 0; (index_name < vector_size(vector)) ? ((item = *(type*)vector_at(vector, index_name)), 1) : 0; ++index_name)
|
2018-01-17 19:22:57 +01:00
|
|
|
|
|
|
|
#define FOR_EACH(type, item, vector) \
|
|
|
|
FOR_EACH_(type, item, vector, UNIQUE_NAME(i))
|
|
|
|
|
2018-11-02 22:16:20 +01:00
|
|
|
|
|
|
|
#ifdef FT_TEST_BUILD
|
2018-11-03 07:14:02 +01:00
|
|
|
vector_t *copy_vector(vector_t *);
|
2018-09-01 18:42:57 +02:00
|
|
|
size_t vector_index_of(const vector_t *, const void *item);
|
|
|
|
int vector_erase(vector_t *, size_t index);
|
|
|
|
void vector_clear(vector_t *);
|
|
|
|
#endif
|
|
|
|
|
2018-03-09 10:44:16 +01:00
|
|
|
#endif /* VECTOR_H */
|