forked from fox-archives/volant
-
Notifications
You must be signed in to change notification settings - Fork 4
Vectors
Apoorv Singal edited this page Aug 30, 2020
·
3 revisions
A vector is a linear data structure used for storing a group of data with dynamic length.
Vectors have type vec type
.
vector: vec type;
Vectors can be initialized using compound literals.
vector: vec type;
vector = (vec type){el1, el2, el3, el4};
-
vector.length
returns the number of elements in the vector. -
vector.capacity
returns the maximum number of elements that the vector can have. Appending more elements than the capacity of the vector reallocates the vector with a higher capacity. -
vector.push(value)
appendsvalue
to the end of the vector. -
vector.pop()
removes and returns the last value of the vector. -
vector.clone()
creates and returns a copy of the vector. -
vector.concat(anotherVector)
appends all elements ofanotherVector
to the end ofvector
. Both vectors must have the same type. -
vector.free()
frees the vector from the heap. It is not necessary to manually free vectors because Volant also has garbage collection.