< Summary

Line coverage
98%
Covered lines: 174
Uncovered lines: 2
Coverable lines: 176
Total lines: 637
Line coverage: 98.8%
Branch coverage
93%
Covered branches: 60
Total branches: 64
Branch coverage: 93.7%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
File 1: .cctor()100%11100%
File 2: .cctor()100%11100%
File 2: .ctor()100%11100%
File 2: .ctor(...)100%44100%
File 2: .ctor(...)87.5%88100%
File 2: .ctor(...)50%22100%
File 2: get_InnerArray()100%11100%
File 2: get_Count()100%11100%
File 2: get_Capacity()100%11100%
File 2: System.Collections.Generic.ICollection<T>.get_IsReadOnly()100%11100%
File 2: get_IsSynchronized()100%11100%
File 2: System.Collections.ICollection.get_SyncRoot()100%22100%
File 2: get_Item(...)100%11100%
File 2: set_Item(...)100%11100%
File 2: get_State()100%11100%
File 2: set_State(...)75%44100%
File 2: System.Collections.Generic.ICollection<T>.Add(...)100%11100%
File 2: Push(...)100%22100%
File 2: PushRange(...)100%44100%
File 2: System.Collections.Generic.ICollection<T>.Remove(...)100%11100%
File 2: Pop()100%22100%
File 2: Clear()100%44100%
File 2: FastClear()100%11100%
File 2: EnsureCapacity(...)100%22100%
File 2: Resize(...)100%44100%
File 2: TrimCapacity()75%44100%
File 2: Peek()100%11100%
File 2: ToString()100%22100%
File 2: AsSpan()100%11100%
File 2: AsReadOnlySpan()100%11100%
File 2: CopyTo(...)100%11100%
File 2: CopyTo(...)100%11100%
File 2: CopyTo(...)100%2281.81%
File 2: CloneTo(...)100%22100%
File 2: Contains(...)100%44100%
File 2: Exists(...)100%44100%
File 2: Find(...)100%44100%
File 2: GetEnumerator()100%11100%
File 2: System.Collections.Generic.IEnumerable<T>.GetEnumerator()100%11100%
File 2: System.Collections.IEnumerable.GetEnumerator()100%11100%
File 2: .ctor(...)100%11100%
File 2: get_Current()100%11100%
File 2: System.Collections.IEnumerator.get_Current()100%11100%
File 2: MoveNext()100%44100%
File 2: Reset()100%11100%
File 2: Dispose()100%11100%

File(s)

/_/src/SwiftCollections/obj/Release/net8.0/MemoryPack.Generator/MemoryPack.Generator.MemoryPackGenerator/SwiftCollections.SwiftStack_T_.MemoryPackFormatter.g.cs

File '/_/src/SwiftCollections/obj/Release/net8.0/MemoryPack.Generator/MemoryPack.Generator.MemoryPackGenerator/SwiftCollections.SwiftStack_T_.MemoryPackFormatter.g.cs' does not exist (any more).

/home/runner/work/SwiftCollections/SwiftCollections/src/SwiftCollections/Collection/SwiftStack.cs

#LineLine coverage
 1using Chronicler;
 2using MemoryPack;
 3using System;
 4using System.Collections;
 5using System.Collections.Generic;
 6using System.Runtime.CompilerServices;
 7using System.Text.Json.Serialization;
 8
 9namespace SwiftCollections;
 10
 11/// <summary>
 12/// Represents a fast, array-based stack (LIFO - Last-In-First-Out) collection of objects.
 13/// <para>
 14/// The <c>SwiftStack&lt;T&gt;</c> class provides O(1) time complexity for <c>Push</c> and <c>Pop</c> operations,
 15/// making it highly efficient for scenarios where performance is critical.
 16/// It minimizes memory allocations by reusing internal arrays and offers methods
 17/// like <c>FastClear</c> to quickly reset the stack without deallocating memory.
 18/// </para>
 19/// <para>
 20/// This implementation is optimized for performance and does not perform versioning checks.
 21/// Modifying the stack during enumeration may result in undefined behavior.
 22/// </para>
 23/// </summary>
 24/// <typeparam name="T">Specifies the type of elements in the stack.</typeparam>
 25[Serializable]
 26[JsonConverter(typeof(StateJsonConverterFactory))]
 27[MemoryPackable]
 28public sealed partial class SwiftStack<T> : IStateBacked<SwiftArrayState<T>>, ISwiftCloneable<T>, IEnumerable<T>, IEnume
 29{
 30    #region Constants
 31
 32    /// <summary>
 33    /// The default initial capacity of the SwiftStack if none is specified.
 34    /// Used to allocate a reasonable starting size to minimize resizing operations.
 35    /// </summary>
 36    public const int DefaultCapacity = 8;
 37
 338    private static readonly T[] _emptyArray = Array.Empty<T>();
 339    private static readonly bool _clearReleasedSlots = RuntimeHelpers.IsReferenceOrContainsReferences<T>();
 40
 41    #endregion
 42
 43    #region Fields
 44
 45    /// <summary>
 46    /// The internal array that stores elements of the SwiftStack. Resized as needed to
 47    /// accommodate additional elements. Not directly exposed outside the stack.
 48    /// </summary>
 49    private T[] _innerArray;
 50
 51    /// <summary>
 52    /// The current number of elements in the SwiftStack. Represents the total count of
 53    /// valid elements stored in the stack, also indicating the arrayIndex of the next insertion point.
 54    /// </summary>
 55    private int _count;
 56
 57    [NonSerialized]
 58    private uint _version;
 59
 60    [NonSerialized]
 61    private object? _syncRoot;
 62
 63    #endregion
 64
 65    #region Constructors
 66
 67    /// <summary>
 68    /// Initializes a new, empty instance of SwiftStack.
 69    /// </summary>
 9470    public SwiftStack() : this(0) { }
 71
 72    /// <summary>
 73    /// Initializes a new, empty instance of SwiftStack with the specified initial capacity.
 74    /// </summary>
 5275    public SwiftStack(int capacity)
 76    {
 5277        if (capacity == 0)
 4778            _innerArray = _emptyArray;
 79        else
 80        {
 581            capacity = capacity <= DefaultCapacity ? DefaultCapacity : SwiftHashTools.NextPowerOfTwo(capacity);
 582            _innerArray = new T[capacity];
 83        }
 584    }
 85
 86    /// <summary>
 87    /// Initializes a new instance of the <see cref="SwiftStack{T}"/> class that contains elements copied from the speci
 88    /// </summary>
 89    /// <remarks>
 90    /// The elements are copied onto the stack in the order they are returned by the enumerator of the collection,
 91    /// so that the last element in the collection becomes the top of the stack.
 92    /// </remarks>
 93    /// <param name="items">The collection whose elements are copied to the new stack. Cannot be null.</param>
 394    public SwiftStack(IEnumerable<T> items)
 95    {
 396        SwiftThrowHelper.ThrowIfNull(items, nameof(items));
 97
 398        if (items is ICollection<T> collection)
 99        {
 2100            int count = collection.Count;
 2101            if (count == 0)
 1102                _innerArray = _emptyArray;
 103            else
 104            {
 1105                int capacity = SwiftHashTools.NextPowerOfTwo(count <= DefaultCapacity ? DefaultCapacity : count);
 1106                _innerArray = new T[capacity];
 1107                collection.CopyTo(_innerArray, 0);
 1108                _count = count;
 109            }
 110        }
 111        else
 112        {
 1113            _innerArray = new T[DefaultCapacity];
 8114            foreach (T item in items)
 3115                Push(item);
 116        }
 1117    }
 118
 119    ///  <summary>
 120    ///  Initializes a new instance of the <see cref="SwiftStack{T}"/> class with the specified <see cref="SwiftArraySta
 121    ///  </summary>
 122    ///  <param name="state">The state containing the internal array, count, offset, and version for initialization.</pa
 123    [MemoryPackConstructor]
 3124    public SwiftStack(SwiftArrayState<T> state)
 125    {
 3126        State = state;
 3127        _innerArray ??= _emptyArray; // Ensure _innerArray is not null after deserialization
 3128    }
 129
 130    #endregion
 131
 132    #region Properties
 133
 134    /// <inheritdoc cref="_innerArray"/>
 135    [JsonIgnore]
 136    [MemoryPackIgnore]
 3137    public T[] InnerArray => _innerArray;
 138
 139    /// <inheritdoc cref="_count"/>
 140    [JsonIgnore]
 141    [MemoryPackIgnore]
 120142    public int Count => _count;
 143
 144    /// <summary>
 145    /// Gets the total number of elements the SwiftQueue can hold without resizing.
 146    /// Reflects the current allocated size of the internal array.
 147    /// </summary>
 148    [JsonIgnore]
 149    [MemoryPackIgnore]
 12150    public int Capacity => _innerArray.Length;
 151
 152    [JsonIgnore]
 153    [MemoryPackIgnore]
 1154    bool ICollection<T>.IsReadOnly => false;
 155
 156    /// <inheritdoc/>
 157    [JsonIgnore]
 158    [MemoryPackIgnore]
 1159    public bool IsSynchronized => false;
 160
 161    [JsonIgnore]
 162    [MemoryPackIgnore]
 1163    object ICollection.SyncRoot => _syncRoot ??= new object();
 164
 165    /// <summary>
 166    /// Gets the element at the specified arrayIndex.
 167    /// </summary>
 168    [JsonIgnore]
 169    [MemoryPackIgnore]
 170    public T this[int index]
 171    {
 172        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 173        get
 174        {
 205175            SwiftThrowHelper.ThrowIfListIndexInvalid(index, _count);
 203176            return _innerArray[index];
 177        }
 178        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 179        set
 180        {
 2181            SwiftThrowHelper.ThrowIfListIndexInvalid(index, _count);
 1182            _innerArray[index] = value;
 1183        }
 184    }
 185
 186    /// <summary>
 187    /// Gets or sets the current state of the array, including its items and count.
 188    /// </summary>
 189    /// <remarks>
 190    /// Setting this property replaces the entire contents of the array with the items from the specified state.
 191    /// The setter is intended for internal use and may reset the array's version and capacity.
 192    /// </remarks>
 193    [JsonInclude]
 194    [MemoryPackInclude]
 195    public SwiftArrayState<T> State
 196    {
 197        get
 198        {
 2199            var items = new T[_count];
 2200            Array.Copy(_innerArray, 0, items, 0, _count);
 2201            return new SwiftArrayState<T>(items);
 202        }
 203        internal set
 204        {
 3205            SwiftThrowHelper.ThrowIfNull(value.Items, nameof(value.Items));
 206
 3207            int count = value.Items.Length;
 208
 3209            if (count == 0)
 210            {
 1211                _innerArray = _emptyArray;
 1212                _count = 0;
 1213                _version = 0;
 1214                return;
 215            }
 216
 2217            int capacity = SwiftHashTools.NextPowerOfTwo(count <= DefaultCapacity ? DefaultCapacity : count);
 218
 2219            _innerArray = new T[capacity];
 2220            Array.Copy(value.Items, 0, _innerArray, 0, count);
 221
 2222            _count = count;
 2223            _version = 0;
 2224        }
 225    }
 226
 227    #endregion
 228
 229    #region Collection Manipulation
 230
 231    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 2232    void ICollection<T>.Add(T item) => Push(item);
 233
 234    /// <summary>
 235    /// Inserts an object at the top of the SwiftStack.
 236    /// </summary>
 237    /// <param name="item"></param>
 238    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 239    public void Push(T item)
 240    {
 279241        if ((uint)_count == (uint)_innerArray.Length)
 41242            Resize(_innerArray.Length * 2);
 279243        _innerArray[_count++] = item;
 279244        _version++;
 279245    }
 246
 247    /// <summary>
 248    /// Pushes the elements of the specified span onto the stack in order.
 249    /// </summary>
 250    /// <param name="items">The span whose elements should be pushed.</param>
 251    public void PushRange(ReadOnlySpan<T> items)
 252    {
 6253        if (items.Length == 0)
 1254            return;
 255
 5256        if (_count + items.Length > _innerArray.Length)
 257        {
 4258            int newCapacity = SwiftHashTools.NextPowerOfTwo(_count + items.Length);
 4259            Resize(newCapacity);
 260        }
 261
 5262        items.CopyTo(_innerArray.AsSpan(_count, items.Length));
 5263        _count += items.Length;
 5264        _version++;
 5265    }
 266
 267    bool ICollection<T>.Remove(T item)
 268    {
 1269        throw new NotSupportedException("Remove is not supported on Stack.");
 270    }
 271
 272    /// <summary>
 273    /// Removes and returns the object at the top of the SwiftStack.
 274    /// </summary>
 275    /// <returns></returns>
 276    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 277    public T Pop()
 278    {
 3279        SwiftThrowHelper.ThrowIfTrue((uint)_count == 0, message: "Stack is empty.");
 2280        T item = _innerArray[--_count];
 2281        if (_clearReleasedSlots)
 1282            _innerArray[_count] = default!;
 2283        _version++;
 2284        return item;
 285    }
 286
 287    /// <summary>
 288    /// Removes all elements from the SwiftStack, resetting its count to zero.
 289    /// </summary>
 290    public void Clear()
 291    {
 6292        if (_count == 0) return;
 4293        if (_clearReleasedSlots)
 1294            Array.Clear(_innerArray, 0, _count);
 4295        _count = 0;
 4296        _version++;
 4297    }
 298
 299    /// <summary>
 300    /// Clears the SwiftStack without releasing the reference to the stored elements.
 301    /// Use FastClear() when you want to quickly reset the list without reallocating memory.
 302    /// </summary>
 303    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 304    public void FastClear()
 305    {
 1306        _count = 0;
 1307        _version++;
 1308    }
 309
 310    #endregion
 311
 312    #region Capacity Management
 313
 314    /// <summary>
 315    /// Ensures that the internal storage has at least the specified capacity, resizing if necessary.
 316    /// </summary>
 317    /// <remarks>
 318    /// If the current capacity is less than the specified value, the internal storage is increased to
 319    /// the next power of two greater than or equal to <paramref name="capacity"/>.
 320    /// No action is taken if the current capacity is sufficient.
 321    /// </remarks>
 322    /// <param name="capacity">The minimum number of elements that the internal storage should be able to hold. Must be 
 323    public void EnsureCapacity(int capacity)
 324    {
 1325        capacity = SwiftHashTools.NextPowerOfTwo(capacity);
 1326        if (capacity > _innerArray.Length)
 1327            Resize(capacity);
 1328    }
 329
 330    /// <summary>
 331    /// Ensures that the capacity of the stack is sufficient to accommodate the specified number of elements.
 332    /// The stack capacity can increase by double to balance memory allocation efficiency and space.
 333    /// </summary>
 334    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 335    private void Resize(int newSize)
 336    {
 46337        int newCapacity = newSize <= DefaultCapacity ? DefaultCapacity : newSize;
 46338        T[] newArray = new T[newCapacity];
 46339        if ((uint)_count > 0)
 8340            Array.Copy(_innerArray, 0, newArray, 0, _count);
 46341        _innerArray = newArray;
 46342        _version++;
 46343    }
 344
 345
 346    /// <summary>
 347    /// Sets the capacity of a <see cref="SwiftStack{T}"/> to the actual
 348    /// number of elements it contains, rounded up to a nearby next power of 2 value.
 349    /// </summary>
 350    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 351    public void TrimCapacity()
 352    {
 2353        int newCapacity = _count <= DefaultCapacity ? DefaultCapacity : SwiftHashTools.NextPowerOfTwo(_count);
 2354        T[] newArray = new T[newCapacity];
 2355        if ((uint)_count > 0)
 1356            Array.Copy(_innerArray, 0, newArray, 0, _count);
 2357        _innerArray = newArray;
 2358        _version++;
 2359    }
 360
 361    #endregion
 362
 363    #region Utility Methods
 364
 365    /// <summary>
 366    /// Returns the object at the top of the SwiftStack without removing it.
 367    /// </summary>
 368    /// <returns></returns>
 369    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 370    public T Peek()
 371    {
 7372        SwiftThrowHelper.ThrowIfTrue((uint)_count == 0, message: "Stack is empty.");
 6373        return _innerArray[_count - 1];
 374    }
 375
 376    /// <summary>
 377    /// Returns a string that represents the current stack, including its type and the number of elements it contains.
 378    /// </summary>
 379    /// <returns>
 380    /// A string containing the type name and the current element count if the stack is not empty;
 381    /// otherwise, a string indicating that the stack is empty.
 382    /// </returns>
 383    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 2384    public override string ToString() => (uint)_count == 0 ? $"{typeof(SwiftStack<T>)}: Empty" : $"{typeof(SwiftStack<T>
 385
 386    /// <summary>
 387    /// Returns a mutable span over the populated portion of the stack.
 388    /// </summary>
 389    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 2390    public Span<T> AsSpan() => _innerArray.AsSpan(0, _count);
 391
 392    /// <summary>
 393    /// Returns a read-only span over the populated portion of the stack.
 394    /// </summary>
 395    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 4396    public ReadOnlySpan<T> AsReadOnlySpan() => _innerArray.AsSpan(0, _count);
 397
 398    /// <summary>
 399    /// Copies the elements of the collection to the specified array, starting at the specified array index.
 400    /// </summary>
 401    /// <param name="array">
 402    /// The one-dimensional array that is the destination of the elements copied from the collection.
 403    /// The array must have zero-based indexing.</param>
 404    /// <param name="arrayIndex">The zero-based index in the destination array at which copying begins.</param>
 405    /// <exception cref="ArgumentOutOfRangeException">
 406    /// Thrown when <paramref name="arrayIndex"/> is less than 0 or greater than the length of <paramref name="array"/>.
 407    /// </exception>
 408    /// <exception cref="ArgumentException">
 409    /// Thrown when the number of elements in the source collection is greater than
 410    /// the available space from <paramref name="arrayIndex"/> to the end of <paramref name="array"/>.
 411    /// </exception>
 412    public void CopyTo(T[] array, int arrayIndex)
 413    {
 4414        SwiftThrowHelper.ThrowIfNull(array, nameof(array));
 3415        SwiftThrowHelper.ThrowIfArrayIndexInvalid(arrayIndex, array.Length);
 2416        SwiftThrowHelper.ThrowIfArgument((uint)(array.Length - arrayIndex) < (uint)_count, nameof(array), "Destination a
 417
 1418        Array.Copy(_innerArray, 0, array, arrayIndex, _count);
 1419    }
 420
 421    /// <summary>
 422    /// Copies the populated elements of the SwiftStack into the specified destination span.
 423    /// </summary>
 424    /// <param name="destination">The destination span.</param>
 425    public void CopyTo(Span<T> destination)
 426    {
 2427        SwiftThrowHelper.ThrowIfArgument(destination.Length < _count, nameof(destination), "Destination span is not long
 428
 1429        AsSpan().CopyTo(destination);
 1430    }
 431
 432    /// <inheritdoc/>
 433    public void CopyTo(Array array, int arrayIndex)
 434    {
 3435        SwiftThrowHelper.ThrowIfNull(array, nameof(array));
 3436        SwiftThrowHelper.ThrowIfArgument(array.Rank != 1, nameof(array), "Array must be single dimensional.");
 2437        SwiftThrowHelper.ThrowIfArgument(array.GetLowerBound(0) != 0, nameof(array), "Array must have zero-based indexin
 1438        SwiftThrowHelper.ThrowIfArrayIndexInvalid(arrayIndex, array.Length);
 1439        SwiftThrowHelper.ThrowIfArgument((uint)(array.Length - arrayIndex) < (uint)_count, nameof(array), "Destination a
 440
 441        try
 442        {
 8443            for (int i = 0; (uint)i < (uint)_count; i++)
 3444                array.SetValue(_innerArray[i], arrayIndex++);
 1445        }
 0446        catch (ArrayTypeMismatchException)
 447        {
 0448            throw new ArgumentException("Invalid array type.");
 449        }
 1450    }
 451
 452    /// <inheritdoc/>
 453    public void CloneTo(ICollection<T> output)
 454    {
 1455        output.Clear();
 6456        for (int i = 0; (uint)i < (uint)_count; i++)
 2457            output.Add(_innerArray[i]);
 1458    }
 459
 460    /// <inheritdoc/>
 461    public bool Contains(T item)
 462    {
 2463        EqualityComparer<T> comparer = EqualityComparer<T>.Default;
 10464        for (int i = 0; i < _count; i++)
 465        {
 4466            if (comparer.Equals(_innerArray[i], item))
 1467                return true;
 468        }
 1469        return false;
 470    }
 471
 472    /// <summary>
 473    /// Determines whether the <see cref="SwiftStack{T}"/> contains an element that matches the conditions defined by th
 474    /// </summary>
 475    /// <param name="match">The predicate that defines the conditions of the element to search for.</param>
 476    /// <returns><c>true</c> if the <see cref="SwiftStack{T}"/> contains one or more elements that match the specified p
 477    public bool Exists(Predicate<T> match)
 478    {
 3479        SwiftThrowHelper.ThrowIfNull(match, nameof(match));
 480
 12481        for (int i = _count - 1; i >= 0; i--)
 482        {
 5483            if (match(_innerArray[i]))
 1484                return true;
 485        }
 486
 1487        return false;
 488    }
 489
 490    /// <summary>
 491    /// Searches for an element that matches the conditions defined by the specified predicate, and returns the first ma
 492    /// </summary>
 493    /// <param name="match">The predicate that defines the conditions of the element to search for.</param>
 494    /// <returns>The first element that matches the conditions defined by the specified predicate, if found; otherwise, 
 495    public T Find(Predicate<T> match)
 496    {
 2497        SwiftThrowHelper.ThrowIfNull(match, nameof(match));
 498
 8499        for (int i = _count - 1; i >= 0; i--)
 500        {
 3501            if (match(_innerArray[i]))
 1502                return _innerArray[i];
 503        }
 504
 1505        return default!;
 506    }
 507
 508    #endregion
 509
 510    #region Enumerators
 511
 512    /// <inheritdoc cref="IEnumerable.GetEnumerator()"/>
 20513    public SwiftStackEnumerator GetEnumerator() => new(this);
 9514    IEnumerator<T> IEnumerable<T>.GetEnumerator() => GetEnumerator();
 3515    IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
 516
 517    /// <summary>
 518    /// Supports simple iteration over the elements of a <see cref="SwiftStack{T}"/> in last-in, first-out (LIFO) order.
 519    /// </summary>
 520    /// <remarks>
 521    /// The enumerator is invalidated if the collection is modified after the enumerator is created.
 522    /// This type is not thread-safe.
 523    /// </remarks>
 524    public struct SwiftStackEnumerator : IEnumerator<T>, IEnumerator, IDisposable
 525    {
 526        private readonly SwiftStack<T> _stack;
 527        private readonly T[] _array;
 528        private readonly uint _version;
 529        private readonly int _count;
 530        private int _index;
 531
 532        private T _current;
 533
 534        internal SwiftStackEnumerator(SwiftStack<T> stack)
 535        {
 20536            _stack = stack;
 20537            _array = stack._innerArray;
 20538            _count = stack._count;
 20539            _version = stack._version;
 20540            _index = -2; // Enumerator not started
 20541            _current = default!;
 20542        }
 543
 544        /// <inheritdoc/>
 430545        public T Current => _current;
 546
 547        object IEnumerator.Current
 548        {
 549            get
 550            {
 2551                SwiftThrowHelper.ThrowIfTrue((uint)_index > _count, message: "Bad enumeration");
 1552                return _current!;
 553            }
 554        }
 555
 556        /// <inheritdoc/>
 557        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 558        public bool MoveNext()
 559        {
 251560            SwiftThrowHelper.ThrowIfTrue(_version != _stack._version, message: "Enumerator modified outside of enumerati
 561
 250562            if (_index == -2)
 563            {
 22564                _index = _count - 1;
 565            }
 566            else
 567            {
 228568                _index--;
 569            }
 570
 250571            if (_index >= 0)
 572            {
 232573                _current = _array[_index];
 232574                return true;
 575            }
 576
 18577            _index = -1;
 18578            _current = default!;
 18579            return false;
 580        }
 581
 582        /// <inheritdoc/>
 583        public void Reset()
 584        {
 4585            SwiftThrowHelper.ThrowIfTrue(_version != _stack._version, message: "Enumerator modified outside of enumerati
 586
 3587            _index = -2;
 3588            _current = default!;
 3589        }
 590
 591        /// <inheritdoc/>
 11592        public void Dispose() => _index = -1;
 593    }
 594
 595    #endregion
 596}