/* This file was generated by scramble.py. */
#include "vector.h"
#include "scramble.h"
Vector * vector_new(int size)
{
    Vector *v = ALLOCATE0(sizeof *v);
    v->element_size = size;
    return v;
}
void vector_del(Vector *v)
{
    if (v->data) FREE(v->data);
    FREE(v);
}
int vector_cat(Vector *v, void const *data, int n)
{
    int i = v->count;
    v->count += n;
    if (v->count > v->allocated)
    {
        if (v->allocated == 0)
        {
            v->allocated++;
        }
        while (v->count > v->allocated)
        {
            v->allocated *= 2;
        }
        v->data = realloc(v->data, v->element_size * v->allocated);
    }
    memcpy((char *)v->data + i * v->element_size, data, v->element_size * n);
    return i;
}
int vector_add(Vector *v, void *data)
/* the 1 is the number of elements (not bytes) */
{
    return vector_cat(v, data, 1);
}
void * vector_get(Vector *v, int i)
{
    return (char *)v->data + i * v->element_size;
}
void vector_allocate(Vector *v, int size)
{
    v->allocated = v->count = size;
    v->data = realloc(v->data, v->element_size * v->allocated);
    memset((char *)v->data, 0, v->element_size * v->allocated);
}
/* This file was generated by scramble.py. */
