Clarify get and get_ptr in core:container/small_array.

See #5892.
This commit is contained in:
Jeroen van Rijn
2025-11-06 15:21:56 +01:00
parent 4ce01854d5
commit 91409cb37e

View File

@@ -105,8 +105,13 @@ This operation assumes that the small-array is large enough.
This will result in:
- the value if 0 <= index < len
- the zero value of the type if len < index < capacity
- 'crash' if capacity < index or index < 0
- raise a bounds check error if capacity <= index
- the previous value if len < index < capacity, which defauls to T's zero value.
e.g. if you call `small_array.push(&a, 0, 1, 2)`, and `i := pop_back(&a)`,
then `get(a, 2)` will return the earlier value `2` at that location.
See also `get_safe`, which returns T's zero value and `false` if `index` is out of bounds.
**Inputs**
- `a`: The small-array
@@ -125,8 +130,13 @@ This operation assumes that the small-array is large enough.
This will result in:
- the pointer if 0 <= index < len
- the pointer to the zero value if len < index < capacity
- 'crash' if capacity < index or index < 0
- raise a bounds check error if capacity <= index
- a pointer to the previous value if len < index < capacity, which defauls to T's zero value.
e.g. if you call `small_array.push(&a, 0, 1, 2)`, and `i := pop_back(&a)`,
then `get_ptr(a, 2)` will return a pointer to the slot containing the earlier value `2` at that location.
See also `get_ptr_safe`, which returns a nil pointer, and `false` if `index` is out of bounds.
**Inputs**
- `a`: A pointer to the small-array