Lines Matching refs:vector

15 static inline void ds_vector_reallocate(ds_vector_t *vector, zend_long capacity)  in ds_vector_reallocate()  argument
17vector->buffer = ds_reallocate_zval_buffer(vector->buffer, capacity, vector->capacity, vector->s… in ds_vector_reallocate()
18 vector->capacity = capacity; in ds_vector_reallocate()
23 ds_vector_t *vector = ecalloc(1, sizeof(ds_vector_t)); in ds_vector_ex() local
28 vector->buffer = ds_allocate_zval_buffer(capacity); in ds_vector_ex()
29 vector->capacity = capacity; in ds_vector_ex()
30 vector->size = 0; in ds_vector_ex()
32 return vector; in ds_vector_ex()
40 ds_vector_t *ds_vector_clone(ds_vector_t *vector) in ds_vector_clone() argument
42 if (DS_VECTOR_IS_EMPTY(vector)) { in ds_vector_clone()
48 clone->buffer = ds_allocate_zval_buffer(vector->capacity); in ds_vector_clone()
49 clone->capacity = vector->capacity; in ds_vector_clone()
50 clone->size = vector->size; in ds_vector_clone()
52 COPY_ZVAL_BUFFER(clone->buffer, vector->buffer, vector->size); in ds_vector_clone()
59 ds_vector_t *vector = ecalloc(1, sizeof(ds_vector_t)); in ds_vector_from_buffer() local
67 vector->buffer = buffer; in ds_vector_from_buffer()
68 vector->capacity = capacity; in ds_vector_from_buffer()
69 vector->size = size; in ds_vector_from_buffer()
71 return vector; in ds_vector_from_buffer()
74 void ds_vector_allocate(ds_vector_t *vector, zend_long capacity) in ds_vector_allocate() argument
76 if (capacity > vector->capacity) { in ds_vector_allocate()
77 ds_vector_reallocate(vector, capacity); in ds_vector_allocate()
81 static inline void ds_vector_increase_capacity(ds_vector_t *vector) in ds_vector_increase_capacity() argument
83 ds_vector_reallocate(vector, vector->capacity + (vector->capacity >> 1)); in ds_vector_increase_capacity()
86 static inline void ds_vector_ensure_capacity(ds_vector_t *vector, zend_long capacity) in ds_vector_ensure_capacity() argument
88 if (capacity > vector->capacity) { in ds_vector_ensure_capacity()
89 zend_long boundary = vector->capacity + (vector->capacity >> 1); in ds_vector_ensure_capacity()
90 ds_vector_reallocate(vector, MAX(capacity, boundary)); in ds_vector_ensure_capacity()
94 static inline void ds_vector_auto_truncate(ds_vector_t *vector) in ds_vector_auto_truncate() argument
96 const zend_long c = vector->capacity; in ds_vector_auto_truncate()
97 const zend_long n = vector->size; in ds_vector_auto_truncate()
100 ds_vector_reallocate(vector, c / 2); in ds_vector_auto_truncate()
104 void ds_vector_remove(ds_vector_t *vector, zend_long index, zval *return_value) in ds_vector_remove() argument
106 if (index_out_of_range(index, vector->size)) { in ds_vector_remove()
110 if (index == vector->size - 1) { in ds_vector_remove()
111 ds_vector_pop(vector, return_value); in ds_vector_remove()
114 zval *pos = vector->buffer + index; in ds_vector_remove()
124 memmove(pos, pos + 1, sizeof(zval) * (vector->size - index)); in ds_vector_remove()
125 vector->size--; in ds_vector_remove()
127 ds_vector_auto_truncate(vector); in ds_vector_remove()
131 zval *ds_vector_get(ds_vector_t *vector, zend_long index) in ds_vector_get() argument
133 if (index_out_of_range(index, vector->size)) { in ds_vector_get()
137 return vector->buffer + index; in ds_vector_get()
140 static inline void increase_capacity_if_full(ds_vector_t *vector) in increase_capacity_if_full() argument
142 if (vector->size == vector->capacity) { in increase_capacity_if_full()
143 ds_vector_increase_capacity(vector); in increase_capacity_if_full()
147 static inline void ds_vector_clear_buffer(ds_vector_t *vector) in ds_vector_clear_buffer() argument
149 zval *pos = vector->buffer; in ds_vector_clear_buffer()
150 zval *end = vector->buffer + vector->size; in ds_vector_clear_buffer()
156 vector->size = 0; in ds_vector_clear_buffer()
159 void ds_vector_clear(ds_vector_t *vector) in ds_vector_clear() argument
161 if (vector->size > 0) { in ds_vector_clear()
162 ds_vector_clear_buffer(vector); in ds_vector_clear()
164 if (vector->capacity > DS_VECTOR_MIN_CAPACITY) { in ds_vector_clear()
165 ds_vector_reallocate(vector, DS_VECTOR_MIN_CAPACITY); in ds_vector_clear()
170 void ds_vector_set(ds_vector_t *vector, zend_long index, zval *value) in ds_vector_set() argument
172 if ( ! index_out_of_range(index, vector->size)) { in ds_vector_set()
173 zval *ptr = vector->buffer + index; in ds_vector_set()
179 void ds_vector_to_array(ds_vector_t *vector, zval *return_value) in ds_vector_to_array() argument
181 zend_long size = vector->size; in ds_vector_to_array()
187 zval *pos = vector->buffer; in ds_vector_to_array()
199 static inline zend_long ds_vector_find_index(ds_vector_t *vector, zval *value) in ds_vector_find_index() argument
201 zval *pos = vector->buffer; in ds_vector_find_index()
202 zval *end = vector->buffer + vector->size; in ds_vector_find_index()
206 return pos - vector->buffer; in ds_vector_find_index()
213 void ds_vector_find(ds_vector_t *vector, zval *value, zval *return_value) in ds_vector_find() argument
215 zend_long index = ds_vector_find_index(vector, value); in ds_vector_find()
225 bool ds_vector_contains(ds_vector_t *vector, zval *value) in ds_vector_contains() argument
227 return ds_vector_find_index(vector, value) != FAILURE; in ds_vector_contains()
230 bool ds_vector_contains_va(ds_vector_t *vector, VA_PARAMS) in ds_vector_contains_va() argument
233 if ( ! ds_vector_contains(vector, argv++)) { in ds_vector_contains_va()
241 void ds_vector_join(ds_vector_t *vector, char *str, size_t len, zval *return_value) in ds_vector_join() argument
244 s = ds_join_zval_buffer(vector->buffer, DS_VECTOR_SIZE(vector), str, len); in ds_vector_join()
248 void ds_vector_insert_va(ds_vector_t *vector, zend_long index, VA_PARAMS) in ds_vector_insert_va() argument
250 if ( ! index_out_of_range(index, vector->size + 1) && argc > 0) { in ds_vector_insert_va()
256 ds_vector_ensure_capacity(vector, vector->size + argc); in ds_vector_insert_va()
259 dst = vector->buffer + index; in ds_vector_insert_va()
261 len = vector->size - index; in ds_vector_insert_va()
264 memmove(end, dst, (vector->size - index) * sizeof(zval)); in ds_vector_insert_va()
271 vector->size += argc; in ds_vector_insert_va()
275 void ds_vector_insert(ds_vector_t *vector, zend_long index, zval *value) in ds_vector_insert() argument
277 ds_vector_insert_va(vector, index, 1, value); in ds_vector_insert()
280 void ds_vector_push(ds_vector_t *vector, zval *value) in ds_vector_push() argument
282 increase_capacity_if_full(vector); in ds_vector_push()
283 ZVAL_COPY(&vector->buffer[vector->size++], value); in ds_vector_push()
286 void ds_vector_push_va(ds_vector_t *vector, VA_PARAMS) in ds_vector_push_va() argument
289 ds_vector_push(vector, argv); in ds_vector_push_va()
296 ds_vector_ensure_capacity(vector, vector->size + argc); in ds_vector_push_va()
299 dst = &vector->buffer[vector->size]; in ds_vector_push_va()
306 vector->size += argc; in ds_vector_push_va()
310 void ds_vector_unshift(ds_vector_t *vector, zval *value) in ds_vector_unshift() argument
312 ds_vector_insert(vector, 0, value); in ds_vector_unshift()
315 void ds_vector_unshift_va(ds_vector_t *vector, VA_PARAMS) in ds_vector_unshift_va() argument
318 ds_vector_unshift(vector, argv); in ds_vector_unshift_va()
325 ds_vector_ensure_capacity(vector, vector->size + argc); in ds_vector_unshift_va()
328 dst = vector->buffer; in ds_vector_unshift_va()
331 memmove(end, dst, vector->size * sizeof(zval)); in ds_vector_unshift_va()
337 vector->size += argc; in ds_vector_unshift_va()
341 void ds_vector_sort_callback(ds_vector_t *vector) in ds_vector_sort_callback() argument
343 ds_user_sort_zval_buffer(vector->buffer, vector->size); in ds_vector_sort_callback()
346 void ds_vector_sort(ds_vector_t *vector) in ds_vector_sort() argument
348 ds_sort_zval_buffer(vector->buffer, vector->size); in ds_vector_sort()
351 bool ds_vector_isset(ds_vector_t *vector, zend_long index, int check_empty) in ds_vector_isset() argument
353 if (index < 0 || index >= vector->size) { in ds_vector_isset()
357 return ds_zval_isset(vector->buffer + index, check_empty); in ds_vector_isset()
360 bool ds_vector_index_exists(ds_vector_t *vector, zend_long index) in ds_vector_index_exists() argument
362 return index >= 0 && index < vector->size; in ds_vector_index_exists()
371 static inline void add_traversable_to_vector(ds_vector_t *vector, zval *obj) in add_traversable_to_vector() argument
373 spl_iterator_apply(obj, iterator_add, (void*) vector); in add_traversable_to_vector()
376 static inline void add_array_to_vector(ds_vector_t *vector, HashTable *array) in add_array_to_vector() argument
379 ds_vector_ensure_capacity(vector, vector->size + array->nNumOfElements); in add_array_to_vector()
382 ds_vector_push(vector, value); in add_array_to_vector()
387 void ds_vector_rotate(ds_vector_t *vector, zend_long r) in ds_vector_rotate() argument
391 zend_long n = vector->size; in ds_vector_rotate()
403 a = vector->buffer; // Start of buffer in ds_vector_rotate()
413 void ds_vector_push_all(ds_vector_t *vector, zval *values) in ds_vector_push_all() argument
420 add_array_to_vector(vector, Z_ARRVAL_P(values)); in ds_vector_push_all()
425 add_traversable_to_vector(vector, values); in ds_vector_push_all()
432 ds_vector_t *ds_vector_merge(ds_vector_t *vector, zval *values) in ds_vector_merge() argument
435 ds_vector_t *merged = ds_vector_clone(vector); in ds_vector_merge()
444 void ds_vector_pop(ds_vector_t *vector, zval *return_value) in ds_vector_pop() argument
446 SET_AS_RETURN_AND_UNDEF(&vector->buffer[--vector->size]); in ds_vector_pop()
447 ds_vector_auto_truncate(vector); in ds_vector_pop()
450 void ds_vector_pop_throw(ds_vector_t *vector, zval *return_value) in ds_vector_pop_throw() argument
452 if (DS_VECTOR_IS_EMPTY(vector)) { in ds_vector_pop_throw()
457 ds_vector_pop(vector, return_value); in ds_vector_pop_throw()
460 void ds_vector_shift(ds_vector_t *vector, zval *return_value) in ds_vector_shift() argument
462 zval *first = vector->buffer; in ds_vector_shift()
466 vector->size--; in ds_vector_shift()
467 memmove(first, first + 1, vector->size * sizeof(zval)); in ds_vector_shift()
468 ds_vector_auto_truncate(vector); in ds_vector_shift()
471 void ds_vector_shift_throw(ds_vector_t *vector, zval *return_value) in ds_vector_shift_throw() argument
473 if (DS_VECTOR_IS_EMPTY(vector)) { in ds_vector_shift_throw()
478 ds_vector_shift(vector, return_value); in ds_vector_shift_throw()
481 zval *ds_vector_get_last(ds_vector_t *vector) in ds_vector_get_last() argument
483 return &vector->buffer[vector->size - 1]; in ds_vector_get_last()
486 zval *ds_vector_get_last_throw(ds_vector_t *vector) in ds_vector_get_last_throw() argument
488 if (DS_VECTOR_IS_EMPTY(vector)) { in ds_vector_get_last_throw()
493 return ds_vector_get_last(vector); in ds_vector_get_last_throw()
496 zval *ds_vector_get_first(ds_vector_t *vector) in ds_vector_get_first() argument
498 return &vector->buffer[0]; in ds_vector_get_first()
501 zval *ds_vector_get_first_throw(ds_vector_t *vector) in ds_vector_get_first_throw() argument
503 if (DS_VECTOR_IS_EMPTY(vector)) { in ds_vector_get_first_throw()
508 return ds_vector_get_first(vector); in ds_vector_get_first_throw()
511 void ds_vector_reverse(ds_vector_t *vector) in ds_vector_reverse() argument
513 ds_reverse_zval_range(vector->buffer, vector->buffer + vector->size); in ds_vector_reverse()
516 ds_vector_t *ds_vector_reversed(ds_vector_t *vector) in ds_vector_reversed() argument
519 zval *buffer = ds_allocate_zval_buffer(vector->capacity); in ds_vector_reversed()
520 zval *target = &buffer[vector->size - 1]; in ds_vector_reversed()
522 DS_VECTOR_FOREACH(vector, value) { in ds_vector_reversed()
527 return ds_vector_from_buffer(buffer, vector->capacity, vector->size); in ds_vector_reversed()
530 void ds_vector_apply(ds_vector_t *vector, FCI_PARAMS) in ds_vector_apply() argument
535 DS_VECTOR_FOREACH(vector, value) { in ds_vector_apply()
550 ds_vector_t *ds_vector_map(ds_vector_t *vector, FCI_PARAMS) in ds_vector_map() argument
554 zval *buffer = ds_allocate_zval_buffer(vector->capacity); in ds_vector_map()
557 DS_VECTOR_FOREACH(vector, value) { in ds_vector_map()
579 return ds_vector_from_buffer(buffer, vector->capacity, vector->size); in ds_vector_map()
582 ds_vector_t *ds_vector_filter(ds_vector_t *vector) in ds_vector_filter() argument
584 if (DS_VECTOR_IS_EMPTY(vector)) { in ds_vector_filter()
589 zval *buffer = ds_allocate_zval_buffer(vector->size); in ds_vector_filter()
592 DS_VECTOR_FOREACH(vector, value) { in ds_vector_filter()
599 return ds_vector_from_buffer(buffer, vector->size, (target - buffer)); in ds_vector_filter()
603 ds_vector_t *ds_vector_filter_callback(ds_vector_t *vector, FCI_PARAMS) in ds_vector_filter_callback() argument
605 if (DS_VECTOR_IS_EMPTY(vector)) { in ds_vector_filter_callback()
611 zval *buffer = ds_allocate_zval_buffer(vector->size); in ds_vector_filter_callback()
614 DS_VECTOR_FOREACH(vector, value) { in ds_vector_filter_callback()
641 return ds_vector_from_buffer(buffer, vector->size, (target - buffer)); in ds_vector_filter_callback()
645 void ds_vector_reduce(ds_vector_t *vector, zval *initial, zval *return_value, FCI_PARAMS) in ds_vector_reduce() argument
657 DS_VECTOR_FOREACH(vector, value) { in ds_vector_reduce()
677 ds_vector_t *ds_vector_slice(ds_vector_t *vector, zend_long index, zend_long length) in ds_vector_slice() argument
679 ds_normalize_slice_args(&index, &length, vector->size); in ds_vector_slice()
688 zval *src = vector->buffer + index; in ds_vector_slice()
689 zval *end = vector->buffer + index + length; in ds_vector_slice()
700 void ds_vector_sum(ds_vector_t *vector, zval *return_value) in ds_vector_sum() argument
706 DS_VECTOR_FOREACH(vector, value) { in ds_vector_sum()
712 void ds_vector_free(ds_vector_t *vector) in ds_vector_free() argument
714 ds_vector_clear_buffer(vector); in ds_vector_free()
715 efree(vector->buffer); in ds_vector_free()
716 efree(vector); in ds_vector_free()