libflint/include/lfvector.h

44 lines
990 B
C
Raw Normal View History

2023-10-25 14:56:41 +00:00
#ifndef LIBFLINT_H_VECTOR
#define LIBFLINT_H_VECTOR
#include <memory.h>
typedef struct Vector {
size_t capacity;
size_t length;
void **elements;
void (*destroy)(void *data);
} Vector;
int vec_init(Vector *vec, void (*destroy)(void *data));
int vec_init_with_capacity(Vector *vec, void (*destroy)(void *data), size_t cap);
void vec_destroy(Vector *vec);
int vec_insert(Vector *vec, void *data, size_t index);
int vec_push(Vector *vec, void *data);
void *vec_safe_at(Vector *vec, size_t index);
void *vec_remove(Vector *vec, size_t index);
2023-10-25 15:42:38 +00:00
int vec_shrink(Vector *vec);
2023-11-29 22:39:59 +00:00
const void *vec_min(const Vector *vec, int(*cmp)(const void *a, const void *b));
const void *vec_max(const Vector *vec, int(*cmp)(const void *a, const void *b));
int vec_cmp_int(const void *a, const void *b);
int vec_cmp_char(const void *a, const void *b);
2023-10-25 14:56:41 +00:00
#define vec_at(v, i) (v)->elements[(i)]
#define vec_len(v) (v)->length
2023-10-25 15:42:38 +00:00
#define vec_cap(v) (v)->capacity
2023-10-25 14:56:41 +00:00
#endif // LIBFLINT_H_VECTOR