Vector¶
-
struct
Vector
¶ A type safe, generic vector.
Type definitions
-
VECTOR_DECL_SPEC
(T, SPEC)¶ Declares a new vector type, prepending a specifier to the generated declarations.
- Parameters
T
: [symbol] Vector type.SPEC
: [specifier] Specifier.
-
VECTOR_DECL_EQUATABLE_SPEC
(T, SPEC)¶ Declares a new equatable vector type, prepending a specifier to the generated declarations.
- Parameters
T
: [symbol] Vector type.SPEC
: [specifier] Specifier.
-
VECTOR_DECL_COMPARABLE
(T)¶ Declares a new comparable vector type.
- Parameters
T
: [symbol] Vector type.
-
VECTOR_DECL_COMPARABLE_SPEC
(T, SPEC)¶ Declares a new comparable vector type, prepending a specifier to the generated declarations.
- Parameters
T
: [symbol] Vector type.SPEC
: [specifier] Specifier.
-
VECTOR_IMPL_EQUATABLE
(T, __equal_func)¶ Implements a previously declared equatable vector type.
Elements of an equatable vector can be checked for equality via __equal_func.
- Parameters
T
: [symbol] Vector type.__equal_func
: [(T, T) -> bool] Equality function.
-
VECTOR_IMPL_COMPARABLE
(T, __equal_func, __compare_func)¶ Implements a previously declared comparable vector type.
Elements of a comparable vector can be checked for equality via __equal_func and ordered via __compare_func.
- Parameters
T
: [symbol] Vector type.__equal_func
: [(T, T) -> bool] Equality function.__compare_func
: [(T, T) -> bool] Comparison function (True if LHS is smaller than RHS).
-
VECTOR_IMPL_IDENTIFIABLE
(T)¶ Implements a previously declared comparable vector type whose elements can be checked for equality via == and compared via <.
- Parameters
T
: [symbol] Vector type.
-
VECTOR_INIT_EQUATABLE
(T, __equal_func)¶ Defines a new static equatable vector type.
- Parameters
T
: [symbol] Vector type.__equal_func
: [(T, T) -> bool] Equality function.
Declaration
Memory management
-
vector_alloc
(T)¶ Allocates a new vector.
-
vector_free
(T, vec)¶ Deallocates the specified vector.
-
vector_copy
(T, vec)¶ Copies the specified vector.
-
vector_deep_copy
(T, vec, __copy_func)¶ Performs a deep copy of the specified vector.
-
vector_copy_to_array
(T, vec, array)¶ Copies the elements of the specified vector into the given array.
-
vector_init
(T)¶ Initializes a new vector on the stack.
-
vector_deinit
(vec)¶ De-initializes a vector previously initialized via VECTOR_INIT.
-
vector_reserve_capacity
(T, vec, size)¶ Ensures the specified vector can hold at least as many elements as ‘size’.
-
vector_expand
(T, vec, size)¶ Expands the specified vector so that it can contain additional ‘size’ elements.
Primitives
-
vector_get
(vec, idx)¶ Retrieves the element at the specified index.
-
vector_set
(vec, idx, item)¶ Replaces the element at the specified index.
-
vector_first
(vec)¶ Returns the first element in the vector.
-
vector_last
(vec)¶ Returns the last element in the vector.
-
vector_is_empty
(vec)¶ Checks whether the specified vector is empty.
-
vector_count
(vec)¶ Returns the number of elements in the vector.
-
vector_push
(T, vec, item)¶ Pushes the specified element to the top of the vector (last element).
-
vector_pop
(T, vec)¶ Removes and returns the element at the top of the vector (last element).
-
vector_remove_at
(T, vec, idx)¶ Removes the element at the specified index.
-
vector_insert_at
(T, vec, idx, item)¶ Inserts an element at the specified index.
-
vector_remove_all
(T, vec)¶ Removes all the elements in the vector.
-
vector_append
(T, vec, vec_to_append)¶ Appends a vector to another.
-
vector_append_array
(T, vec, array, n)¶ Appends an array to the specified vector.
-
vector_append_items
(T, vec, ...)¶ Appends multiple items to the specified vector.
Iteration
-
vector_iterate
(T, vec, item_name, idx_name, code)¶ Iterates over the vector, executing the specified code block for each element.
-
vector_iterate_reverse
(T, vec, item_name, idx_name, code)¶ Iterates over the vector in reverse order, executing the specified code block for each element.
-
vector_foreach
(T, vec, item_name, code)¶ Iterates over the vector, executing the specified code block for each element.
-
vector_foreach_reverse
(T, vec, item_name, code)¶ Iterates over the vector in reverse order, executing the specified code block for each element.
Equatable
-
vector_index_of
(T, vec, item)¶ Returns the index of the first occurrence of the specified element.
-
vector_index_of_reverse
(T, vec, item)¶ Returns the index of the last occurrence of the specified element.
-
vector_contains
(T, vec, item)¶ Checks whether the vector contains the specified element.
-
vector_contains_all
(T, vec, other_vec)¶ Checks whether the vector contains all the elements present in another vector.
-
vector_contains_any
(T, vec, other_vec)¶ Checks whether the vector contains any of the elements contained in another vector.
-
vector_remove
(T, vec, item)¶ Removes the specified element.
-
vector_equals
(T, vec_a, vec_b)¶ Checks whether the two vectors are equal.
Two vectors are considered equal if they contain the same elements in the same order.
Comparable
-
vector_index_of_min
(T, vec)¶ Returns the index of the minimum element in the vector.
-
vector_index_of_max
(T, vec)¶ Returns the index of the maximum element in the vector.
-
vector_sort
(T, vec)¶ Sorts the vector.
Average performance: O(n log n)
-
vector_sort_range
(T, vec, start, len)¶ Sorts the elements in the specified range.
Average performance: O(n log n)
-
vector_insertion_index_sorted
(T, vec, item)¶ Finds the insertion index for the specified item in a sorted vector.
Average performance: O(log n)
-
vector_index_of_sorted
(T, vec, item)¶ Returns the index of the specified element in a sorted vector.
Average performance: O(log n)
-
vector_contains_sorted
(T, vec, item)¶ Checks whether a sorted vector contains the specified element.
Average performance: O(log n)
Higher order
-
vector_first_index_where
(T, vec, idx_var, bool_exp)¶ Returns the index of the first element that matches the specified boolean expression.
-
vector_qsort
(T, vec, __comp_func)¶ Sorts the vector via qsort.
-
vector_qsort_range
(T, vec, start, len, __comp_func)¶ Sorts the elements in the specified range via qsort.
-