20 lines
595 B
C
20 lines
595 B
C
// vim: set et sw=4 ts=4 tw=80:
|
|
#include "./collections.h"
|
|
|
|
static inline void vector_expand(vector_t* self) {
|
|
if (self->size >= self->capacity) {
|
|
self->capacity *= 2;
|
|
self->elements = realloc(self->elements,
|
|
sizeof(void*) * self->capacity);
|
|
}
|
|
}
|
|
|
|
void vector_init(vector_t* self, const size_t initial_capacity) {
|
|
self->elements = (void**) malloc(sizeof(void*) * initial_capacity);
|
|
self->size = 0;
|
|
self->capacity = initial_capacity;
|
|
}
|
|
|
|
void vector_insert(vector_t* self, const size_t position, const void* element) {
|
|
vector_expand(self);
|
|
}
|