Lines Matching refs:vec

27 slot(struct vect *vec, size_t i)  in slot()  argument
29 return ((unsigned char *)vec->data) + vec->elt_size * i; in slot()
33 cslot(const struct vect *vec, size_t i) in cslot() argument
35 return ((const unsigned char *)vec->data) + vec->elt_size * i; in cslot()
39 vect_init(struct vect *vec, size_t elt_size) in vect_init() argument
41 *vec = (struct vect){ NULL, 0, 0, elt_size }; in vect_init()
88 vect_reserve(struct vect *vec, size_t count) in vect_reserve() argument
90 if (count > vec->allocated) { in vect_reserve()
91 size_t na = vec->allocated != 0 ? 2 * vec->allocated : 4; in vect_reserve()
94 void *n = realloc(vec->data, na * vec->elt_size); in vect_reserve()
97 vec->data = n; in vect_reserve()
98 vec->allocated = na; in vect_reserve()
100 assert(count <= vec->allocated); in vect_reserve()
105 vect_size(const struct vect *vec) in vect_size() argument
107 return vec->size; in vect_size()
111 vect_empty(const struct vect *vec) in vect_empty() argument
113 return vec->size == 0; in vect_empty()
117 vect_reserve_additional(struct vect *vec, size_t count) in vect_reserve_additional() argument
119 return vect_reserve(vec, vect_size(vec) + count); in vect_reserve_additional()
123 vect_pushback(struct vect *vec, void *eltp) in vect_pushback() argument
125 if (vect_reserve_additional(vec, 1) < 0) in vect_pushback()
127 memcpy(slot(vec, vec->size++), eltp, vec->elt_size); in vect_pushback()
132 vect_erase(struct vect *vec, size_t start, size_t end, in vect_erase() argument
135 assert(start < vect_size(vec) || start == 0); in vect_erase()
136 assert(end <= vect_size(vec)); in vect_erase()
142 dtor(slot(vec, i), data); in vect_erase()
146 memmove(slot(vec, start), slot(vec, end), in vect_erase()
147 slot(vec, vec->size) - slot(vec, end)); in vect_erase()
148 vec->size -= end - start; in vect_erase()
152 vect_popback(struct vect *vec, in vect_popback() argument
155 assert(vect_size(vec) > 0); in vect_popback()
156 vect_erase(vec, vect_size(vec)-1, vect_size(vec), dtor, data); in vect_popback()
160 vect_destroy(struct vect *vec, void (*dtor)(void *emt, void *data), void *data) in vect_destroy() argument
162 if (vec == NULL) in vect_destroy()
165 vect_erase(vec, 0, vect_size(vec), dtor, data); in vect_destroy()
166 assert(vect_size(vec) == 0); in vect_destroy()
167 free(vec->data); in vect_destroy()
171 vect_each(struct vect *vec, void *start_after, in vect_each() argument
175 : ((start_after - vec->data) / vec->elt_size) + 1; in vect_each()
177 for (; i < vec->size; ++i) { in vect_each()
178 void *slt = slot(vec, i); in vect_each()
193 vect_qsort(struct vect *vec, int (*compar)(const void *, const void *)) in vect_qsort() argument
195 qsort(vec->data, vec->size, vec->elt_size, compar); in vect_qsort()
199 vect_each_cst(const struct vect *vec, const void *start_after, in vect_each_cst() argument
202 return vect_each((struct vect *)vec, (void *)start_after, in vect_each_cst()