vector

struct Vector

Vector is a dynamic array allocated on the heap. It is automatically freed when it goes out of scope

Members

  • usize length - length of the vector
  • usize memberSize - size (bytes) of 1 element
  • addr elements - pointer to the vector's elements
  • usize capacity - capacity of the vector

This structure inherits from Array, so you can use functions made for Array on an instance of Vector

alloc_vec_capacity

Parameters: ptr Vector vec

Used internally to allocate the elements with the capacity

double_vec_capacity

Parameters: ptr Vector vec

Used internally to double vector capacity and re-allocate

halve_vec_capacity

Parameters: ptr Vector vec

Used internally to halve the vector capacity and re-allocate

init_vec

Parameters: usize typeSize, ptr Vector vec

Initialises the vector. The type size is in bytes

free_vec

Parameters: ptr Vector vec

Frees the vector's elements and sets all values to zero

to_vec

Parameters: ptr Array arr, ptr Vector vec

Copies the array's metadata to the vector. The array elements are copied to the heap and the new elements address is stored in the vector

vec_push

Parameters: cell value, ptr Vector vec

Pushes the given value to the top of the vector

vec_top

Parameters: ptr Vector vec -> cell value

Returns the last value in the vector

vec_pop

Parameters: ptr Vector vec

Removes the last element in the vector

vec_remove

Parameters: cell index, ptr Vector vec

Removes the given index from the vector

vec_insert

Parameters: cell value, cell index, ptr Vector vec

Inserts the given value at the given index