//// //#pragma warning disable //#nullable enable annotations // //// Licensed to the .NET Foundation under one or more agreements. //// The .NET Foundation licenses this file to you under the MIT license. // //namespace System //{ // /// Represent a range has start and end indexes. // /// // /// Range is used by the C# compiler to support the range syntax. // /// // /// int[] someArray = new int[5] { 1, 2, 3, 4, 5 }; // /// int[] subArray1 = someArray[0..2]; // { 1, 2 } // /// int[] subArray2 = someArray[1..^0]; // { 2, 3, 4, 5 } // /// // /// // [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] // public readonly struct Range : global::System.IEquatable // { // /// Represent the inclusive start index of the Range. // public global::System.Index Start { get; } // // /// Represent the exclusive end index of the Range. // public global::System.Index End { get; } // // /// Construct a Range object using the start and end indexes. // /// Represent the inclusive start index of the range. // /// Represent the exclusive end index of the range. // public Range(global::System.Index start, global::System.Index end) // { // Start = start; // End = end; // } // // /// Indicates whether the current Range object is equal to another object of the same type. // /// An object to compare with this object // public override bool Equals([global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] object? value) => // value is global::System.Range r && // r.Start.Equals(Start) && // r.End.Equals(End); // // /// Indicates whether the current Range object is equal to another Range object. // /// An object to compare with this object // public bool Equals(global::System.Range other) => other.Start.Equals(Start) && other.End.Equals(End); // // /// Returns the hash code for this instance. // public override int GetHashCode() // { // return global::System.Range.HashHelpers.Combine(Start.GetHashCode(), End.GetHashCode()); // } // // /// Converts the value of the current Range object to its equivalent string representation. // public override string ToString() // { // return Start.ToString() + ".." + End.ToString(); // } // // /// Create a Range object starting from start index to the end of the collection. // public static global::System.Range StartAt(global::System.Index start) => new global::System.Range(start, global::System.Index.End); // // /// Create a Range object starting from first element in the collection to the end Index. // public static global::System.Range EndAt(global::System.Index end) => new global::System.Range(global::System.Index.Start, end); // // /// Create a Range object starting from first element to the end. // public static global::System.Range All => new global::System.Range(global::System.Index.Start, global::System.Index.End); // // /// Calculate the start offset and length of range object using a collection length. // /// The length of the collection that the range will be used with. length has to be a positive value. // /// // /// For performance reason, we don't validate the input length parameter against negative values. // /// It is expected Range will be used with collections which always have non negative length/count. // /// We validate the range is inside the length scope though. // /// // [global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] // public (int Offset, int Length) GetOffsetAndLength(int length) // { // int start; // global::System.Index startIndex = Start; // if (startIndex.IsFromEnd) // start = length - startIndex.Value; // else // start = startIndex.Value; // // int end; // global::System.Index endIndex = End; // if (endIndex.IsFromEnd) // end = length - endIndex.Value; // else // end = endIndex.Value; // // if ((uint)end > (uint)length || (uint)start > (uint)end) // { // global::System.Range.ThrowHelper.ThrowArgumentOutOfRangeException(); // } // // return (start, end - start); // } // // private static class HashHelpers // { // public static int Combine(int h1, int h2) // { // uint rol5 = ((uint)h1 << 5) | ((uint)h1 >> 27); // return ((int)rol5 + h1) ^ h2; // } // } // // private static class ThrowHelper // { // [global::System.Diagnostics.CodeAnalysis.DoesNotReturn] // public static void ThrowArgumentOutOfRangeException() // { // throw new global::System.ArgumentOutOfRangeException("length"); // } // } // } //}