static class · System

Spans

public static class Spans

What spans of comparable, equatable and number elements can do.

Tipo
static class
Espacio de nombres
System
Ensamblado
System.Core
Acceso
public, static, abstract
Archivo fuente
Span.ant

Herencia

Clases base
Any Spans

Métodos

Of<T>(List<T> list) : Span<T>
#

static

A span of a list's elements (in place: it sees them until the list grows).

Sort<T : IComparable<T>>(Span<T> span)
#

static

IndexOf<T : IHashable<T>>(Span<T> span, T value) : i32
#

static

Contains<T : IHashable<T>>(Span<T> span, T value) : bool
#

static

SequenceEqual<T : IHashable<T>>(Span<T> a, Span<T> b) : bool
#

static

Sum<T : INumber<T>>(Span<T> span) : T
#

static

Miembros heredados (5)

Código fuente

Spans en Antril, descompilado a partir de su Larva HIR.

System.Spans.ant
// 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;
			}
	}
}
Esc