Lucien Cartier-Tilet
1e86a8736f
The code has not yet been tested, the only “test” is the static code analysis from within Emacs with LSP with clangd as its backend
39 lines
1.5 KiB
C
39 lines
1.5 KiB
C
#include <stdint.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
#define UNINPLEMENTED printf("%s:%d: Not yet implemented", __FILE__, __LINE__)
|
|
|
|
#define foreach(item, vector) \
|
|
for (int keep = 1, \
|
|
count = 0, \
|
|
size = sizeof(vector->elements) / sizeof *(vector->elements); \
|
|
keep && count != size; \
|
|
keep = !keep, count++) \
|
|
for (item = (vector->elements) + (count * vector->obj_size); keep; \
|
|
keep = !keep)
|
|
|
|
typedef void (*Destructor)(void *element);
|
|
|
|
struct Vector_s {
|
|
void ** elements;
|
|
uint32_t obj_size;
|
|
uint32_t len;
|
|
Destructor destructor;
|
|
};
|
|
|
|
typedef struct Vector_s Vector;
|
|
|
|
Vector * vec_new_with_capacity(uint32_t obj_size,
|
|
uint32_t obj_number,
|
|
Destructor destructor); // DONE
|
|
Vector * vec_new(uint32_t obj_size,
|
|
Destructor destructor); // DONE
|
|
uint32_t vec_len(Vector *self); // DONE
|
|
uint32_t vec_capacity(Vector *self); // DONE
|
|
uint8_t vec_push(Vector *self, void *element); // TODO
|
|
uint8_t vec_pop(Vector *self); // TODO
|
|
void * vec_at(Vector *self, uint32_t index); // DONE
|
|
void * vec_at_safe(Vector *self, uint32_t index); // DONE
|
|
void vec_delete(Vector *self); // DONE
|