static class · System
Spans
public static class Spans
What spans of comparable, equatable and number elements can do.
- Kind
- static class
- Namespace
- System
- Assembly
- System.Core
- Access
- public, static, abstract
- Source file
Span.ant
Inheritance
- Base classes
-
AnySpans
Methods
A span of a list's elements (in place: it sees them until the list grows).
Sort<T : IComparable<T>>(Span<T> span)
#
Inherited members (5)
GetTypemethod from AnyUndescribedmethod from AnyToStringmethod from AnyHashmethod from Anydestroymethod from Any
Source
Spans as Antril, decompiled from its Larva HIR.
// System.Spans — System.Core (decompiled from Larva HIR)
into namespace System
{
/// What spans of comparable, equatable and number elements can do.
public static class Spans
{
public:
/// A span of a list's elements (in place: it sees them until the list grows).
Of<T>(List<T> list) : Span<T> => new Span<T>(list.Items(), 0, list.Count);
Sort<T : IComparable<T>>(Span<T> span)
{
if (span.Length > 1)
Array.Sort(span.Items, span.Start, span.Length);
}
IndexOf<T : IHashable<T>>(Span<T> span, T value) : i32
{
loop (i32 i = 0..span.Length)
{
if (span[i].Equals(value))
return i;
}
return -1;
}
Contains<T : IHashable<T>>(Span<T> span, T value) : bool => IndexOf(span, value) >= 0;
SequenceEqual<T : IHashable<T>>(Span<T> a, Span<T> b) : bool
{
if (a.Length != b.Length)
return false;
loop (i32 i = 0..a.Length)
{
if (!a[i].Equals(b[i]))
return false;
}
return true;
}
Sum<T : INumber<T>>(Span<T> span) : T
{
T total = T.Zero;
T[] array = span.Items;
loop (i32 i = span.Start..span.Start + span.Length)
total = total + array[i];
return total;
}
}
}