package base:builtin
Overview
package builtin provides documentation for Odin's predeclared identifiers. The items documented here are not actually in package builtin but here to allow for better documentation for the language's special identifiers.
Index
Constants (21)
- nil
- false
- true
- ODIN_OS
- ODIN_ARCH
- ODIN_ENDIAN
- ODIN_BUILD_MODE
- ODIN_ERROR_POS_STYLE
- ODIN_PLATFORM_SUBTARGET
- ODIN_WINDOWS_SUBSYSTEM
- ODIN_VENDOR
- ODIN_VERSION
- ODIN_ROOT
- ODIN_DEBUG
- ODIN_DISABLE_ASSERT
- ODIN_DEFAULT_TO_NIL_ALLOCATOR
- ODIN_DEFAULT_TO_PANIC_ALLOCATOR
- ODIN_NO_CRT
- ODIN_NO_ENTRY_POINT
- ODIN_NO_RTTI
- ODIN_COMPILE_TIMESTAMP
Types (57)
- byte
- bool
- b8
- b16
- b32
- b64
- i8
- u8
- i16
- u16
- i32
- u32
- i64
- u64
- i128
- u128
- rune
- f16
- f32
- f64
- complex32
- complex64
- complex128
- quaternion64
- quaternion128
- quaternion256
- int
- uint
- uintptr
- rawptr
- string
- cstring
- typeid
- any
- i16le
- u16le
- i32le
- u32le
- i64le
- u64le
- i128le
- u128le
- i16be
- u16be
- i32be
- u32be
- i64be
- u64be
- i128be
- u128be
- f16le
- f32le
- f64le
- f16be
- f32be
- f64be
- runtime.Maybe
Procedures (101)
- len
- cap
- size_of
- align_of
- offset_of
- offset_of_selector
- offset_of_member
- offset_of_by_string
- type_of
- type_info_of
- typeid_of
- swizzle
- complex
- quaternion
- real
- imag
- jmag
- kmag
- conj
- expand_values
- min
- max
- abs
- clamp
- soa_zip
- soa_unzip
- raw_data
- runtime.container_of
- runtime.init_global_temporary_allocator
- runtime.copy_slice
- runtime.copy_from_string
- runtime.unordered_remove
- runtime.ordered_remove
- runtime.remove_range
- runtime.pop
- runtime.pop_safe
- runtime.pop_front
- runtime.pop_front_safe
- runtime.delete_string
- runtime.delete_cstring
- runtime.delete_dynamic_array
- runtime.delete_slice
- runtime.delete_map
- runtime.new
- runtime.new_clone
- runtime.make_slice
- runtime.make_dynamic_array
- runtime.make_dynamic_array_len
- runtime.make_dynamic_array_len_cap
- runtime.make_map
- runtime.make_map_cap
- runtime.make_multi_pointer
- runtime.clear_map
- runtime.reserve_map
- runtime.shrink_map
- runtime.delete_key
- runtime.append_elem
- runtime.non_zero_append_elem
- runtime.append_elems
- runtime.non_zero_append_elems
- runtime.append_elem_string
- runtime.non_zero_append_elem_string
- runtime.append_string
- runtime.append_nothing
- runtime.inject_at_elem
- runtime.inject_at_elems
- runtime.inject_at_elem_string
- runtime.assign_at_elem
- runtime.assign_at_elems
- runtime.assign_at_elem_string
- runtime.clear_dynamic_array
- runtime.reserve_dynamic_array
- runtime.non_zero_reserve_dynamic_array
- runtime.resize_dynamic_array
- runtime.non_zero_resize_dynamic_array
- runtime.map_insert
- runtime.map_upsert
- runtime.card
- runtime.raw_soa_footer_slice
- runtime.assert
- runtime.raw_soa_footer_dynamic_array
- runtime.panic
- runtime.unimplemented
- runtime.make_soa_aligned
- runtime.make_soa_slice
- runtime.make_soa_dynamic_array
- runtime.assert_contextless
- runtime.make_soa_dynamic_array_len
- runtime.panic_contextless
- runtime.make_soa_dynamic_array_len_cap
- runtime.unimplemented_contextless
- runtime.resize_soa
- runtime.non_zero_resize_soa
- runtime.reserve_soa
- runtime.non_zero_reserve_soa
- runtime.append_soa_elem
- runtime.non_zero_append_soa_elem
- runtime.append_soa_elems
- runtime.non_zero_append_soa_elems
- runtime.unordered_remove_soa
- runtime.ordered_remove_soa
Procedure Groups (19)
- runtime.copy
- runtime.clear
- runtime.reserve
- runtime.non_zero_reserve
- runtime.resize
- runtime.non_zero_resize
- runtime.shrink
- runtime.free
- runtime.free_all
- runtime.delete
- runtime.make
- runtime.append
- runtime.non_zero_append
- runtime.inject_at
- runtime.assign_at
- runtime.make_soa
- runtime.append_soa
- runtime.delete_soa
- runtime.clear_soa
Constants
nil ¶
nil :: … // untyped nil
nil
is a predeclared identifier representing the zero value for a pointer, multi-pointer, enum, bit_set, slice, dynamic array, map, procedure, any, typeid, cstring, union, #soa array, #soa pointer, #relative type
false ¶
false :: 0 != 0 // untyped boolean
true ¶
true :: 0 == 0 // untyped boolean
ODIN_OS ¶
ODIN_OS : runtime.Odin_OS_Type : …
An enum value specifying the target platform's operating system.
// Defined internally by the compiler
Odin_OS_Type :: enum int { Unknown, Windows, Darwin, Linux, Essence, FreeBSD, OpenBSD, NetBSD, Haiku, WASI, JS, Orca, Freestanding, }
ODIN_ARCH ¶
ODIN_ARCH : runtime.Odin_Arch_Type : …
An enum value specifying the target platform's architecture.
// Defined internally by the compiler
Odin_Arch_Type :: enum int { Unknown, amd64, i386, arm32, arm64, wasm32, wasm64p32, riscv64, }
ODIN_ENDIAN ¶
ODIN_ENDIAN : runtime.Odin_Endian_Type : …
An enum value specifying the target platform's endiannes.
// Defined internally by the compiler
Odin_Endian_Type :: enum int { Unknown, Little, Big, }
ODIN_BUILD_MODE ¶
ODIN_BUILD_MODE : runtime.Odin_Build_Mode_Type : …
An enum value specifying the "build-mode".
// Defined internally by the compiler
Odin_Build_Mode_Type :: enum int { Executable, Dynamic, Static, Object, Assembly, LLVM_IR, }
ODIN_ERROR_POS_STYLE ¶
ODIN_ERROR_POS_STYLE : runtime.Odin_Error_Pos_Style_Type : …
An enum value specifying whether errors should be stylized in the default (MSVC-like) style or a UNIX (GCC-like) style.
Default = `path(1:2) Unix = `path:1:2:
ODIN_PLATFORM_SUBTARGET ¶
ODIN_PLATFORM_SUBTARGET : runtime.Odin_Platform_Subtarget_Type : …
An enum value specifying the selected subtarget type, only useful for Darwin targets.
// Defined internally by the compiler
Odin_Platform_Subtarget_Type :: enum int { Default, iOS, }
ODIN_WINDOWS_SUBSYSTEM ¶
ODIN_WINDOWS_SUBSYSTEM :: … // untyped string
A string specifying the current Windows subsystem, only useful on Windows targets.
ODIN_VENDOR ¶
ODIN_VENDOR :: … // untyped string
A string specifying the current Odin compiler vendor.
ODIN_DEBUG ¶
ODIN_DEBUG :: … // untyped boolean
Equal to true
if the -debug
flag has been set during compilation, otherwise false
.
ODIN_DISABLE_ASSERT ¶
ODIN_DISABLE_ASSERT :: … // untyped boolean
Equal to true
if the -disable-assert
flag has been set during compilation, otherwise false
.
ODIN_DEFAULT_TO_NIL_ALLOCATOR ¶
ODIN_DEFAULT_TO_NIL_ALLOCATOR :: … // untyped boolean
Equal to true
if the -default-to-nil-allocator
flag has been set during compilation or whether the current target defaults to the "nil allocator", otherwise false
.
ODIN_DEFAULT_TO_PANIC_ALLOCATOR ¶
ODIN_DEFAULT_TO_PANIC_ALLOCATOR :: … // untyped boolean
Equal to true
if the -default-to-panic-allocator
flag has been set during compilation or whether the current target defaults to the "panic allocator", otherwise false
.
ODIN_NO_CRT ¶
ODIN_NO_CRT :: … // untyped boolean
Equal to true
if the -no-crt
flag has been set during compilation (disallowing the C Run-Time library), otherwise false
.
ODIN_NO_ENTRY_POINT ¶
ODIN_NO_ENTRY_POINT :: … // untyped boolean
Equal to true
if the -no-entry-point
flag has been set during compilation, otherwise false
.
ODIN_NO_RTTI ¶
ODIN_NO_RTTI :: … // untyped boolean
Equal to true
if the -no-rtti
flag has been set during compilation (disabling Odin's Run-Time Type Information, only allowed on freestanding targets), otherwise false
.
ODIN_COMPILE_TIMESTAMP ¶
ODIN_COMPILE_TIMESTAMP :: … // untyped integer
Equal to the UNIX timestamp in nanoseconds at the time of the program's compilation.
Types
byte ¶
byte :: u8
byte
is an alias for u8
and is equivalent to u8
in all ways. It is used as a convention to distinguish values from 8-bit unsigned integer values.
bool ¶
bool :: bool
bool
is the set of boolean values, false
and true
. This is distinct to b8
. bool
has a size of 1 byte (8 bits).
b8 ¶
b8 :: b8
b8
is the set of boolean values, false
and true
. This is distinct to bool
. b8
has a size of 1 byte (8 bits).
b16 ¶
b16 :: b16
b16
is the set of boolean values, false
and true
. b16
has a size of 2 bytes (16 bits).
b32 ¶
b32 :: b32
b32
is the set of boolean values, false
and true
. b32
has a size of 4 bytes (32 bits).
b64 ¶
b64 :: b64
b64
is the set of boolean values, false
and true
. b64
has a size of 8 bytes (64 bits).
i16 ¶
i16 :: i16
i16
is the set of all signed 16-bit integers with native endianness. Range -32768 through 32767.
u16 ¶
u16 :: u16
u16
is the set of all unsigned 16-bit integers with native endianness. Range 0 through 65535.
i32 ¶
i32 :: i32
i32
is the set of all signed 32-bit integers with native endianness. Range -2147483648 through 2147483647.
u32 ¶
u32 :: u32
u32
is the set of all unsigned 32-bit integers with native endianness. Range 0 through 4294967295.
i64 ¶
i64 :: i64
i64
is the set of all signed 64-bit integers with native endianness. Range -9223372036854775808 through 9223372036854775807.
u64 ¶
u64 :: u64
u64
is the set of all unsigned 64-bit integers with native endianness. Range 0 through 18446744073709551615.
i128 ¶
i128 :: i128
i128
is the set of all signed 128-bit integers with native endianness. Range -170141183460469231731687303715884105728 through 170141183460469231731687303715884105727.
u128 ¶
u128 :: u128
u128
is the set of all unsigned 128-bit integers with native endianness. Range 0 through 340282366920938463463374607431768211455.
rune ¶
rune :: rune
rune
is the set of all Unicode code points. It is internally the same as i32
but distinct.
f16 ¶
f16 :: f16
f16
is the set of all IEEE-754 16-bit floating-point numbers with native endianness.
f32 ¶
f32 :: f32
f32
is the set of all IEEE-754 32-bit floating-point numbers with native endianness.
f64 ¶
f64 :: f64
f64
is the set of all IEEE-754 64-bit floating-point numbers with native endianness.
complex32 ¶
complex32 :: complex32
complex32
is the set of all complex numbers with f16
real and imaginary parts
complex64 ¶
complex64 :: complex64
complex64
is the set of all complex numbers with f32
real and imaginary parts
complex128 ¶
complex128 :: complex128
complex128
is the set of all complex numbers with f64
real and imaginary parts
quaternion64 ¶
quaternion64 :: quaternion64
quaternion64
is the set of all complex numbers with f16
real and imaginary (i, j, & k) parts
quaternion128 ¶
quaternion128 :: quaternion128
quaternion128
is the set of all complex numbers with f32
real and imaginary (i, j, & k) parts
quaternion256 ¶
quaternion256 :: quaternion256
quaternion256
is the set of all complex numbers with f64
real and imaginary (i, j, & k) parts
int ¶
int :: int
int
is a signed integer type that is at least 32 bits in size. It is a distinct type, however, and not an alias for say, i32
.
uint ¶
uint :: uint
uint
is an unsigned integer type that is at least 32 bits in size. It is a distinct type, however, and not an alias for say, u32
.
uintptr ¶
uintptr :: uintptr
uintptr
is an unsigned integer type that is large enough to hold the bit pattern of any pointer.
rawptr ¶
rawptr :: rawptr
rawptr
represents a pointer to an arbitrary type. It is equivalent to void *
in C.
string ¶
string :: string
string
is the set of all strings of 8-bit bytes, conventionally but not necessarily representing UTF-8 encoding text. A string
may be empty but not nil
. Elements of string
type are immutable and indexable.
cstring ¶
cstring :: cstring
cstring
is the set of all strings of 8-bit bytes terminated with a NUL (0) byte, conventionally but not necessarily representing UTF-8 encoding text. A cstring
may be empty or nil
. Elements of string
type are immutable but not indexable.
typeid ¶
typeid :: typeid
typeid
is a unique identifier for an Odin type at runtime. It can be mapped to relevant type information through type_info_of
.
any ¶
any :: any
any
can reference any data type at runtime. Internally it contains a pointer to the underlying data and its relevant typeid
. This is a very useful construct in order to have a runtime type safe printing procedure.
Note: The any
value is only valid for as long as the underlying data is still valid. Passing a literal to an any
will allocate the literal in the current stack frame.
Note: It is highly recommend that you do not use this unless you know what you are doing. Its primary use is for printing procedures.
i16le ¶
i16le :: i16le
i16le
is the set of all signed 16-bit integers with little endianness. Range -32768 through 32767.
u16le ¶
u16le :: u16le
u16le
is the set of all unsigned 16-bit integers with little endianness. Range 0 through 65535.
i32le ¶
i32le :: i32le
i32le
is the set of all signed 32-bit integers with little endianness. Range -2147483648 through 2147483647.
u32le ¶
u32le :: u32le
u32le
is the set of all unsigned 32-bit integers with little endianness. Range 0 through 4294967295.
i64le ¶
i64le :: i64le
i64le
is the set of all signed 64-bit integers with little endianness. Range -9223372036854775808 through 9223372036854775807.
u64le ¶
u64le :: u64le
u64le
is the set of all unsigned 64-bit integers with little endianness. Range 0 through 18446744073709551615.
i128le ¶
i128le :: i128le
i128le
is the set of all signed 128-bit integers with little endianness. Range -170141183460469231731687303715884105728 through 170141183460469231731687303715884105727.
u128le ¶
u128le :: u128le
u128le
is the set of all unsigned 128-bit integers with little endianness. Range 0 through 340282366920938463463374607431768211455.
i16be ¶
i16be :: i16be
i16be
is the set of all signed 16-bit integers with big endianness. Range -32768 through 32767.
u16be ¶
u16be :: u16be
u16be
is the set of all unsigned 16-bit integers with big endianness. Range 0 through 65535.
i32be ¶
i32be :: i32be
i32be
is the set of all signed 32-bit integers with big endianness. Range -2147483648 through 2147483647.
u32be ¶
u32be :: u32be
u32be
is the set of all unsigned 32-bit integers with big endianness. Range 0 through 4294967295.
i64be ¶
i64be :: i64be
i64be
is the set of all signed 64-bit integers with big endianness. Range -9223372036854775808 through 9223372036854775807.
u64be ¶
u64be :: u64be
u64be
is the set of all unsigned 64-bit integers with big endianness. Range 0 through 18446744073709551615.
i128be ¶
i128be :: i128be
i128be
is the set of all signed 128-bit integers with big endianness. Range -170141183460469231731687303715884105728 through 170141183460469231731687303715884105727.
u128be ¶
u128be :: u128be
u128be
is the set of all unsigned 128-bit integers with big endianness. Range 0 through 340282366920938463463374607431768211455.
f16le ¶
f16le :: f16le
f16le
is the set of all IEEE-754 16-bit floating-point numbers with little endianness.
f32le ¶
f32le :: f32le
f32le
is the set of all IEEE-754 32-bit floating-point numbers with little endianness.
f64le ¶
f64le :: f64le
f64le
is the set of all IEEE-754 64-bit floating-point numbers with little endianness.
f16be ¶
f16be :: f16be
f16be
is the set of all IEEE-754 16-bit floating-point numbers with big endianness.
f32be ¶
f32be :: f32be
f32be
is the set of all IEEE-754 32-bit floating-point numbers with big endianness.
f64be ¶
f64be :: f64be
f64be
is the set of all IEEE-754 64-bit floating-point numbers with big endianness.
Procedures
len ¶
len :: proc(v: Array_Type) -> int {…}
The len
built-in procedure returns the length of v
according to its type:
Array: the number of elements in v. Pointer to (any) array: the number of elements in `v^` (even if `v` is `nil`). Slice, dynamic array, or map: the number of elements in `v`; if `v` is `nil`, `len(v)` is zero. String: the number of bytes in `v` Enumerated array: the number elements in v.` Enum type: the number of enumeration fields. #soa array: the number of elements in `v`; if `v` is `nil`, `len(v)` is zero. #simd vector: the number of elements in `v`.
For some arguments, such as a string literal or a simple array expression, the result can be constant.
cap ¶
cap :: proc(v: Array_Type) -> int {…}
The cap
built-in procedure returns the length of v
according to its type:
Array: the number of elements in v. Pointer to (any) array: the number of elements in `v^` (even if `v` is `nil`). Dynamic array, or map: the reserved number of elements in `v`; if `v` is `nil`, `len(v)` is zero. Enum type: equal to `max(Enum)-min(Enum)+1`. #soa dynamic array: the reserved number of elements in `v`; if `v` is `nil`, `len(v)` is zero.
For some arguments, such as a string literal or a simple array expression, the result can be constant.
size_of ¶
size_of :: proc($T: typeid) -> int {…}
size_of
takes an expression or type, and returns the size in bytes of the type of the expression if it was hypothetically instantiated as a variable. The size does not include any memory possibly referenced by a value. For instance, if a slice was given, size_of
returns the size of the internal slice data structure and not the size of the memory referenced by the slice. For a struct, the size includes any padding introduced by field alignment (if not specified with #packed
. Other types follow similar rules. The return value of size_of
is a compile time known integer constant.
align_of ¶
align_of :: proc($T: typeid) -> int {…}
align_of
takes an expression or type, and returns the alignment in bytes of the type of the expression if it was hypothetically instantiated as a variable v
. It is the largest value m
such that the address of v
is always 0 mod m
.
offset_of ¶
offset_of :: proc{offset_of_selector, offset_of_member} {…}
offset_of
returns the offset in bytes with the struct of the field.
offset_of_selector ¶
offset_of_selector :: proc(selector: $T) -> uintptr {…}
e.g. offset_of(t.f), where t is an instance of the type T
offset_of_member ¶
offset_of_member :: proc($T: typeid, member: $M) -> uintptr {…}
e.g. offset_of(T, f), where T can be the type instead of a variable
offset_of_by_string ¶
e.g. offset_of(T, "f"), where T can be the type instead of a variable
type_info_of ¶
type_info_of :: proc($T: typeid) -> ^runtime.Type_Info {…}
type_info_of
returns the runtime type information from a given typeid
.
typeid_of ¶
typeid_of :: proc($T: typeid) -> typeid {…}
typeid_of
returns the associated runtime known typeid
of the specified type.
complex ¶
complex :: proc(real, imag: Float) -> Complex_Type {…}
quaternion ¶
quaternion :: proc(real, imag, jmag, kmag: Float) -> Quaternion_Type {…}
real ¶
real :: proc(v: Complex_Or_Quaternion) -> Float {…}
real
returns the real part of a complex or quaternion number v
. The return value will be the floating-point type corresponding to the type of v
.
imag ¶
imag :: proc(v: Complex_Or_Quaternion) -> Float {…}
imag
returns the i-imaginary part of a complex or quaternion number v
. The return value will be the floating-point type corresponding to the type of v
.
jmag ¶
jmag :: proc(v: Quaternion) -> Float {…}
jmag
returns the j-imaginary part of a quaternion number v
. The return value will be the floating-point type corresponding to the type of v
.
kmag ¶
kmag :: proc(v: Quaternion) -> Float {…}
kmag
returns the k-imaginary part of a quaternion number v
. The return value will be the floating-point type corresponding to the type of v
.
conj ¶
conj :: proc(v: Complex_Or_Quaternion) -> Complex_Or_Quaternion {…}
conj
returns the complex conjugate of a complex or quaternion number v
. This negates the imaginary component(s) whilst keeping the real component untouched.
expand_values ¶
expand_values :: proc(value: Struct_Or_Array) -> (A, B, C, ...) {…}
expand_values
will return multiple values corresponding to the multiple fields of the passed struct or the multiple elements of a passed fixed length array.
min ¶
min :: proc(values: ..T) -> T {…}
min
returns the minimum value of passed arguments of all the same type.
If one argument is passed and it is an enum or numeric type, then min
returns the minimum value of the enum type's fields or its minimum / most negative numeric value respectively.
max ¶
max :: proc(values: ..T) -> T {…}
max
returns the maximum value of passed arguments of all the same type.
If one argument is passed and it is an enum or numeric type, then max
returns the maximum value of the enum type's fields or its maximum numeric value respectively.
abs ¶
abs :: proc(value: T) -> T {…}
abs
returns the absolute value of passed argument.
If the argument is a complex or quaternion, this is equivalent to real(conj(value) * value)
.
clamp ¶
clamp :: proc(v, minimum, maximum: T) -> T {…}
clamp
returns a value v
clamped between minimum
and maximum
.
This is calculated as the following: minimum if v < minimum else maximum if v > maximum else v
.
soa_zip ¶
soa_zip :: proc(slices: ...) -> #soa[]Struct {…}
soa_unzip ¶
soa_unzip :: proc(value: $S/#soa[]$E) -> (slices: ...) {…}
raw_data ¶
raw_data :: proc(value: $T) -> [^]$E {…}
raw_data
returns the underlying data of a built-in data type as a multi-pointer.
raw_data([]$E) -> [^]E // slices raw_data([dynamic]$E) -> [^]E // dynamic arrays raw_data(^[$N]$E) -> [^]E // fixed array and enumerated arrays raw_data(^#simd[$N]$E) -> [^]E // simd vectors raw_data(string) -> [^]byte // string
container_of ¶
Recovers the containing/parent struct from a pointer to one of its fields. Works by "walking back" to the struct's starting address using the offset between the field and the struct.
Inputs:
ptr: Pointer to the field of a container struct
T: The type of the container struct
field_name: The name of the field in the T
struct
Returns:
A pointer to the container struct based on a pointer to a field in it
Example:
package container_of
import "base:runtime"
Node :: struct {
value: int,
prev: ^Node,
next: ^Node,
}
main :: proc() {
node: Node
field_ptr := &node.next
container_struct_ptr: ^Node = runtime.container_of(field_ptr, Node, "next")
assert(container_struct_ptr == &node)
assert(uintptr(field_ptr) - uintptr(container_struct_ptr) == size_of(node.value) + size_of(node.prev))
}
^Node
init_global_temporary_allocator ¶
init_global_temporary_allocator :: proc(size: int, backup_allocator := context.allocator) {…}
copy_slice ¶
copy_slice :: proc "contextless" (dst, src: $T/[]$T) -> int {…}
copy_slice
is a built-in procedure that copies elements from a source slice src
to a destination slice dst
.
The source and destination may overlap. Copy returns the number of elements copied, which will be the minimum
of len(src) and len(dst).
Prefer the procedure group copy
.
copy_from_string ¶
copy_from_string
is a built-in procedure that copies elements from a source string src
to a destination slice dst
.
The source and destination may overlap. Copy returns the number of elements copied, which will be the minimum
of len(src) and len(dst).
Prefer the procedure group copy
.
unordered_remove ¶
unordered_remove :: proc(array: ^$T/[dynamic]$T, #any_int index: int, loc := #caller_location) {…}
unordered_remove
removed the element at the specified index
. It does so by replacing the current end value
with the old value, and reducing the length of the dynamic array by 1.
Note: This is an O(1) operation.
Note: If you want the elements to remain in their order, use ordered_remove
.
Note: If the index is out of bounds, this procedure will panic.
ordered_remove ¶
ordered_remove :: proc(array: ^$T/[dynamic]$T, #any_int index: int, loc := #caller_location) {…}
ordered_remove
removed the element at the specified index
whilst keeping the order of the other elements.
Note: This is an O(N) operation.
Note: If the elements do not have to remain in their order, prefer unordered_remove
.
Note: If the index is out of bounds, this procedure will panic.
remove_range ¶
remove_range :: proc(array: ^$T/[dynamic]$T, #any_int lo, #any_int hi: int, loc := #caller_location) {…}
remove_range
removes a range of elements specified by the range lo
and hi
, whilst keeping the order of the other elements.
Note: This is an O(N) operation. Note: If the range is out of bounds, this procedure will panic.
pop ¶
pop :: proc(array: ^$T/[dynamic]$T, loc := #caller_location) -> (res: $T) {…}
pop
will remove and return the end value of dynamic array array
and reduces the length of array
by 1.
Note: If the dynamic array has no elements (len(array) == 0
), this procedure will panic.
pop_safe ¶
pop_safe :: proc "contextless" (array: ^$T/[dynamic]$T) -> (res: $T, ok: bool) {…}
pop_safe
trys to remove and return the end value of dynamic array array
and reduces the length of array
by 1.
If the operation is not possible, it will return false.
pop_front ¶
pop_front :: proc(array: ^$T/[dynamic]$T, loc := #caller_location) -> (res: $T) {…}
pop_front
will remove and return the first value of dynamic array array
and reduces the length of array
by 1.
Note: If the dynamic array as no elements (len(array) == 0
), this procedure will panic.
pop_front_safe ¶
pop_front_safe :: proc "contextless" (array: ^$T/[dynamic]$T) -> (res: $T, ok: bool) {…}
pop_front_safe
trys to return and remove the first value of dynamic array array
and reduces the length of array
by 1.
If the operation is not possible, it will return false.
delete_string ¶
delete_string :: proc(str: string, allocator := context.allocator, loc := #caller_location) -> Allocator_Error {…}
delete_string
will try to free the underlying data of the passed string, with the given allocator
if the allocator supports this operation.
Note: Prefer the procedure group delete
.
delete_cstring ¶
delete_cstring :: proc(str: cstring, allocator := context.allocator, loc := #caller_location) -> Allocator_Error {…}
delete_cstring
will try to free the underlying data of the passed string, with the given allocator
if the allocator supports this operation.
Note: Prefer the procedure group delete
.
delete_dynamic_array ¶
delete_dynamic_array :: proc(array: $T/[dynamic]$T, loc := #caller_location) -> Allocator_Error {…}
delete_dynamic_array
will try to free the underlying data of the passed dynamic array, with the given allocator
if the allocator supports this operation.
Note: Prefer the procedure group delete
.
delete_slice ¶
delete_slice :: proc(array: $T/[]$T, allocator := context.allocator, loc := #caller_location) -> Allocator_Error {…}
delete_slice
will try to free the underlying data of the passed sliced, with the given allocator
if the allocator supports this operation.
Note: Prefer the procedure group delete
.
delete_map ¶
delete_map :: proc(m: $T/map[$T]$T, loc := #caller_location) -> Allocator_Error {…}
delete_map
will try to free the underlying data of the passed map, with the given allocator
if the allocator supports this operation.
Note: Prefer the procedure group delete
.
new ¶
new :: proc($T: typeid, allocator := context.allocator, loc := #caller_location) -> (^typeid, Allocator_Error) #optional_ok {…}
The new built-in procedure allocates memory. The first argument is a type, not a value, and the value return is a pointer to a newly allocated value of that type using the specified allocator, default is context.allocator
new_clone ¶
new_clone :: proc(data: $T, allocator := context.allocator, loc := #caller_location) -> (t: ^$T, err: Allocator_Error) #optional_ok {…}
make_slice ¶
make_slice :: proc($T: typeid/[]T, #any_int len: int, allocator := context.allocator, loc := #caller_location) -> (T, Allocator_Error) #optional_ok {…}
make_slice
allocates and initializes a slice. Like new
, the first argument is a type, not a value.
Unlike new
, make
's return value is the same as the type of its argument, not a pointer to it.
Note: Prefer using the procedure group make
.
make_dynamic_array ¶
make_dynamic_array :: proc($T: typeid/[dynamic]T, allocator := context.allocator, loc := #caller_location) -> (T, Allocator_Error) #optional_ok {…}
make_dynamic_array
allocates and initializes a dynamic array. Like new
, the first argument is a type, not a value.
Unlike new
, make
's return value is the same as the type of its argument, not a pointer to it.
Note: Prefer using the procedure group make
.
make_dynamic_array_len ¶
make_dynamic_array_len :: proc($T: typeid/[dynamic]T, #any_int len: int, allocator := context.allocator, loc := #caller_location) -> (T, Allocator_Error) #optional_ok {…}
make_dynamic_array_len
allocates and initializes a dynamic array. Like new
, the first argument is a type, not a value.
Unlike new
, make
's return value is the same as the type of its argument, not a pointer to it.
Note: Prefer using the procedure group make
.
make_dynamic_array_len_cap ¶
make_dynamic_array_len_cap :: proc($T: typeid/[dynamic]T, #any_int len: int, #any_int cap: int, allocator := context.allocator, loc := #caller_location) -> (array: T, err: Allocator_Error) #optional_ok {…}
make_dynamic_array_len_cap
allocates and initializes a dynamic array. Like new
, the first argument is a type, not a value.
Unlike new
, make
's return value is the same as the type of its argument, not a pointer to it.
Note: Prefer using the procedure group make
.
make_map ¶
make_map :: proc($T: typeid/map[T]T, allocator := context.allocator, loc := #caller_location) -> (m: T) {…}
make_map
initializes a map with an allocator. Like new
, the first argument is a type, not a value.
Unlike new
, make
's return value is the same as the type of its argument, not a pointer to it.
Note: Prefer using the procedure group make
.
make_map_cap ¶
make_map_cap :: proc($T: typeid/map[T]T, #any_int capacity: int, allocator := context.allocator, loc := #caller_location) -> (m: T, err: Allocator_Error) #optional_ok {…}
make_map_cap
initializes a map with an allocator and allocates space using capacity
.
Like new
, the first argument is a type, not a value.
Unlike new
, make
's return value is the same as the type of its argument, not a pointer to it.
Note: Prefer using the procedure group make
.
make_multi_pointer ¶
make_multi_pointer :: proc($T: typeid/[^]T, #any_int len: int, allocator := context.allocator, loc := #caller_location) -> (mp: $/[^]T, err: Allocator_Error) #optional_ok {…}
make_multi_pointer
allocates and initializes a multi-pointer. Like new
, the first argument is a type, not a value.
Unlike new
, make
's return value is the same as the type of its argument, not a pointer to it.
This is "similar" to doing raw_data(make([]E, len, allocator))
.
Note: Prefer using the procedure group make
.
clear_map ¶
clear_map :: proc "contextless" (m: ^$T/map[$T]$T) {…}
clear_map
will set the length of a passed map to 0
Note: Prefer the procedure group clear
reserve_map ¶
reserve_map :: proc(m: ^$T/map[$T]$T, #any_int capacity: int, loc := #caller_location) -> Allocator_Error {…}
reserve_map
will try to reserve memory of a passed map to the requested element count (setting the cap
).
Note: Prefer the procedure group reserve
shrink_map ¶
shrink_map :: proc(m: ^$T/map[$T]$T, loc := #caller_location) -> (did_shrink: bool, err: Allocator_Error) {…}
Shrinks the capacity of a map down to the current length.
Note: Prefer the procedure group shrink
delete_key ¶
delete_key :: proc(m: ^$T/map[$T]$T, key: $T) -> (deleted_key: $T, deleted_value: $T) {…}
The delete_key built-in procedure deletes the element with the specified key (m[key]) from the map. If m is nil, or there is no such element, this procedure is a no-op
append_elem ¶
append_elem :: proc(array: ^$T/[dynamic]$T, #no_broadcast arg: $T, loc := #caller_location) -> (n: int, err: Allocator_Error) #optional_ok {…}
non_zero_append_elem ¶
non_zero_append_elem :: proc(array: ^$T/[dynamic]$T, #no_broadcast arg: $T, loc := #caller_location) -> (n: int, err: Allocator_Error) #optional_ok {…}
append_elems ¶
append_elems :: proc(array: ^$T/[dynamic]$T, .. #no_broadcast args: ..$T, loc := #caller_location) -> (n: int, err: Allocator_Error) #optional_ok {…}
non_zero_append_elems ¶
non_zero_append_elems :: proc(array: ^$T/[dynamic]$T, .. #no_broadcast args: ..$T, loc := #caller_location) -> (n: int, err: Allocator_Error) #optional_ok {…}
append_elem_string ¶
append_elem_string :: proc(array: ^$T/[dynamic]$E/u8, arg: $S/string, loc := #caller_location) -> (n: int, err: Allocator_Error) #optional_ok {…}
non_zero_append_elem_string ¶
non_zero_append_elem_string :: proc(array: ^$T/[dynamic]$E/u8, arg: $S/string, loc := #caller_location) -> (n: int, err: Allocator_Error) #optional_ok {…}
append_string ¶
append_string :: proc(array: ^$T/[dynamic]$E/u8, .. args: ..string, loc := #caller_location) -> (n: int, err: Allocator_Error) #optional_ok {…}
The append_string built-in procedure appends multiple strings to the end of a [dynamic]u8 like type
append_nothing ¶
append_nothing :: proc(array: ^$T/[dynamic]$T, loc := #caller_location) -> (n: int, err: Allocator_Error) #optional_ok {…}
inject_at_elem ¶
inject_at_elem :: proc(array: ^$T/[dynamic]$T, #any_int index: int, #no_broadcast arg: $T, loc := #caller_location) -> (ok: bool, err: Allocator_Error) #optional_ok {…}
inject_at_elems ¶
inject_at_elems :: proc(array: ^$T/[dynamic]$T, #any_int index: int, .. #no_broadcast args: ..$T, loc := #caller_location) -> (ok: bool, err: Allocator_Error) #optional_ok {…}
inject_at_elem_string ¶
inject_at_elem_string :: proc(array: ^$T/[dynamic]$E/u8, #any_int index: int, arg: string, loc := #caller_location) -> (ok: bool, err: Allocator_Error) #optional_ok {…}
assign_at_elem ¶
assign_at_elem :: proc(array: ^$T/[dynamic]$T, #any_int index: int, #no_broadcast arg: $T, loc := #caller_location) -> (ok: bool, err: Allocator_Error) #optional_ok {…}
assign_at_elems ¶
assign_at_elems :: proc(array: ^$T/[dynamic]$T, #any_int index: int, .. #no_broadcast args: ..$T, loc := #caller_location) -> (ok: bool, err: Allocator_Error) #optional_ok {…}
assign_at_elem_string ¶
assign_at_elem_string :: proc(array: ^$T/[dynamic]$E/u8, #any_int index: int, arg: string, loc := #caller_location) -> (ok: bool, err: Allocator_Error) #optional_ok {…}
clear_dynamic_array ¶
clear_dynamic_array :: proc "contextless" (array: ^$T/[dynamic]$T) {…}
clear_dynamic_array
will set the length of a passed dynamic array to 0
Note: Prefer the procedure group clear
.
reserve_dynamic_array ¶
reserve_dynamic_array :: proc(array: ^$T/[dynamic]$T, #any_int capacity: int, loc := #caller_location) -> Allocator_Error {…}
non_zero_reserve_dynamic_array ¶
non_zero_reserve_dynamic_array :: proc(array: ^$T/[dynamic]$T, #any_int capacity: int, loc := #caller_location) -> Allocator_Error {…}
resize_dynamic_array ¶
resize_dynamic_array :: proc(array: ^$T/[dynamic]$T, #any_int length: int, loc := #caller_location) -> Allocator_Error {…}
resize_dynamic_array
will try to resize memory of a passed dynamic array or map to the requested element count (setting the len
, and possibly cap
).
Note: Prefer the procedure group resize
non_zero_resize_dynamic_array ¶
non_zero_resize_dynamic_array :: proc(array: ^$T/[dynamic]$T, #any_int length: int, loc := #caller_location) -> Allocator_Error {…}
map_insert ¶
map_insert :: proc(m: ^$T/map[$T]$T, key: $T, value: $T, loc := #caller_location) -> (ptr: ^$T) {…}
map_upsert ¶
map_upsert :: proc(m: ^$T/map[$T]$T, key: $T, value: $T, loc := #caller_location) -> (prev_key: $T, value_ptr: ^$T, found_previous: bool) {…}
Explicitly inserts a key and value into a map m
, the same as map_insert
, but the return values differ.
prev_key
will return the previous pointer of a key if it exists, check found_previous
if was previously found
value_ptr
will return the pointer of the memory where the insertion happens, and nil
if the map failed to resize
found_previous
will be true a previous key was found
raw_soa_footer_slice ¶
raw_soa_footer_slice :: proc(array: ^$T/#soa[]$T) -> (footer: ^Raw_SOA_Footer_Slice) {…}
assert ¶
assert :: proc(condition: bool, message: string = "", loc := #caller_location) {…}
raw_soa_footer_dynamic_array ¶
raw_soa_footer_dynamic_array :: proc(array: ^$T/#soa[dynamic]$T) -> (footer: ^Raw_SOA_Footer_Dynamic_Array) {…}
panic ¶
panic :: proc(message: string, loc := #caller_location) -> ! {…}
unimplemented ¶
unimplemented :: proc(message: string, loc := #caller_location) -> ! {…}
make_soa_aligned ¶
make_soa_aligned :: proc($T: typeid/#soa[]T, #any_int length, #any_int alignment: int, allocator := context.allocator, loc := #caller_location) -> (array: T, err: Allocator_Error) #optional_ok {…}
make_soa_slice ¶
make_soa_slice :: proc($T: typeid/#soa[]T, #any_int length: int, allocator := context.allocator, loc := #caller_location) -> (array: T, err: Allocator_Error) #optional_ok {…}
make_soa_dynamic_array ¶
make_soa_dynamic_array :: proc($T: typeid/#soa[dynamic]T, allocator := context.allocator, loc := #caller_location) -> (array: T, err: Allocator_Error) #optional_ok {…}
assert_contextless ¶
assert_contextless :: proc "contextless" (condition: bool, message: string = "", loc := #caller_location) {…}
make_soa_dynamic_array_len ¶
make_soa_dynamic_array_len :: proc($T: typeid/#soa[dynamic]T, #any_int length: int, allocator := context.allocator, loc := #caller_location) -> (array: T, err: Allocator_Error) #optional_ok {…}
panic_contextless ¶
panic_contextless :: proc "contextless" (message: string, loc := #caller_location) -> ! {…}
make_soa_dynamic_array_len_cap ¶
make_soa_dynamic_array_len_cap :: proc($T: typeid/#soa[dynamic]T, #any_int length, #any_int capacity: int, allocator := context.allocator, loc := #caller_location) -> (array: T, err: Allocator_Error) #optional_ok {…}
unimplemented_contextless ¶
unimplemented_contextless :: proc "contextless" (message: string, loc := #caller_location) -> ! {…}
resize_soa ¶
resize_soa :: proc(array: ^$T/#soa[dynamic]$T, #any_int length: int, loc := #caller_location) -> Allocator_Error {…}
non_zero_resize_soa ¶
non_zero_resize_soa :: proc(array: ^$T/#soa[dynamic]$T, #any_int length: int, loc := #caller_location) -> Allocator_Error {…}
reserve_soa ¶
reserve_soa :: proc(array: ^$T/#soa[dynamic]$T, #any_int capacity: int, loc := #caller_location) -> Allocator_Error {…}
non_zero_reserve_soa ¶
non_zero_reserve_soa :: proc(array: ^$T/#soa[dynamic]$T, #any_int capacity: int, loc := #caller_location) -> Allocator_Error {…}
append_soa_elem ¶
append_soa_elem :: proc(array: ^$T/#soa[dynamic]$T, #no_broadcast arg: $T, loc := #caller_location) -> (n: int, err: Allocator_Error) #optional_ok {…}
non_zero_append_soa_elem ¶
non_zero_append_soa_elem :: proc(array: ^$T/#soa[dynamic]$T, #no_broadcast arg: $T, loc := #caller_location) -> (n: int, err: Allocator_Error) #optional_ok {…}
append_soa_elems ¶
append_soa_elems :: proc(array: ^$T/#soa[dynamic]$T, .. #no_broadcast args: ..$T, loc := #caller_location) -> (n: int, err: Allocator_Error) #optional_ok {…}
non_zero_append_soa_elems ¶
non_zero_append_soa_elems :: proc(array: ^$T/#soa[dynamic]$T, .. #no_broadcast args: ..$T, loc := #caller_location) -> (n: int, err: Allocator_Error) #optional_ok {…}
unordered_remove_soa ¶
unordered_remove_soa :: proc(array: ^$T/#soa[dynamic]$T, #any_int index: int, loc := #caller_location) {…}
unordered_remove_soa
removed the element at the specified index
. It does so by replacing the current end value
with the old value, and reducing the length of the dynamic array by 1.
Note: This is an O(1) operation.
Note: If you the elements to remain in their order, use ordered_remove_soa
.
Note: If the index is out of bounds, this procedure will panic.
ordered_remove_soa ¶
ordered_remove_soa :: proc(array: ^$T/#soa[dynamic]$T, #any_int index: int, loc := #caller_location) {…}
ordered_remove_soa
removed the element at the specified index
whilst keeping the order of the other elements.
Note: This is an O(N) operation.
Note: If you the elements do not have to remain in their order, prefer unordered_remove_soa
.
Note: If the index is out of bounds, this procedure will panic.
Procedure Groups
copy ¶
copy :: proc{ copy_slice, copy_from_string, }
copy
is a built-in procedure that copies elements from a source slice/string src
to a destination slice dst
.
The source and destination may overlap. Copy returns the number of elements copied, which will be the minimum
of len(src) and len(dst).
clear ¶
clear :: proc{ clear_dynamic_array, clear_map, clear_soa_dynamic_array, }
clear
will set the length of a passed dynamic array or map to 0
reserve ¶
reserve :: proc{ reserve_dynamic_array, reserve_map, reserve_soa, }
reserve
will try to reserve memory of a passed dynamic array or map to the requested element count (setting the cap
).
non_zero_reserve ¶
non_zero_reserve :: proc{ non_zero_reserve_dynamic_array, non_zero_reserve_soa, }
resize ¶
resize :: proc{ resize_dynamic_array, resize_soa, }
resize
will try to resize memory of a passed dynamic array to the requested element count (setting the len
, and possibly cap
).
non_zero_resize ¶
non_zero_resize :: proc{ non_zero_resize_dynamic_array, non_zero_resize_soa, }
shrink ¶
shrink :: proc{ shrink_dynamic_array, shrink_map, }
Shrinks the capacity of a dynamic array or map down to the current length, or the given capacity.
free ¶
free :: proc{ mem_free, }
free
will try to free the passed pointer, with the given allocator
if the allocator supports this operation.
free_all ¶
free_all :: proc{ mem_free_all, }
free_all
will try to free/reset all of the memory of the given allocator
if the allocator supports this operation.
delete ¶
delete :: proc{ delete_string, delete_cstring, delete_dynamic_array, delete_slice, delete_map, delete_soa_slice, delete_soa_dynamic_array, }
delete
will try to free the underlying data of the passed built-in data structure (string, cstring, dynamic array, slice, or map), with the given allocator
if the allocator supports this operation.
Note: Prefer delete
over the specific delete_*
procedures where possible.
make ¶
make :: proc{ make_slice, make_dynamic_array, make_dynamic_array_len, make_dynamic_array_len_cap, make_map, make_map_cap, make_multi_pointer, make_soa_slice, make_soa_dynamic_array, make_soa_dynamic_array_len, make_soa_dynamic_array_len_cap, }
make
built-in procedure allocates and initializes a value of type slice, dynamic array, map, or multi-pointer (only).
Similar to new
, the first argument is a type, not a value. Unlike new, make's return type is the same as the
type of its argument, not a pointer to it.
Make uses the specified allocator, default is context.allocator.
append ¶
append :: proc{ append_elem, append_elems, append_elem_string, append_soa_elem, append_soa_elems, }
The append built-in procedure appends elements to the end of a dynamic array
non_zero_append ¶
non_zero_append :: proc{ non_zero_append_elem, non_zero_append_elems, non_zero_append_elem_string, non_zero_append_soa_elem, non_zero_append_soa_elems, }
inject_at ¶
inject_at :: proc{ inject_at_elem, inject_at_elems, inject_at_elem_string, }
assign_at ¶
assign_at :: proc{ assign_at_elem, assign_at_elems, assign_at_elem_string, }
make_soa ¶
make_soa :: proc{ make_soa_slice, make_soa_dynamic_array, make_soa_dynamic_array_len, make_soa_dynamic_array_len_cap, }
append_soa ¶
append_soa :: proc{ append_soa_elem, append_soa_elems, }
The append_soa built-in procedure appends elements to the end of an #soa dynamic array
delete_soa ¶
delete_soa :: proc{ delete_soa_slice, delete_soa_dynamic_array, }
clear_soa ¶
clear_soa :: proc{ clear_soa_dynamic_array, }