sonolus.script.array¶
For usage details, see the corresponding concepts page.
Dim = Literal
module-attribute
¶
Shorthand for typing.Literal intended for use in array dimensions for type checker compatibility.
Array
¶
Bases: GenericValue, ArrayLike[T]
A fixed size array of values.
Supports negative indexes.
Usage
array_1 = Array(1, 2, 3)
array_2 = Array[int, 0]()
array_3 = +Array[int, 3] # Create a zero-initialized array
array_4 = +Array[int, Dim[3]] # Alternative syntax for compliance with type checkers
array_5 = +array_1 # Create a copy of array_1
__contains__(value: Any) -> bool
¶
Return whether any element in the array is equal to the given value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Any
|
The value to check for. |
required |
__iter__() -> SonolusIterator[T]
¶
Return an iterator over the array.
__pos__() -> Array[T, Size]
¶
Return a copy of the array.
__reversed__()
¶
Return a reversed view of the array.
count(value: T) -> int
¶
Return the number of elements in the array equal to the given value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
T
|
The value to count. |
required |
element_type() -> type[T] | type[Value]
classmethod
¶
Return the type of elements in this array type.
get_unchecked(index: Num) -> T
¶
Get the element at the given index possibly without bounds checking.
The compiler may still determine that the index is out of bounds and throw an error, but it may skip these checks at runtime.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
Num
|
The index to get. |
required |
Returns:
| Type | Description |
|---|---|
T
|
The element at the given index. |
index(value: T, start: int = 0, stop: int | None = None) -> int
¶
Return the index of the value in the array equal to the given value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
T
|
The value to search for. |
required |
start
|
int
|
The index to start searching from. |
0
|
stop
|
int | None
|
The index to stop searching at. If |
None
|
index_of_max(*, key: Callable[[T], Any] | None = None) -> int
¶
Return the index of the maximum value in the array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
Callable[[T], Any] | None
|
A one-argument ordering function to use for comparison like the one used in |
None
|
index_of_min(*, key: Callable[[T], Any] | None = None) -> int
¶
Return the index of the minimum value in the array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
Callable[[T], Any] | None
|
A one-argument ordering function to use for comparison like the one used in |
None
|
last_index(value: T) -> int
¶
Return the last index of the value in the array equal to the given value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
T
|
The value to search for. |
required |
reverse()
¶
Reverse the values in the array in place.
set_unchecked(index: Num, value: T)
¶
Set the element at the given index possibly without bounds checking.
The compiler may still determine that the index is out of bounds and throw an error, but it may skip these checks at runtime.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
Num
|
The index to set. |
required |
value
|
T
|
The value to set. |
required |
shuffle()
¶
Shuffle the values in the array in place.
size() -> int
classmethod
¶
Return the size of this array type.
On instances, use len(array) instead.
sort(*, key: Callable[[T], Any] | None = None, reverse: bool = False)
¶
Sort the values in the array in place.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
Callable[[T], Any] | None
|
A one-argument ordering function to use for comparison. |
None
|
reverse
|
bool
|
If |
False
|
swap(i: int, j: int)
¶
Swap the values at the given positive indices.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
i
|
int
|
The first index. |
required |
j
|
int
|
The second index. |
required |
swap_unchecked(i: Num, j: Num)
¶
Swap the values at the given indices possibly without bounds checking.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
i
|
Num
|
The first index. |
required |
j
|
Num
|
The second index. |
required |
unchecked() -> ArrayLike[T]
¶
Return a proxy object that may skip bounds checking and may not support negative indexes.