2021-11-30 21:29:18 -06:00
|
|
|
#ifndef VEC_H
|
|
|
|
#define VEC_H
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
struct vec {
|
2022-06-27 14:12:26 -05:00
|
|
|
int len; // How many elements are in the vec
|
|
|
|
int size; // The capacity of the vec
|
|
|
|
size_t width; // The size in bytes of an element of the vector
|
2021-11-30 21:29:18 -06:00
|
|
|
void *data;
|
|
|
|
};
|
|
|
|
|
2022-06-27 14:12:26 -05:00
|
|
|
struct vec vec_init(size_t width, int size);
|
2022-02-06 10:14:57 -06:00
|
|
|
struct vec *vec_make(size_t width, int size);
|
2021-11-30 21:29:18 -06:00
|
|
|
void *vec_get(struct vec *vec, int n);
|
|
|
|
void vec_walk(struct vec *vec, void (*fn)(void *data));
|
|
|
|
void vec_clear(struct vec *vec);
|
2022-02-06 10:14:57 -06:00
|
|
|
void *vec_add(struct vec *vec, const void *data);
|
2021-11-30 21:29:18 -06:00
|
|
|
|
|
|
|
/* sort returns 0 for a<=b, 1 for a>b */
|
2022-06-30 10:31:23 -05:00
|
|
|
void *vec_add_sort(struct vec *vec, void *data, int (*sort)(void *a, void *b));
|
2021-11-30 21:29:18 -06:00
|
|
|
void *vec_insert(struct vec *vec, void *data, int n);
|
|
|
|
void *vec_set(struct vec *vec, int n, void *data);
|
2022-06-30 10:31:23 -05:00
|
|
|
void *vec_find(struct vec *v, int (*valid)(void *a, void *data), void *data);
|
2021-11-30 21:29:18 -06:00
|
|
|
void vec_delete(struct vec *vec, int n);
|
|
|
|
void vec_del_order(struct vec *vec, int n);
|
|
|
|
void vec_store(struct vec *vec, FILE *f);
|
|
|
|
void vec_load(struct vec *vec, FILE *f);
|
|
|
|
char *vec_p(struct vec *vec, int n);
|
|
|
|
void vec_expand(struct vec *vec);
|
|
|
|
void vec_fit(struct vec *vec);
|
|
|
|
|
2022-02-06 10:14:57 -06:00
|
|
|
#endif
|