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
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* VECTOR
|
|
|
|
* ***************************************************************************/
|
|
|
|
|
|
|
|
#define INVALID_VEC_INDEX ((size_t) -1)
|
|
|
|
|
2018-05-06 16:04:34 +02:00
|
|
|
extern vector_t *create_vector(size_t item_size, size_t capacity);
|
|
|
|
extern void destroy_vector(vector_t *);
|
|
|
|
extern vector_t *copy_vector(vector_t *);
|
2018-01-17 19:22:57 +01:00
|
|
|
|
2018-05-06 16:04:34 +02:00
|
|
|
extern size_t vector_size(const vector_t *);
|
|
|
|
extern size_t vector_capacity(const vector_t *);
|
|
|
|
extern size_t vector_index_of(const vector_t *, const void *item);
|
2018-01-17 19:22:57 +01:00
|
|
|
|
2018-05-06 16:04:34 +02:00
|
|
|
extern int vector_push(vector_t *, const void *item);
|
|
|
|
extern int vector_erase(vector_t *, size_t index);
|
|
|
|
extern void vector_clear(vector_t *);
|
2018-02-25 09:39:41 +01:00
|
|
|
extern const void *vector_at_c(const vector_t *vector, size_t index);
|
2018-05-06 16:04:34 +02:00
|
|
|
extern void *vector_at(vector_t *, size_t index);
|
2018-04-22 20:42:22 +02:00
|
|
|
extern 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-03-09 10:44:16 +01:00
|
|
|
#endif /* VECTOR_H */
|