#ifndef VEC_H #define VEC_H #include #include #include typedef any {}; typedef vec[any type]() { struct <> { size_t n; size_t s; type *buf; }; static inline struct <> <>create() { return (struct <>){ .n = 0, .s = 0, .buf = NULL }; } static inline void <>append(struct <> *v, type n) { v->n++; if (v->n > v->s) { v->s = v->s == 0 ? 1 : 2 * v->s; v->buf = realloc(v->buf, v->s * sizeof(type)); } v->buf[v->n - 1] = n; } static inline type *<>at(struct <> *v, size_t i) { assert(i < v->n); return &v->buf[i]; } static inline void <>destroy(struct <> *v) { free(v->buf); } } #endif /* VEC_H */