struct
InlineArray
A fixed-size sequence of size homogeneous elements where size is a constant expression.
Parameters
- ElementType (
CollectionElement
): The type of the elements in the array. - size (
Int
): The size of the array.
Aliases
type = array<#lit.struct.extract<:@stdlib::@builtin::@int::@Int size, "value">, :trait<@stdlib::@builtin::@value::@CollectionElement> ElementType>
:
Implemented traits
AnyType
,
Copyable
,
Movable
,
Sized
Methods
__init__
__init__(inout self: Self)
This constructor will always cause a compile time error if used. It is used to steer users away from uninitialized memory.
__init__(inout self: Self, *, unsafe_uninitialized: Bool)
Create an InlineArray with uninitialized memory.
Note that this is highly unsafe and should be used with caution.
We recommend to use the InlineList
instead if all the objects
are not available when creating the array.
If despite those workarounds, one still needs an uninitialized array, it is possible with:
var uninitialized_array = InlineArray[Int, 10](unsafe_uninitialized=True)
Args:
- unsafe_uninitialized (
Bool
): A boolean to indicate if the array should be initialized. Always set toTrue
(it's not actually used inside the constructor).
__init__(inout self: Self, fill: ElementType)
Constructs an empty array where each element is the supplied fill
.
Args:
- fill (
ElementType
): The element to fill each index.
__init__(inout self: Self, *elems: ElementType)
Constructs an array given a set of arguments.
Args:
- *elems (
ElementType
): The element types.
__getitem__
__getitem__(self: Reference[InlineArray[ElementType, size], is_mutable, lifetime, 0], idx: Int) -> ref [$1] ElementType
Get a Reference
to the element at the given index.
Args:
- idx (
Int
): The index of the item.
Returns:
A reference to the item at the given index.
__getitem__[IntableType: Intable, index: $0](self: Reference[InlineArray[ElementType, size], is_mutable, lifetime, 0]) -> ref [$3] ElementType
Get a Reference
to the element at the given index.
Parameters:
- IntableType (
Intable
): The inferred type of an intable argument. - index (
$0
): The index of the item.
Returns:
A reference to the item at the given index.
__contains__
__contains__[T: ComparableCollectionElement](self: Self, value: T) -> Bool
Verify if a given value is present in the array.
from utils import InlineArray
var x = InlineArray[Int, 3](1,2,3)
if 3 in x: print("x contains 3")
Parameters:
- T (
ComparableCollectionElement
): The type of the elements in the array. Must implement the traitsEqualityComparable
andCollectionElement
.
Args:
- value (
T
): The value to find.
Returns:
True if the value is contained in the array, False otherwise.
unsafe_ptr
unsafe_ptr(self: Self) -> UnsafePointer[ElementType, 0]
Get an UnsafePointer
to the underlying array.
That pointer is unsafe but can be used to read or write to the array.
Be careful when using this. As opposed to a pointer to a List
,
this pointer becomes invalid when the InlineArray
is moved.
Make sure to refresh your pointer every time the InlineArray
is moved.
Returns:
An UnsafePointer
to the underlying array.