Legofit
infers population history from nucleotide site patterns.
ptrvec.h
1#ifndef ARR_PTRVEC_H
2#define ARR_PTRVEC_H
3
4#include "typedefs.h"
5#include <assert.h>
6
7struct PtrVec {
8 unsigned buffsize;
9 unsigned used;
10 void **buff; // array of pointers
11};
12
13PtrVec *PtrVec_new(unsigned n);
14void PtrVec_free(PtrVec *self);
15int PtrVec_push(PtrVec *self, void *val);
16void *PtrVec_pop(PtrVec *self);
17int PtrVec_resize(PtrVec *self, unsigned size);
18static inline void PtrVec_empty(PtrVec *self);
19static inline void *PtrVec_get(PtrVec *self, unsigned i);
20static inline unsigned PtrVec_length(PtrVec *self);
21
22static inline void *PtrVec_get(PtrVec *self, unsigned i) {
23 assert(i < self->used);
24 return self->buff[i];
25}
26
27static inline unsigned PtrVec_length(PtrVec *self) {
28 return self->used;
29}
30
31static inline void PtrVec_empty(PtrVec *self) {
32 self->used = 0;
33}
34
35
36#endif
int PtrVec_resize(PtrVec *self, unsigned size)
Enlarge size of allocated buffer if necessary.
Definition: ptrvec.c:62
PtrVec * PtrVec_new(unsigned n)
Allocate an array with room for n pointers.
Definition: ptrvec.c:17
Definition: ptrvec.h:7