1 #ifndef _SHD_VPLIST_H_ 2 #define _SHD_VPLIST_H_ 3 4 #include <stdio.h> 5 #include <assert.h> 6 7 8 struct vplist { 9 size_t head; 10 size_t tail; 11 size_t allocated; 12 void **l; 13 }; 14 15 16 struct vplist *vplist_create(size_t initial_length); 17 void vplist_flush(struct vplist *v); 18 void vplist_free(struct vplist *v); 19 void vplist_grow(struct vplist *v); 20 void *vplist_pop_head(struct vplist *v); 21 void *vplist_pop_tail(struct vplist *v); 22 23 vplist_append(struct vplist * v,void * item)24static inline void vplist_append(struct vplist *v, void *item) 25 { 26 if (v->tail == v->allocated) 27 vplist_grow(v); 28 v->l[v->tail++] = item; 29 } 30 31 vplist_get(struct vplist * v,size_t i)32static inline void *vplist_get(struct vplist *v, size_t i) 33 { 34 assert(i < (v->tail - v->head)); 35 return v->l[v->head + i]; 36 } 37 38 vplist_len(struct vplist * v)39static inline size_t vplist_len(struct vplist *v) 40 { 41 return v->tail - v->head; 42 } 43 44 #endif 45