Lines Matching +full:- +full:v
4 * SPDX-License-Identifier: BSD-2-Clause
6 * Copyright (c) 2018-2021 Gavin D. Howard and contributors.
44 void bc_vec_grow(BcVec *restrict v, size_t n) { in bc_vec_grow() argument
46 size_t len, cap = v->cap; in bc_vec_grow()
49 len = bc_vm_growSize(v->len, n); in bc_vec_grow()
54 v->v = bc_vm_realloc(v->v, bc_vm_arraySize(cap, v->size)); in bc_vec_grow()
55 v->cap = cap; in bc_vec_grow()
59 void bc_vec_init(BcVec *restrict v, size_t esize, BcVecFree dtor) { in bc_vec_init() argument
61 assert(v != NULL && esize); in bc_vec_init()
62 v->size = esize; in bc_vec_init()
63 v->cap = BC_VEC_START_CAP; in bc_vec_init()
64 v->len = 0; in bc_vec_init()
65 v->dtor = dtor; in bc_vec_init()
66 v->v = bc_vm_malloc(bc_vm_arraySize(BC_VEC_START_CAP, esize)); in bc_vec_init()
69 void bc_vec_expand(BcVec *restrict v, size_t req) { in bc_vec_expand() argument
71 assert(v != NULL); in bc_vec_expand()
73 if (v->cap < req) { in bc_vec_expand()
79 v->v = bc_vm_realloc(v->v, bc_vm_arraySize(req, v->size)); in bc_vec_expand()
80 v->cap = req; in bc_vec_expand()
86 void bc_vec_npop(BcVec *restrict v, size_t n) { in bc_vec_npop() argument
90 assert(v != NULL && n <= v->len); in bc_vec_npop()
94 if (v->dtor == NULL) v->len -= n; in bc_vec_npop()
96 size_t len = v->len - n; in bc_vec_npop()
97 while (v->len > len) v->dtor(v->v + (v->size * --v->len)); in bc_vec_npop()
103 void bc_vec_npopAt(BcVec *restrict v, size_t n, size_t idx) { in bc_vec_npopAt() argument
107 assert(v != NULL); in bc_vec_npopAt()
108 assert(idx + n < v->len); in bc_vec_npopAt()
110 ptr = bc_vec_item(v, idx); in bc_vec_npopAt()
111 data = bc_vec_item(v, idx + n); in bc_vec_npopAt()
115 if (v->dtor != NULL) { in bc_vec_npopAt()
119 for (i = 0; i < n; ++i) v->dtor(bc_vec_item(v, idx + i)); in bc_vec_npopAt()
122 v->len -= n; in bc_vec_npopAt()
123 memmove(ptr, data, (v->len - idx) * v->size); in bc_vec_npopAt()
128 void bc_vec_npush(BcVec *restrict v, size_t n, const void *data) { in bc_vec_npush() argument
132 assert(v != NULL && data != NULL); in bc_vec_npush()
136 if (v->len + n > v->cap) bc_vec_grow(v, n); in bc_vec_npush()
138 memcpy(v->v + (v->size * v->len), data, v->size * n); in bc_vec_npush()
139 v->len += n; in bc_vec_npush()
144 inline void bc_vec_push(BcVec *restrict v, const void *data) { in bc_vec_push() argument
145 bc_vec_npush(v, 1, data); in bc_vec_push()
148 void bc_vec_pushByte(BcVec *restrict v, uchar data) { in bc_vec_pushByte() argument
149 assert(v != NULL && v->size == sizeof(uchar)); in bc_vec_pushByte()
150 bc_vec_npush(v, 1, &data); in bc_vec_pushByte()
153 void bc_vec_pushIndex(BcVec *restrict v, size_t idx) { in bc_vec_pushIndex() argument
157 assert(v != NULL); in bc_vec_pushIndex()
158 assert(v->size == sizeof(uchar)); in bc_vec_pushIndex()
168 bc_vec_npush(v, amt + 1, nums); in bc_vec_pushIndex()
171 static void bc_vec_pushAt(BcVec *restrict v, const void *data, size_t idx) { in bc_vec_pushAt() argument
175 assert(v != NULL && data != NULL && idx <= v->len); in bc_vec_pushAt()
179 if (idx == v->len) bc_vec_push(v, data); in bc_vec_pushAt()
184 if (v->len == v->cap) bc_vec_grow(v, 1); in bc_vec_pushAt()
186 ptr = v->v + v->size * idx; in bc_vec_pushAt()
188 memmove(ptr + v->size, ptr, v->size * (v->len++ - idx)); in bc_vec_pushAt()
189 memmove(ptr, data, v->size); in bc_vec_pushAt()
195 void bc_vec_string(BcVec *restrict v, size_t len, const char *restrict str) { in bc_vec_string() argument
199 assert(v != NULL && v->size == sizeof(char)); in bc_vec_string()
200 assert(v->dtor == NULL); in bc_vec_string()
201 assert(!v->len || !v->v[v->len - 1]); in bc_vec_string()
202 assert(v->v != str); in bc_vec_string()
206 bc_vec_popAll(v); in bc_vec_string()
207 bc_vec_expand(v, bc_vm_growSize(len, 1)); in bc_vec_string()
208 memcpy(v->v, str, len); in bc_vec_string()
209 v->len = len; in bc_vec_string()
211 bc_vec_pushByte(v, '\0'); in bc_vec_string()
216 void bc_vec_concat(BcVec *restrict v, const char *restrict str) { in bc_vec_concat() argument
220 assert(v != NULL && v->size == sizeof(char)); in bc_vec_concat()
221 assert(v->dtor == NULL); in bc_vec_concat()
222 assert(!v->len || !v->v[v->len - 1]); in bc_vec_concat()
223 assert(v->v != str); in bc_vec_concat()
227 if (v->len) v->len -= 1; in bc_vec_concat()
229 bc_vec_npush(v, strlen(str) + 1, str); in bc_vec_concat()
234 void bc_vec_empty(BcVec *restrict v) { in bc_vec_empty() argument
238 assert(v != NULL && v->size == sizeof(char)); in bc_vec_empty()
239 assert(v->dtor == NULL); in bc_vec_empty()
243 bc_vec_popAll(v); in bc_vec_empty()
244 bc_vec_pushByte(v, '\0'); in bc_vec_empty()
250 void bc_vec_replaceAt(BcVec *restrict v, size_t idx, const void *data) { in bc_vec_replaceAt() argument
256 assert(v != NULL); in bc_vec_replaceAt()
258 ptr = bc_vec_item(v, idx); in bc_vec_replaceAt()
260 if (v->dtor != NULL) v->dtor(ptr); in bc_vec_replaceAt()
262 memcpy(ptr, data, v->size); in bc_vec_replaceAt()
266 inline void* bc_vec_item(const BcVec *restrict v, size_t idx) { in bc_vec_item() argument
267 assert(v != NULL && v->len && idx < v->len); in bc_vec_item()
268 return v->v + v->size * idx; in bc_vec_item()
271 inline void* bc_vec_item_rev(const BcVec *restrict v, size_t idx) { in bc_vec_item_rev() argument
272 assert(v != NULL && v->len && idx < v->len); in bc_vec_item_rev()
273 return v->v + v->size * (v->len - idx - 1); in bc_vec_item_rev()
276 inline void bc_vec_clear(BcVec *restrict v) { in bc_vec_clear() argument
278 v->v = NULL; in bc_vec_clear()
279 v->len = 0; in bc_vec_clear()
280 v->dtor = NULL; in bc_vec_clear()
284 BcVec *v = (BcVec*) vec; in bc_vec_free() local
286 bc_vec_popAll(v); in bc_vec_free()
287 free(v->v); in bc_vec_free()
290 static size_t bc_map_find(const BcVec *restrict v, const char *name) { in bc_map_find() argument
292 size_t low = 0, high = v->len; in bc_map_find()
297 const BcId *id = bc_vec_item(v, mid); in bc_map_find()
298 int result = strcmp(name, id->name); in bc_map_find()
308 bool bc_map_insert(BcVec *restrict v, const char *name, in bc_map_insert() argument
315 assert(v != NULL && name != NULL && i != NULL); in bc_map_insert()
317 *i = bc_map_find(v, name); in bc_map_insert()
319 assert(*i <= v->len); in bc_map_insert()
321 if (*i != v->len && !strcmp(name, ((BcId*) bc_vec_item(v, *i))->name)) in bc_map_insert()
327 bc_vec_pushAt(v, &id, *i); in bc_map_insert()
332 size_t bc_map_index(const BcVec *restrict v, const char *name) { in bc_map_index() argument
336 assert(v != NULL && name != NULL); in bc_map_index()
338 i = bc_map_find(v, name); in bc_map_index()
340 if (i >= v->len) return BC_VEC_INVALID_IDX; in bc_map_index()
342 return strcmp(name, ((BcId*) bc_vec_item(v, i))->name) ? in bc_map_index()