compiler/shared/l0/stdlib/std/vector.l0

Module std.vector

Overview Symbols grouped by source file: compiler/shared/l0/stdlib/std/vector.l0

Module: std.vector

Source: compiler/shared/l0/stdlib/std/vector.l0 Language: Dea/L0

Imports / Includes

  • std.array
  • std.string
  • std.assert
  • sys.memory
  • sys.rt

Symbols

Type Alias StringVector

type StringVector = VectorBase

Function vec_create

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

func vec_grow(self: VectorBase*)

Internal function to grow the vector's capacity if needed.

Parameters:

Function vec_reserve

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

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

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

func vec_push(self: VectorBase*) -> void*

Grows the vector by one element and returns a pointer to the new slot.

Parameters:

Returns: A pointer to the newly added element slot.

Function vec_size

func vec_size(self: VectorBase*) -> int

Returns the number of elements currently in the vector.

Parameters:

Returns: The number of elements.

Function vec_capacity

func vec_capacity(self: VectorBase*) -> int

Returns the current total capacity of the vector.

Parameters:

Returns: The current capacity.

Function vec_zap

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

func vec_clear(self: VectorBase*)

Clears the vector, resetting its length to zero and shrinking its capacity.

Parameters:

Function vec_free

func vec_free(self: VectorBase*)

Free a VectorBase and its backing array.

Parameters:

  • self: Vector to free.

Function vec_push_int

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

arr: ArrayBase*

VectorBase Field length

length: int