@array
A dynamic array which automatically grows or shrinks as needed
A dynamic array which automatically grows or shrinks as needed
//use built in array syntax
var myArr: "apples", "oranges", "pears";
for myArr {
print @value;
}
//or do it manually
var.@array(i64) otherArr: [1, 2, 3, 4];
otherArr.add(5);
sbuf
The static buffer of values.
//this will be expanded
var.sbuf foo: [];
//into this
var.[#paste SMALL_BUFFER_SIZE x @subtype] foo: [];
Type: var.[2 x @subtype]|ptr(@subtype)
The space for some values or a pointer to the first value
if @self.buffer => ptr(@subtype) {
return @self.buffer + index;
}
Type: var.i64
How many values are currently in the array
if index < @self.size {
//etc
}
Type: var.i64
How much space is allocated for values
if @self.capacity > @self.size {
//etc
}
Type: fn => ptr(@subtype)|null
Returns a pointer to the value at the given index or null if not found
The offset into the array.
print myArr.at(0);
Type: fn => @subtype
Returns the value at the given index
Warning! Might read out of bounds.
The offset into the array.
var lastValue: myArr.value(myArr.size - 1);
Type: fn
Appends a value at the end of the array, resizing the array if necessary
The value to be inserted.
var.@array(i64) myArray: 1, 2, 3;
myArray.add(123);
myArray.add(888);
Type: fn
Use this method when you want to increase capacity for more elements ahead of time
How many elements will fit.
myArr.reserve(1024);
Type: fn => ptr(@subtype)
The runtime calls this method to set up the array before copying elements into it
how many elements will fit
To gain a better understanding of this class, it is recommended to look at the source code of the following file: