Implement versioned enumerator retrieval
This commit is contained in:
1 parent
ed23fd7f69
commit
c2affa4ad7
10 files changed
+133
-19
No files matched your search
@@ -7,6 +7,7 @@ namespace Recyclable.Collections
|
|||||||
public partial class RecyclableList<T>
|
public partial class RecyclableList<T>
|
||||||
{
|
{
|
||||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||||
|
[VersionedCollectionsGenerator.CloneForVersioned]
|
||||||
public struct Enumerator : IEnumerator<T>
|
public struct Enumerator : IEnumerator<T>
|
||||||
{
|
{
|
||||||
private static readonly bool _isReferenceType = !typeof(T).IsValueType;
|
private static readonly bool _isReferenceType = !typeof(T).IsValueType;
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using System.Runtime.CompilerServices;
|
|||||||
|
|
||||||
namespace Recyclable.Collections
|
namespace Recyclable.Collections
|
||||||
{
|
{
|
||||||
|
[VersionedCollectionsGenerator.GenerateVersioned]
|
||||||
public static class RecyclableListExtensions
|
public static class RecyclableListExtensions
|
||||||
{
|
{
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
|||||||
@@ -6,9 +6,11 @@ namespace Recyclable.Collections
|
|||||||
{
|
{
|
||||||
public partial class RecyclableList<T> : IRecyclableVersionedList<T>
|
public partial class RecyclableList<T> : IRecyclableVersionedList<T>
|
||||||
{
|
{
|
||||||
|
[VersionedCollectionsGenerator.CloneForVersioned]
|
||||||
VersionedEnumerator IRecyclableVersionedList<T>.GetEnumerator() => new(this);
|
VersionedEnumerator IRecyclableVersionedList<T>.GetEnumerator() => new(this);
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||||
|
[VersionedCollectionsGenerator.CloneForVersioned]
|
||||||
public struct VersionedEnumerator : IEnumerator<T>
|
public struct VersionedEnumerator : IEnumerator<T>
|
||||||
{
|
{
|
||||||
private int _currentItemIndex;
|
private int _currentItemIndex;
|
||||||
|
|||||||
@@ -364,13 +364,28 @@ namespace Recyclable.Collections
|
|||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
[VersionedCollectionsGenerator.CloneForVersioned]
|
||||||
|
#if WITH_VERSIONING
|
||||||
|
public VersionedEnumerator GetEnumerator() => new(this);
|
||||||
|
#else
|
||||||
public Enumerator GetEnumerator() => new(this);
|
public Enumerator GetEnumerator() => new(this);
|
||||||
|
#endif
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
[VersionedCollectionsGenerator.CloneForVersioned]
|
||||||
|
#if WITH_VERSIONING
|
||||||
|
IEnumerator IEnumerable.GetEnumerator() => new VersionedEnumerator(this);
|
||||||
|
#else
|
||||||
IEnumerator IEnumerable.GetEnumerator() => new Enumerator(this);
|
IEnumerator IEnumerable.GetEnumerator() => new Enumerator(this);
|
||||||
|
#endif
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
[VersionedCollectionsGenerator.CloneForVersioned]
|
||||||
|
#if WITH_VERSIONING
|
||||||
|
IEnumerator<T> IEnumerable<T>.GetEnumerator() => new VersionedEnumerator(this);
|
||||||
|
#else
|
||||||
IEnumerator<T> IEnumerable<T>.GetEnumerator() => new Enumerator(this);
|
IEnumerator<T> IEnumerable<T>.GetEnumerator() => new Enumerator(this);
|
||||||
|
#endif
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -126,7 +126,9 @@ namespace Recyclable.Collections
|
|||||||
}
|
}
|
||||||
|
|
||||||
targetList._capacity = capacity;
|
targetList._capacity = capacity;
|
||||||
targetList._version++;
|
#if WITH_VERSIONING
|
||||||
|
targetList._version++;
|
||||||
|
#endif
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -186,9 +188,12 @@ namespace Recyclable.Collections
|
|||||||
targetList._nextItemBlockIndex = targetBlockIdx;
|
targetList._nextItemBlockIndex = targetBlockIdx;
|
||||||
targetList._nextItemIndex = targetItemIdx;
|
targetList._nextItemIndex = targetItemIdx;
|
||||||
targetList._lastBlockWithData = targetBlockIdx - (targetItemIdx > 0 ? 0 : 1);
|
targetList._lastBlockWithData = targetBlockIdx - (targetItemIdx > 0 ? 0 : 1);
|
||||||
targetList._version++;
|
#if WITH_VERSIONING
|
||||||
|
targetList._version++;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[VersionedCollectionsGenerator.RewriteForVersioned]
|
||||||
public static void AddRange<T>(this RecyclableLongList<T> targetList, in Array items)
|
public static void AddRange<T>(this RecyclableLongList<T> targetList, in Array items)
|
||||||
{
|
{
|
||||||
if (items.LongLength == 0)
|
if (items.LongLength == 0)
|
||||||
@@ -240,7 +245,9 @@ namespace Recyclable.Collections
|
|||||||
}
|
}
|
||||||
|
|
||||||
targetList._longCount = targetCapacity;
|
targetList._longCount = targetCapacity;
|
||||||
targetList._version++;
|
#if WITH_VERSIONING
|
||||||
|
targetList._version++;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void AddRange<T>(this RecyclableLongList<T> targetList, ICollection items)
|
public static void AddRange<T>(this RecyclableLongList<T> targetList, ICollection items)
|
||||||
@@ -305,7 +312,9 @@ namespace Recyclable.Collections
|
|||||||
RecyclableArrayPool<T>.ReturnShared(itemsBuffer, RecyclableLongList<T>._needsClearing);
|
RecyclableArrayPool<T>.ReturnShared(itemsBuffer, RecyclableLongList<T>._needsClearing);
|
||||||
}
|
}
|
||||||
|
|
||||||
targetList._version++;
|
#if WITH_VERSIONING
|
||||||
|
targetList._version++;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void AddRange<T>(this RecyclableLongList<T> targetList, ICollection<T> items)
|
public static void AddRange<T>(this RecyclableLongList<T> targetList, ICollection<T> items)
|
||||||
@@ -373,7 +382,9 @@ namespace Recyclable.Collections
|
|||||||
RecyclableArrayPool<T>.ReturnShared(itemsBuffer, RecyclableLongList<T>._needsClearing);
|
RecyclableArrayPool<T>.ReturnShared(itemsBuffer, RecyclableLongList<T>._needsClearing);
|
||||||
}
|
}
|
||||||
|
|
||||||
targetList._version++;
|
#if WITH_VERSIONING
|
||||||
|
targetList._version++;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void AddRange<T>(this RecyclableLongList<T> targetList, IEnumerable source)
|
public static void AddRange<T>(this RecyclableLongList<T> targetList, IEnumerable source)
|
||||||
@@ -616,7 +627,9 @@ namespace Recyclable.Collections
|
|||||||
targetList._nextItemBlockIndex = targetBlockIndex;
|
targetList._nextItemBlockIndex = targetBlockIndex;
|
||||||
targetList._longCount = targetCapacity;
|
targetList._longCount = targetCapacity;
|
||||||
targetList._lastBlockWithData = targetBlockIndex - (targetList._nextItemIndex > 0 ? 0 : 1);
|
targetList._lastBlockWithData = targetBlockIndex - (targetList._nextItemIndex > 0 ? 0 : 1);
|
||||||
targetList._version++;
|
#if WITH_VERSIONING
|
||||||
|
targetList._version++;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void AddRange<T>(this RecyclableLongList<T> targetList, ReadOnlySpan<T> items)
|
public static void AddRange<T>(this RecyclableLongList<T> targetList, ReadOnlySpan<T> items)
|
||||||
@@ -671,7 +684,9 @@ namespace Recyclable.Collections
|
|||||||
|
|
||||||
targetList._longCount = targetCapacity;
|
targetList._longCount = targetCapacity;
|
||||||
targetList._lastBlockWithData = targetBlockIndex;
|
targetList._lastBlockWithData = targetBlockIndex;
|
||||||
targetList._version++;
|
#if WITH_VERSIONING
|
||||||
|
targetList._version++;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void AddRange<T>(this RecyclableLongList<T> targetList, RecyclableList<T> items)
|
public static void AddRange<T>(this RecyclableLongList<T> targetList, RecyclableList<T> items)
|
||||||
@@ -728,7 +743,9 @@ namespace Recyclable.Collections
|
|||||||
}
|
}
|
||||||
|
|
||||||
targetList._longCount = targetCapacity;
|
targetList._longCount = targetCapacity;
|
||||||
targetList._version++;
|
#if WITH_VERSIONING
|
||||||
|
targetList._version++;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void AddRange<T>(this RecyclableLongList<T> targetList, RecyclableLongList<T> items)
|
public static void AddRange<T>(this RecyclableLongList<T> targetList, RecyclableLongList<T> items)
|
||||||
@@ -801,7 +818,9 @@ namespace Recyclable.Collections
|
|||||||
}
|
}
|
||||||
|
|
||||||
targetList._longCount = targetCapacity;
|
targetList._longCount = targetCapacity;
|
||||||
targetList._version++;
|
#if WITH_VERSIONING
|
||||||
|
targetList._version++;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void AddRange<T>(this RecyclableLongList<T> targetList, Span<T> items)
|
public static void AddRange<T>(this RecyclableLongList<T> targetList, Span<T> items)
|
||||||
@@ -856,7 +875,9 @@ namespace Recyclable.Collections
|
|||||||
|
|
||||||
targetList._longCount = targetCapacity;
|
targetList._longCount = targetCapacity;
|
||||||
targetList._lastBlockWithData = targetBlockIndex;
|
targetList._lastBlockWithData = targetBlockIndex;
|
||||||
targetList._version++;
|
#if WITH_VERSIONING
|
||||||
|
targetList._version++;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void AddRange<T>(this RecyclableLongList<T> targetList, in T[] items)
|
public static void AddRange<T>(this RecyclableLongList<T> targetList, in T[] items)
|
||||||
@@ -912,7 +933,9 @@ namespace Recyclable.Collections
|
|||||||
|
|
||||||
targetList._longCount = targetCapacity;
|
targetList._longCount = targetCapacity;
|
||||||
targetList._lastBlockWithData = targetBlockIndex;
|
targetList._lastBlockWithData = targetBlockIndex;
|
||||||
targetList._version++;
|
#if WITH_VERSIONING
|
||||||
|
targetList._version++;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
|
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
|
||||||
@@ -954,7 +977,9 @@ namespace Recyclable.Collections
|
|||||||
targetList._nextItemBlockIndex = blockIndex;
|
targetList._nextItemBlockIndex = blockIndex;
|
||||||
targetList._nextItemIndex = itemIndex;
|
targetList._nextItemIndex = itemIndex;
|
||||||
targetList._lastBlockWithData = blockIndex - (itemIndex > 0 ? 0 : 1);
|
targetList._lastBlockWithData = blockIndex - (itemIndex > 0 ? 0 : 1);
|
||||||
targetList._version++;
|
#if WITH_VERSIONING
|
||||||
|
targetList._version++;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
|
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
|
||||||
@@ -999,7 +1024,9 @@ namespace Recyclable.Collections
|
|||||||
targetList._nextItemBlockIndex = blockIndex;
|
targetList._nextItemBlockIndex = blockIndex;
|
||||||
targetList._nextItemIndex = itemIndex;
|
targetList._nextItemIndex = itemIndex;
|
||||||
targetList._lastBlockWithData = blockIndex - (itemIndex > 0 ? 0 : 1);
|
targetList._lastBlockWithData = blockIndex - (itemIndex > 0 ? 0 : 1);
|
||||||
targetList._version++;
|
#if WITH_VERSIONING
|
||||||
|
targetList._version++;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
|
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
|
||||||
@@ -1038,7 +1065,9 @@ namespace Recyclable.Collections
|
|||||||
targetList._nextItemBlockIndex = blockIndex;
|
targetList._nextItemBlockIndex = blockIndex;
|
||||||
targetList._nextItemIndex = itemIndex;
|
targetList._nextItemIndex = itemIndex;
|
||||||
targetList._lastBlockWithData = blockIndex - (itemIndex > 0 ? 0 : 1);
|
targetList._lastBlockWithData = blockIndex - (itemIndex > 0 ? 0 : 1);
|
||||||
targetList._version++;
|
#if WITH_VERSIONING
|
||||||
|
targetList._version++;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
|
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
|
||||||
@@ -1082,7 +1111,9 @@ namespace Recyclable.Collections
|
|||||||
targetList._nextItemBlockIndex = blockIndex;
|
targetList._nextItemBlockIndex = blockIndex;
|
||||||
targetList._nextItemIndex = itemIndex;
|
targetList._nextItemIndex = itemIndex;
|
||||||
targetList._lastBlockWithData = blockIndex - (itemIndex > 0 ? 0 : 1);
|
targetList._lastBlockWithData = blockIndex - (itemIndex > 0 ? 0 : 1);
|
||||||
targetList._version++;
|
#if WITH_VERSIONING
|
||||||
|
targetList._version++;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
|
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
|
||||||
@@ -1121,7 +1152,9 @@ namespace Recyclable.Collections
|
|||||||
targetList._nextItemBlockIndex = blockIndex;
|
targetList._nextItemBlockIndex = blockIndex;
|
||||||
targetList._nextItemIndex = itemIndex;
|
targetList._nextItemIndex = itemIndex;
|
||||||
targetList._lastBlockWithData = blockIndex - (itemIndex > 0 ? 0 : 1);
|
targetList._lastBlockWithData = blockIndex - (itemIndex > 0 ? 0 : 1);
|
||||||
targetList._version++;
|
#if WITH_VERSIONING
|
||||||
|
targetList._version++;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
|
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
|
||||||
@@ -1165,7 +1198,9 @@ namespace Recyclable.Collections
|
|||||||
targetList._nextItemBlockIndex = blockIndex;
|
targetList._nextItemBlockIndex = blockIndex;
|
||||||
targetList._nextItemIndex = itemIndex;
|
targetList._nextItemIndex = itemIndex;
|
||||||
targetList._lastBlockWithData = blockIndex - (itemIndex > 0 ? 0 : 1);
|
targetList._lastBlockWithData = blockIndex - (itemIndex > 0 ? 0 : 1);
|
||||||
targetList._version++;
|
#if WITH_VERSIONING
|
||||||
|
targetList._version++;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
|
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
|
||||||
@@ -1208,7 +1243,9 @@ namespace Recyclable.Collections
|
|||||||
targetList._nextItemBlockIndex = blockIndex;
|
targetList._nextItemBlockIndex = blockIndex;
|
||||||
targetList._nextItemIndex = itemIndex;
|
targetList._nextItemIndex = itemIndex;
|
||||||
targetList._lastBlockWithData = blockIndex - (itemIndex > 0 ? 0 : 1);
|
targetList._lastBlockWithData = blockIndex - (itemIndex > 0 ? 0 : 1);
|
||||||
targetList._version++;
|
#if WITH_VERSIONING
|
||||||
|
targetList._version++;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
|
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
|
||||||
@@ -1248,7 +1285,9 @@ namespace Recyclable.Collections
|
|||||||
targetList._nextItemBlockIndex = blockIndex;
|
targetList._nextItemBlockIndex = blockIndex;
|
||||||
targetList._nextItemIndex = itemIndex;
|
targetList._nextItemIndex = itemIndex;
|
||||||
targetList._lastBlockWithData = blockIndex - (itemIndex > 0 ? 0 : 1);
|
targetList._lastBlockWithData = blockIndex - (itemIndex > 0 ? 0 : 1);
|
||||||
targetList._version++;
|
#if WITH_VERSIONING
|
||||||
|
targetList._version++;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -10,19 +10,25 @@ namespace Recyclable.Collections
|
|||||||
public static void Sort<T>(this RecyclableLongList<T> list)
|
public static void Sort<T>(this RecyclableLongList<T> list)
|
||||||
{
|
{
|
||||||
QuickSortExtensions<T>.QuickSort(list);
|
QuickSortExtensions<T>.QuickSort(list);
|
||||||
|
#if WITH_VERSIONING
|
||||||
list._version++;
|
list._version++;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Sort<T>(this RecyclableLongList<T> list, Comparison<T> comparison)
|
public static void Sort<T>(this RecyclableLongList<T> list, Comparison<T> comparison)
|
||||||
{
|
{
|
||||||
QuickSortExtensions<T>.QuickSort(list, new ComparisonToComparerAdapter<T>(comparison), new SystemRandomNumberGenerator());
|
QuickSortExtensions<T>.QuickSort(list, new ComparisonToComparerAdapter<T>(comparison), new SystemRandomNumberGenerator());
|
||||||
|
#if WITH_VERSIONING
|
||||||
list._version++;
|
list._version++;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Sort<T>(this RecyclableLongList<T> list, IComparer<T>? comparer)
|
public static void Sort<T>(this RecyclableLongList<T> list, IComparer<T>? comparer)
|
||||||
{
|
{
|
||||||
QuickSortExtensions<T>.QuickSort(list, comparer ?? Comparer<T>.Default, new SystemRandomNumberGenerator());
|
QuickSortExtensions<T>.QuickSort(list, comparer ?? Comparer<T>.Default, new SystemRandomNumberGenerator());
|
||||||
|
#if WITH_VERSIONING
|
||||||
list._version++;
|
list._version++;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Sort<T>(this RecyclableLongList<T> list, long index, long count, IComparer<T>? comparer)
|
public static void Sort<T>(this RecyclableLongList<T> list, long index, long count, IComparer<T>? comparer)
|
||||||
@@ -33,7 +39,9 @@ namespace Recyclable.Collections
|
|||||||
}
|
}
|
||||||
|
|
||||||
QuickSortExtensions<T>.QuickSort(list, (int)index, (int)(index + count - 1), comparer ?? Comparer<T>.Default, new SystemRandomNumberGenerator());
|
QuickSortExtensions<T>.QuickSort(list, (int)index, (int)(index + count - 1), comparer ?? Comparer<T>.Default, new SystemRandomNumberGenerator());
|
||||||
|
#if WITH_VERSIONING
|
||||||
list._version++;
|
list._version++;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5,6 +5,7 @@ namespace Recyclable.Collections
|
|||||||
{
|
{
|
||||||
public partial class RecyclableLongList<T>
|
public partial class RecyclableLongList<T>
|
||||||
{
|
{
|
||||||
|
[VersionedCollectionsGenerator.CloneForVersioned]
|
||||||
public struct Enumerator : IEnumerator<T>
|
public struct Enumerator : IEnumerator<T>
|
||||||
{
|
{
|
||||||
#nullable disable
|
#nullable disable
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using System.Runtime.CompilerServices;
|
|||||||
|
|
||||||
namespace Recyclable.Collections
|
namespace Recyclable.Collections
|
||||||
{
|
{
|
||||||
|
[VersionedCollectionsGenerator.GenerateVersioned]
|
||||||
public static class RecyclableLongListExtensions
|
public static class RecyclableLongListExtensions
|
||||||
{
|
{
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
|||||||
@@ -5,9 +5,12 @@ namespace Recyclable.Collections
|
|||||||
{
|
{
|
||||||
public partial class RecyclableLongList<T> : IRecyclableVersionedLongList<T>
|
public partial class RecyclableLongList<T> : IRecyclableVersionedLongList<T>
|
||||||
{
|
{
|
||||||
|
[VersionedCollectionsGenerator.CloneForVersioned]
|
||||||
public VersionedEnumerator GetVersionedEnumerator() => new(this);
|
public VersionedEnumerator GetVersionedEnumerator() => new(this);
|
||||||
|
[VersionedCollectionsGenerator.CloneForVersioned]
|
||||||
VersionedEnumerator IRecyclableVersionedLongList<T>.GetEnumerator() => new(this);
|
VersionedEnumerator IRecyclableVersionedLongList<T>.GetEnumerator() => new(this);
|
||||||
|
|
||||||
|
[VersionedCollectionsGenerator.CloneForVersioned]
|
||||||
public struct VersionedEnumerator : IEnumerator<T>
|
public struct VersionedEnumerator : IEnumerator<T>
|
||||||
{
|
{
|
||||||
#nullable disable
|
#nullable disable
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ using Recyclable.Collections.Pools;
|
|||||||
|
|
||||||
namespace Recyclable.Collections
|
namespace Recyclable.Collections
|
||||||
{
|
{
|
||||||
|
[VersionedCollectionsGenerator.GenerateVersioned]
|
||||||
public partial class RecyclableLongList<T> : IList<T>, IReadOnlyList<T>, IDisposable
|
public partial class RecyclableLongList<T> : IList<T>, IReadOnlyList<T>, IDisposable
|
||||||
{
|
{
|
||||||
private static readonly bool _defaultIsNull = default(T) == null;
|
private static readonly bool _defaultIsNull = default(T) == null;
|
||||||
@@ -36,11 +37,15 @@ namespace Recyclable.Collections
|
|||||||
private set
|
private set
|
||||||
{
|
{
|
||||||
_capacity = value;
|
_capacity = value;
|
||||||
|
#if WITH_VERSIONING
|
||||||
_version++;
|
_version++;
|
||||||
|
#endif
|
||||||
if (_capacity != value)
|
if (_capacity != value)
|
||||||
{
|
{
|
||||||
_capacity = Helpers.Resize(this, _blockSize, _blockSizePow2BitShift, checked((long)BitOperations.RoundUpToPowerOf2((ulong)value)));
|
_capacity = Helpers.Resize(this, _blockSize, _blockSizePow2BitShift, checked((long)BitOperations.RoundUpToPowerOf2((ulong)value)));
|
||||||
|
#if WITH_VERSIONING
|
||||||
_version++;
|
_version++;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -51,6 +56,7 @@ namespace Recyclable.Collections
|
|||||||
public long LongCount => _longCount;
|
public long LongCount => _longCount;
|
||||||
public int NextItemBlockIndex => _nextItemBlockIndex;
|
public int NextItemBlockIndex => _nextItemBlockIndex;
|
||||||
public int NextItemIndex => _nextItemIndex;
|
public int NextItemIndex => _nextItemIndex;
|
||||||
|
[VersionedCollectionsGenerator.CloneForVersioned]
|
||||||
public ulong Version => _version;
|
public ulong Version => _version;
|
||||||
|
|
||||||
public RecyclableLongList(int minBlockSize = RecyclableDefaults.BlockSize, long initialCapacity = RecyclableDefaults.InitialCapacity)
|
public RecyclableLongList(int minBlockSize = RecyclableDefaults.BlockSize, long initialCapacity = RecyclableDefaults.InitialCapacity)
|
||||||
@@ -252,7 +258,9 @@ namespace Recyclable.Collections
|
|||||||
set
|
set
|
||||||
{
|
{
|
||||||
new Span<T>(_memoryBlocks[(int)(index >> _blockSizePow2BitShift)])[(int)(index & _blockSizeMinus1)] = value;
|
new Span<T>(_memoryBlocks[(int)(index >> _blockSizePow2BitShift)])[(int)(index & _blockSizeMinus1)] = value;
|
||||||
|
#if WITH_VERSIONING
|
||||||
_version++;
|
_version++;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -262,7 +270,9 @@ namespace Recyclable.Collections
|
|||||||
set
|
set
|
||||||
{
|
{
|
||||||
new Span<T>(_memoryBlocks[index >> _blockSizePow2BitShift])[index & _blockSizeMinus1] = value;
|
new Span<T>(_memoryBlocks[index >> _blockSizePow2BitShift])[index & _blockSizeMinus1] = value;
|
||||||
|
#if WITH_VERSIONING
|
||||||
_version++;
|
_version++;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -293,7 +303,9 @@ namespace Recyclable.Collections
|
|||||||
}
|
}
|
||||||
|
|
||||||
_longCount++;
|
_longCount++;
|
||||||
|
#if WITH_VERSIONING
|
||||||
_version++;
|
_version++;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Clear()
|
public void Clear()
|
||||||
@@ -327,7 +339,9 @@ namespace Recyclable.Collections
|
|||||||
_nextItemIndex = 0;
|
_nextItemIndex = 0;
|
||||||
_lastBlockWithData = RecyclableDefaults.ItemNotFoundIndex;
|
_lastBlockWithData = RecyclableDefaults.ItemNotFoundIndex;
|
||||||
_longCount = 0;
|
_longCount = 0;
|
||||||
|
#if WITH_VERSIONING
|
||||||
_version++;
|
_version++;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
@@ -358,9 +372,24 @@ namespace Recyclable.Collections
|
|||||||
|
|
||||||
public void CopyTo(T[] array, int arrayIndex) => Helpers.CopyTo(_memoryBlocks, 0, _blockSize, _longCount, array, arrayIndex);
|
public void CopyTo(T[] array, int arrayIndex) => Helpers.CopyTo(_memoryBlocks, 0, _blockSize, _longCount, array, arrayIndex);
|
||||||
|
|
||||||
|
[VersionedCollectionsGenerator.CloneForVersioned]
|
||||||
|
#if WITH_VERSIONING
|
||||||
|
public VersionedEnumerator GetEnumerator() => new(this);
|
||||||
|
#else
|
||||||
public Enumerator GetEnumerator() => new(this);
|
public Enumerator GetEnumerator() => new(this);
|
||||||
|
#endif
|
||||||
|
[VersionedCollectionsGenerator.CloneForVersioned]
|
||||||
|
#if WITH_VERSIONING
|
||||||
|
IEnumerator IEnumerable.GetEnumerator() => new VersionedEnumerator(this);
|
||||||
|
#else
|
||||||
IEnumerator IEnumerable.GetEnumerator() => new Enumerator(this);
|
IEnumerator IEnumerable.GetEnumerator() => new Enumerator(this);
|
||||||
|
#endif
|
||||||
|
[VersionedCollectionsGenerator.CloneForVersioned]
|
||||||
|
#if WITH_VERSIONING
|
||||||
|
IEnumerator<T> IEnumerable<T>.GetEnumerator() => new VersionedEnumerator(this);
|
||||||
|
#else
|
||||||
IEnumerator<T> IEnumerable<T>.GetEnumerator() => new Enumerator(this);
|
IEnumerator<T> IEnumerable<T>.GetEnumerator() => new Enumerator(this);
|
||||||
|
#endif
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||||
public int IndexOf(T item)
|
public int IndexOf(T item)
|
||||||
@@ -433,7 +462,9 @@ namespace Recyclable.Collections
|
|||||||
_lastBlockWithData++;
|
_lastBlockWithData++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if WITH_VERSIONING
|
||||||
_version++;
|
_version++;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Insert(long index, T item)
|
public void Insert(long index, T item)
|
||||||
@@ -472,7 +503,9 @@ namespace Recyclable.Collections
|
|||||||
_lastBlockWithData++;
|
_lastBlockWithData++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if WITH_VERSIONING
|
||||||
_version++;
|
_version++;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||||
@@ -543,7 +576,9 @@ namespace Recyclable.Collections
|
|||||||
#nullable restore
|
#nullable restore
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if WITH_VERSIONING
|
||||||
_version++;
|
_version++;
|
||||||
|
#endif
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -585,7 +620,9 @@ namespace Recyclable.Collections
|
|||||||
#nullable restore
|
#nullable restore
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if WITH_VERSIONING
|
||||||
_version++;
|
_version++;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||||
@@ -623,7 +660,9 @@ namespace Recyclable.Collections
|
|||||||
#nullable restore
|
#nullable restore
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if WITH_VERSIONING
|
||||||
_version++;
|
_version++;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RemoveBlock(int index)
|
public void RemoveBlock(int index)
|
||||||
@@ -645,12 +684,16 @@ namespace Recyclable.Collections
|
|||||||
}
|
}
|
||||||
|
|
||||||
_lastBlockWithData--;
|
_lastBlockWithData--;
|
||||||
|
#if WITH_VERSIONING
|
||||||
_version++;
|
_version++;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
|
#if WITH_VERSIONING
|
||||||
_version++;
|
_version++;
|
||||||
|
#endif
|
||||||
if (_capacity > 0)
|
if (_capacity > 0)
|
||||||
{
|
{
|
||||||
Clear();
|
Clear();
|
||||||
|
|||||||
Reference in new issue
Block a user