perf: better and efficient vec impl

This commit is contained in:
2025-06-06 19:39:44 +02:00
parent dc6424979e
commit 04a102a7bb
2 changed files with 46 additions and 24 deletions

View File

@@ -14,18 +14,20 @@ void read_press(u_char *, char *);
void strcln(char **dest, const char *source);
struct Vector {
uint32_t length;
uint32_t alloc_len;
uint16_t alloc_size;
void** pages;
uint32_t length;
uint32_t capacity;
void **pages;
};
struct Vector vec_new();
int vec_push(struct Vector*, void* item);
void vec_free(struct Vector*);
void vec_clear(struct Vector*);
void vec_reset(struct Vector*);
void* vec_pop(struct Vector*); // won't free it, nor shrink vec list space
void* vec_get(struct Vector*, size_t index);
int vec_resize(struct Vector *, size_t size);
int vec_reserve(struct Vector *, size_t size);
int vec_reserve_exact(struct Vector *, size_t size);
int vec_push(struct Vector *, void *item);
void vec_free(struct Vector *);
void vec_clear(struct Vector *);
void vec_reset(struct Vector *);
void *vec_pop(struct Vector *); // won't free it, nor shrink vec list space
void *vec_get(struct Vector *, size_t index);
#endif