Simple API over static array buffer allocated on stack.
#import "std/static_array"
#import "std/print"
main :: fn () s32 {
arr: StaticArray(s32, 10);
loop i := 0; i < 10; i += 1 {
sarray_push(&arr, i);
}
sarray_erase(&arr, 1);
sarray_erase(&arr, 4);
loop i := 0; i < arr.len; i += 1 {
print("%\n", arr.data[i]);
}
return 0;
}
StaticArray :: fn (TElem: type, elem_count: s64) type
Create Static Array type.
StaticArray :: struct {
data[elem_count]TElem;
len: s64;
}
File: static_array.bl
sarray_push :: fn {
impl_push_empty;
impl_push;
}
Push element at the end of the array and returns its address.
Warning: Asserts in case there is not enough space left in the storage.
File: static_array.bl
sarray_push_all :: fn (arr: *?TArr, values: []sarray_typeof_elem(TArr))
Push bunch of elements at the end of the array.
File: static_array.bl
sarray_pop :: fn (arr: *?TArr, out : *sarray_typeof_elem(TArr): null) bool #inline
Pops the last element of the array into out destination and returns true
otherwise returns false and value of out stays unchanged.
File: static_array.bl
sarray_pop_first :: fn (arr: *?TArr, out : *sarray_typeof_elem(TArr): null) bool #inline
Duplicate first array element into out location (if not null) and shift all other elements by
one slot left (the ordeing is kept). Returns true in case the element was erased.
File: static_array.bl
sarray_erase_keep_order :: fn (arr: *?TArr, i: s64)
Erase element on index i and move all following elements left using memmove. This might be slow in
case the array is large. Function invoke panic in case of index being out of array valid range <0, arr.len).
File: static_array.bl
sarray_erase :: fn (arr: *?TArr, i: s64)
Errase element at the index i. The index value must be valid in range 0 <= i < len.
File: static_array.bl
sarray_clear :: fn (arr: *?TArr) #inline
Clear the array.
File: static_array.bl
sarray_get_slice :: fn (arr: *?TArr) []sarray_typeof_elem(TArr) #inline
Get the content of static array as an slice.
File: static_array.bl
sarray_typeof_elem :: fn (TArr: type) type
Return type of the element.
File: static_array.bl