65#define VLC_VECTOR(type) \
75#define VLC_VECTOR_INITIALIZER { 0, 0, NULL }
80#define vlc_vector_init(pv) (void) \
93#define vlc_vector_destroy(pv) \
101#define vlc_vector_clear(pv) \
104 vlc_vector_destroy(pv), \
105 vlc_vector_init(pv) \
113#define VLC_VECTOR_MINCAP_ ((size_t) 10)
118 return a < b ? a : b;
124 return a > b ? a : b;
139#define VLC_VECTOR_FAILFLAG_ (~(((size_t) -1) >> 1))
169 size_t *restrict pcap,
size_t *restrict psize)
196 *pcap &= ~VLC_VECTOR_FAILFLAG_;
212#define vlc_vector_realloc_(pv, newcap) \
214 (pv)->data = vlc_vector_reallocdata_((pv)->data, newcap, \
215 sizeof(*(pv)->data), \
216 &(pv)->cap, &(pv)->size), \
217 !vlc_vector_test_and_reset_failflag_(&(pv)->cap) \
232#define vlc_vector_resize_(pv, newcap) \
234 (pv)->cap == (newcap) || \
236 (newcap) > 0 ? vlc_vector_realloc_(pv, newcap) \
237 : (vlc_vector_clear(pv), true) \
245 return value + (value >> 1);
249#define vlc_vector_max_cap_(pv) (SIZE_MAX / 2 / sizeof(*(pv)->data))
259#define vlc_vector_reserve(pv, mincap) \
261 vlc_vector_reserve_internal_(pv, \
262 vlc_vector_max_(mincap, VLC_VECTOR_MINCAP_))
264#define vlc_vector_reserve_internal_(pv, mincap) \
266 (mincap) <= (pv)->cap || \
268 (mincap) <= vlc_vector_max_cap_(pv) && \
269 vlc_vector_realloc_(pv, \
271 vlc_vector_between_(vlc_vector_growsize_((pv)->cap), \
273 vlc_vector_max_cap_(pv))) \
282#define vlc_vector_shrink_to_fit(pv) \
284 vlc_vector_resize_(pv, (pv)->size)
293#define vlc_vector_autoshrink(pv) (void) \
295 (pv)->cap <= VLC_VECTOR_MINCAP_ || \
296 (pv)->cap < vlc_vector_growsize_((pv)->size+5) || \
297 vlc_vector_resize_(pv, vlc_vector_max_((pv)->size+5, VLC_VECTOR_MINCAP_)) \
300#define vlc_vector_check_same_ptr_type_(a, b) \
313#define vlc_vector_push(pv, item) \
315 vlc_vector_reserve(pv, (pv)->size + 1) && \
317 (pv)->data[(pv)->size++] = (item), \
331#define vlc_vector_push_all(pv, items, count) \
332 vlc_vector_push_all_internal_(pv, items, vlc_vector_enforce_size_t_(count))
334#define vlc_vector_push_all_internal_(pv, items, count) \
337 vlc_vector_check_same_ptr_type_((pv)->data, items), \
338 vlc_vector_reserve(pv, (pv)->size + (count)) && \
340 memcpy(&(pv)->data[(pv)->size], items, (count) * sizeof(*(pv)->data)), \
341 (pv)->size += (count), \
358#define vlc_vector_insert_hole(pv, index, count) \
359 vlc_vector_insert_hole_internal_(pv, vlc_vector_enforce_size_t_(index), \
360 vlc_vector_enforce_size_t_(count))
362#define vlc_vector_insert_hole_internal_(pv, index, count) \
365 vlc_vector_reserve(pv, (pv)->size + (count)) && \
367 (index) == (pv)->size || \
369 memmove(&(pv)->data[(index) + (count)], \
370 &(pv)->data[index], \
371 ((pv)->size - (index)) * sizeof(*(pv)->data)), \
376 (pv)->size += (count), \
392#define vlc_vector_insert(pv, index, item) \
394 vlc_vector_insert_hole(pv, index, 1) && \
396 (pv)->data[index] = (item), \
413#define vlc_vector_insert_all(pv, index, items, count) \
415 vlc_vector_check_same_ptr_type_((pv)->data, items), \
416 vlc_vector_insert_hole(pv, index, count) && \
418 memcpy(&(pv)->data[index], items, (count) * sizeof(*(pv)->data)), \
427 for (
size_t i = 0; i < len / 2; ++i)
430 array[i] = array[len - i - 1];
431 array[len - i - 1] = c;
493#define vlc_vector_move_slice(pv, index, count, target) \
494 vlc_vector_move_slice_internal_(pv, \
495 vlc_vector_enforce_size_t_(index), \
496 vlc_vector_enforce_size_t_(count), \
497 vlc_vector_enforce_size_t_(target))
499#define vlc_vector_move_slice_internal_(pv, index, count, target) \
500 vlc_vector_move_((char *) (pv)->data, \
501 (index) * sizeof((pv)->data[0]), \
502 (count) * sizeof((pv)->data[0]), \
503 (target) * sizeof((pv)->data[0]))
514#define vlc_vector_move(pv, index, target) \
515 vlc_vector_move_slice(pv, index, 1, target)
529#define vlc_vector_remove_slice_noshrink(pv, index, count) \
530 vlc_vector_remove_slice_noshrink_internal_(pv, \
531 vlc_vector_enforce_size_t_(index), \
532 vlc_vector_enforce_size_t_(count))
534#define vlc_vector_remove_slice_noshrink_internal_(pv, index, count) \
537 if ((index) + (count) < (pv)->size) \
538 memmove(&(pv)->data[index], \
539 &(pv)->data[(index) + (count)], \
540 ((pv)->size - (index) - (count)) * sizeof(*(pv)->data)); \
541 (pv)->size -= (count); \
553#define vlc_vector_remove_slice(pv, index, count) \
555 vlc_vector_remove_slice_noshrink(pv, index, count); \
556 vlc_vector_autoshrink(pv); \
570#define vlc_vector_remove_noshrink(pv, index) \
571 vlc_vector_remove_slice_noshrink(pv, index, 1)
581#define vlc_vector_remove(pv, index) \
583 vlc_vector_remove_noshrink(pv, index); \
584 vlc_vector_autoshrink(pv); \
598#define vlc_vector_swap_remove(pv, index) \
600 (pv)->data[index] = (pv)->data[(pv)->size-1]; \
619#define vlc_vector_index_of(pv, item, pidx) \
621 ssize_t *out = pidx; \
622 size_t vlc_vector_find_idx_; \
623 for (vlc_vector_find_idx_ = 0; \
624 vlc_vector_find_idx_ < (pv)->size; \
625 ++vlc_vector_find_idx_) \
626 if ((pv)->data[vlc_vector_find_idx_] == (item)) \
628 *out = vlc_vector_find_idx_ == (pv)->size ? -1 : \
629 (ssize_t) vlc_vector_find_idx_; \
641#define vlc_vector_foreach(item, pv) \
642 for (size_t vlc_vector_idx_##item = 0; \
643 vlc_vector_idx_##item < (pv)->size && \
644 ((item) = (pv)->data[vlc_vector_idx_##item], true); \
645 ++vlc_vector_idx_##item)
size_t count
Definition: core.c:403
static size_t vlc_vector_growsize_(size_t value)
Definition: vlc_vector.h:243
static void vlc_vector_reverse_array_(char *array, size_t len)
Reverse a char array in place.
Definition: vlc_vector.h:426
static bool vlc_vector_test_and_reset_failflag_(size_t *pcap)
Test and reset the fail flag.
Definition: vlc_vector.h:193
static void vlc_vector_rotate_array_right_(char *array, size_t len, size_t distance)
Right-rotate a (char) array in place.
Definition: vlc_vector.h:461
static size_t vlc_vector_enforce_size_t_(size_t value)
Definition: vlc_vector.h:135
#define VLC_VECTOR_FAILFLAG_
Definition: vlc_vector.h:140
static size_t vlc_vector_between_(size_t x, size_t min, size_t max)
Definition: vlc_vector.h:129
static void vlc_vector_rotate_array_left_(char *array, size_t len, size_t distance)
Right-rotate a (char) array in place.
Definition: vlc_vector.h:445
static size_t vlc_vector_max_(size_t a, size_t b)
Definition: vlc_vector.h:123
static void vlc_vector_move_(char *array, size_t index, size_t count, size_t target)
Move items in a (char) array in place.
Definition: vlc_vector.h:472
static void * vlc_vector_reallocdata_(void *ptr, size_t count, size_t size, size_t *restrict pcap, size_t *restrict psize)
Realloc data and update vector fields.
Definition: vlc_vector.h:169
static size_t vlc_vector_min_(size_t a, size_t b)
Definition: vlc_vector.h:117
This file is a collection of common definitions and types.
static void * vlc_reallocarray(void *ptr, size_t count, size_t size)
Definition: vlc_common.h:1163