value · System
Span<T>
public value Span<T>
A run of an array's elements, seen in place: span[i] reads and writes the array, Slice makes a smaller view,
nothing is copied. A view of a list sees its elements until the list grows.
- Tipo
- value
- Espacio de nombres
- System
- Ensamblado
- System.Core
- Acceso
- public
- Archivo fuente
Span.ant
Parámetros de tipo
| Nombre | Restricciones |
|---|---|
T | cualquier tipo |
Constructores
new(T[] array)
#
The whole array.
count elements of the array from from.
Propiedades
T[] Items { get; }
#
The array under the view and where the view starts in it (for code that works on arrays).
Métodos
span[i].
span[i] = value.
The view from from to the end, and count elements from from.
ToArray() : T[]
#
A new array with the elements.
Copies the elements into target (at least as long).
Fill(T value)
#
Every element set to value.
Iterator() : SpanIterator<T>
#
Código fuente
Span<T> en Antril, descompilado a partir de su Larva HIR.
// System.Span — System.Core (decompiled from Larva HIR)
into namespace System
{
/// A run of an array's elements, seen in place: `span[i]` reads and writes the array, Slice makes a smaller view,
/// nothing is copied. A view of a list sees its elements until the list grows.
public value Span<T>
{
T[] items;
i32 start;
i32 length;
[NoInline]
static OutOfRange()
{
throw new ArgumentError("Span: the range is outside the span");
}
public:
/// The whole array.
new(T[] array)
{
items = array;
length = array.Length;
}
/// `count` elements of the array from `from`.
new(T[] array, i32 from, i32 count)
{
if ((u32)from > (u32)array.Length || (u32)count > (u32)(array.Length - from))
OutOfRange();
items = array;
start = from;
length = count;
}
/// `span[i]`.
At(i32 index) : T
{
if ((u32)index >= (u32)length)
Fail.Index();
return items[start + index];
}
/// `span[i] = value`.
SetAt(i32 index, T value)
{
if ((u32)index >= (u32)length)
Fail.Index();
items[start + index] = value;
}
/// The view from `from` to the end, and `count` elements from `from`.
Slice(i32 from) : Span<T> => Slice(from, length - from);
Slice(i32 from, i32 count) : Span<T>
{
if ((u32)from > (u32)length || (u32)count > (u32)(length - from))
OutOfRange();
Span<T> view = this;
view.start = start + from;
view.length = count;
return view;
}
/// A new array with the elements.
ToArray() : T[]
{
T[] copy = new T[length];
loop (i32 i = 0..length)
copy[i] = items[start + i];
return copy;
}
/// Copies the elements into `target` (at least as long).
CopyTo(Span<T> target)
{
if (target.length < length)
OutOfRange();
if (length > 0)
Array.Copy(items, start, target.items, target.start, length);
}
/// Every element set to `value`.
Fill(T value)
{
loop (i32 i = start..start + length)
items[i] = value;
}
Iterator() : SpanIterator<T> => new SpanIterator<T>(this);
i32 Length
{
get => length;
}
bool IsEmpty
{
get => length == 0;
}
/// The array under the view and where the view starts in it (for code that works on arrays).
T[] Items
{
get => items;
}
i32 Start
{
get => start;
}
}
}