IVersionedLongList<T> interface & RecyclableLongList.GetVersionedEnumerator added for use with foreach.

This commit is contained in:
mlemanczyk committed 2023-06-24 23:55:01 +02:00
1 parent 49c0615a62
commit 9aab9e9f6f
3 files changed
+14 -4

No files matched your search

@@ -0,0 +1,7 @@
namespace Recyclable.Collections
{
public interface IVersionedLongList<T> : IEnumerable<T>
{
new RecyclableLongList<T>.VersionedEnumerator GetEnumerator();
}
}
@@ -3,8 +3,12 @@ using System.Diagnostics.Contracts;
namespace Recyclable.Collections
{
public partial class RecyclableLongList<T>
public partial class RecyclableLongList<T> : IVersionedLongList<T>
{
public VersionedEnumerator GetVersionedEnumerator() => new(this);
VersionedEnumerator IVersionedLongList<T>.GetEnumerator() => new(this);
public struct VersionedEnumerator : IEnumerator<T>
{
#nullable disable
@@ -26,13 +30,13 @@ namespace Recyclable.Collections
public bool MoveNext()
{
if (_enumeratorVersion != _list._version)
var list = _list;
if (_enumeratorVersion != list._version)
{
throw new InvalidOperationException();
}
Contract.EndContractBlock();
var list = _list;
if (_currentBlockIndex < list._lastBlockWithData)
{
@@ -1109,7 +1109,6 @@ namespace Recyclable.Collections
public Enumerator GetEnumerator() => new(this);
IEnumerator IEnumerable.GetEnumerator() => new Enumerator(this);
IEnumerator<T> IEnumerable<T>.GetEnumerator() => new Enumerator(this);
public VersionedEnumerator GetVersionedEnumerator() => new(this);
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public int IndexOf(T item)