vector.l0
Module: std.vector
Source: compiler/shared/l0/stdlib/std/vector.l0 Language: Dea/L0
Imports / Includes
std.arraystd.stringstd.assertsys.memorysys.rt
Symbols
- StringVector
- vec_create
- vec_grow
- vec_reserve
- vec_check
- vec_get
- vec_push
- vec_size
- vec_capacity
- vec_zap
- vec_clear
- vec_free
- vec_push_int
- vec_push_byte
- vec_push_bytes
- vec_push_bool
- vec_push_ptr
- vi_sort
- sv_create
- sv_push
- sv_get
- sv_size
- sv_capacity
- _sv_less
- sv_sort
- sv_clear
- sv_free
- VectorBase
Type Alias StringVector
1
type StringVector = VectorBase
Function vec_create
1
func vec_create(element_size: int, initial_capacity: int) -> VectorBase*
Creates a new VectorBase with the specified element size and initial capacity.
Parameters:
element_size: The size of each element in bytes.initial_capacity: The initial number of elements to allocate space for.
Returns: A pointer to the newly created VectorBase.
Function vec_grow
1
func vec_grow(self: VectorBase*)
Internal function to grow the vector’s capacity if needed.
Parameters:
self: The pointer to the VectorBase.
Function vec_reserve
1
func vec_reserve(self: VectorBase*, total_capacity: int)
Ensures the vector has at least the specified total capacity.
Parameters:
self: The pointer to the VectorBase.total_capacity: The desired total capacity.
Function vec_check
1
func vec_check(self: VectorBase*, index: int)
Checks if the given index is within the logical bounds of the vector.
Parameters:
self: The pointer to the VectorBase.index: The index to check.
Function vec_get
1
func vec_get(self: VectorBase*, index: int) -> void*
Returns a pointer to the element at the specified index.
Parameters:
self: The pointer to the VectorBase.index: The index of the element.
Returns: A pointer to the element data.
Function vec_push
1
func vec_push(self: VectorBase*) -> void*
Grows the vector by one element and returns a pointer to the new slot.
Parameters:
self: The pointer to the VectorBase.
Returns: A pointer to the newly added element slot.
Function vec_size
1
func vec_size(self: VectorBase*) -> int
Returns the number of elements currently in the vector.
Parameters:
self: The pointer to the VectorBase.
Returns: The number of elements.
Function vec_capacity
1
func vec_capacity(self: VectorBase*) -> int
Returns the current total capacity of the vector.
Parameters:
self: The pointer to the VectorBase.
Returns: The current capacity.
Function vec_zap
1
func vec_zap(self: VectorBase*, index: int)
Zeros out the element at the specified index.
Parameters:
self: The pointer to the VectorBase.index: The index of the element to zap.
Function vec_clear
1
func vec_clear(self: VectorBase*)
Clears the vector, resetting its length to zero and shrinking its capacity.
Parameters:
self: The pointer to the VectorBase to clear.
Function vec_free
1
func vec_free(self: VectorBase*)
Free a VectorBase and its backing array.
Parameters:
self: Vector to free.
Function vec_push_int
1
func vec_push_int(self: VectorBase*, val: int)
Pushes an integer onto the vector.
Parameters:
self: The pointer to the VectorBase.val: The integer value to push.
Function vec_push_byte
1
func vec_push_byte(self: VectorBase*, val: byte)
Pushes a byte onto the vector.
Parameters:
self: The pointer to the VectorBase.val: The byte value to push.
Function vec_push_bytes
1
func vec_push_bytes(self: VectorBase*, src: byte*, count: int)
Bulk-push count bytes from src into a byte-element vector.
Reserves capacity in one step and copies with rt_memcpy .
Parameters:
self: The pointer to the VectorBase (must have element_size == 1).src: Pointer to the source bytes.count: Number of bytes to push.
Function vec_push_bool
1
func vec_push_bool(self: VectorBase*, val: bool)
Pushes a boolean onto the vector.
Parameters:
self: The pointer to the VectorBase.val: The boolean value to push.
Function vec_push_ptr
1
func vec_push_ptr(self: VectorBase*, val: void*)
Pushes a generic pointer onto the vector.
Parameters:
self: The pointer to the VectorBase.val: The pointer value to push.
Function vi_sort
1
func vi_sort(self: VectorBase*)
Sorts the elements of an integer vector in ascending order using insertion sort.
Parameters:
self: The pointer to the VectorBase containing integers.
Function sv_create
1
func sv_create(initial_capacity: int) -> StringVector*
Creates a new StringVector with the specified initial capacity.
Parameters:
initial_capacity: The initial capacity.
Returns: A pointer to the newly created StringVector.
Function sv_push
1
func sv_push(self: StringVector*, val: string)
Pushes a string onto the StringVector.
Parameters:
self: The pointer to the StringVector.val: The string value to push.
Function sv_get
1
func sv_get(self: StringVector*, index: int) -> string
Returns the string at the specified index.
Parameters:
self: The pointer to the StringVector.index: The index to access.
Returns: The string at that index.
Function sv_size
1
func sv_size(self: StringVector*) -> int
Returns the number of strings currently in the vector.
Parameters:
self: The pointer to the StringVector.
Returns: The count of elements.
Function sv_capacity
1
func sv_capacity(self: StringVector*) -> int
Returns the current capacity of the string vector.
Parameters:
self: The pointer to the StringVector.
Returns: The total capacity.
Function _sv_less
1
func _sv_less(a: string, b: string) -> bool
Internal helper to compare two strings for sorting.
Parameters:
a: The first string.b: The second string.
Returns: True if a < b lexicographically.
Function sv_sort
1
func sv_sort(self: StringVector*)
Sorts the strings in the vector lexicographically using insertion sort.
Parameters:
self: The pointer to the StringVector to sort.
Function sv_clear
1
func sv_clear(self: StringVector*)
Clears the string vector and releases all held strings.
Parameters:
self: The pointer to the StringVector to clear.
Function sv_free
1
func sv_free(self: StringVector*)
Free a StringVector and release every stored string.
Parameters:
self: String vector to free.
Struct VectorBase
VectorBase implements a dynamic array (vector) of elements of a given size.
It uses ArrayBase internally to manage storage. It can grow dynamically as elements are added, and a capacity can be reserved in advance.
Note: This is a low-level implementation and does not provide type safety. It is the caller’s responsibility to manage types and casting.
VectorBase Field arr
1
arr: ArrayBase*
VectorBase Field length
1
length: int