37 lines
820 B
C
37 lines
820 B
C
|
//---
|
||
|
// vector: Simple vectors that only grow
|
||
|
//---
|
||
|
|
||
|
#ifndef TEX_VECTOR
|
||
|
#define TEX_VECTOR
|
||
|
|
||
|
#include <stdint.h>
|
||
|
#include <stddef.h>
|
||
|
|
||
|
typedef struct
|
||
|
{
|
||
|
int len;
|
||
|
int size;
|
||
|
int elsize;
|
||
|
|
||
|
/* This pointer can be cast to the vector type and indexed */
|
||
|
void *data;
|
||
|
} vector_t;
|
||
|
|
||
|
/* vector_make(): Make a new vector of a given type
|
||
|
@vector Pointer to preallocated vector structure
|
||
|
@type Data type */
|
||
|
void vector_make(vector_t *vector, size_t elsize);
|
||
|
|
||
|
#define vector_make(v, T) vector_make(v, sizeof(T))
|
||
|
|
||
|
/* vector_append(): Append a new element to a vector
|
||
|
@vector Pointer to initialized vector
|
||
|
@element Pointer to new element, which will be *copied* */
|
||
|
void vector_append(vector_t *v, void *element);
|
||
|
|
||
|
/* vector_free(): Free a vector's contents */
|
||
|
void vector_free(vector_t *v);
|
||
|
|
||
|
#endif /* TEX_VECTOR */
|