Merge pull request #20 from mlemanczyk/d2kqjh-codex/dodaj-oznaczenia-wersjonowania-w-recyclablelonglist
Implement versioned enumerator retrieval
This commit is contained in:
9 files changed
+74
-34
No files matched your search
@@ -6,9 +6,10 @@ namespace Recyclable.Collections
|
|||||||
{
|
{
|
||||||
public partial class RecyclableList<T>
|
public partial class RecyclableList<T>
|
||||||
{
|
{
|
||||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||||
public struct Enumerator : IEnumerator<T>
|
[VersionedCollectionsGenerator.CloneForVersioned]
|
||||||
{
|
public struct Enumerator : IEnumerator<T>
|
||||||
|
{
|
||||||
private static readonly bool _isReferenceType = !typeof(T).IsValueType;
|
private static readonly bool _isReferenceType = !typeof(T).IsValueType;
|
||||||
|
|
||||||
private int _currentItemIndex;
|
private int _currentItemIndex;
|
||||||
|
|||||||
@@ -3,8 +3,9 @@ using System.Runtime.CompilerServices;
|
|||||||
|
|
||||||
namespace Recyclable.Collections
|
namespace Recyclable.Collections
|
||||||
{
|
{
|
||||||
public static class RecyclableListExtensions
|
[VersionedCollectionsGenerator.GenerateVersioned]
|
||||||
{
|
public static class RecyclableListExtensions
|
||||||
|
{
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static RecyclableList<T> ToRecyclableList<T>(this Array values) => new(values);
|
public static RecyclableList<T> ToRecyclableList<T>(this Array values) => new(values);
|
||||||
|
|
||||||
|
|||||||
@@ -6,11 +6,13 @@ namespace Recyclable.Collections
|
|||||||
{
|
{
|
||||||
public partial class RecyclableList<T> : IRecyclableVersionedList<T>
|
public partial class RecyclableList<T> : IRecyclableVersionedList<T>
|
||||||
{
|
{
|
||||||
VersionedEnumerator IRecyclableVersionedList<T>.GetEnumerator() => new(this);
|
[VersionedCollectionsGenerator.CloneForVersioned]
|
||||||
|
VersionedEnumerator IRecyclableVersionedList<T>.GetEnumerator() => new(this);
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||||
public struct VersionedEnumerator : IEnumerator<T>
|
[VersionedCollectionsGenerator.CloneForVersioned]
|
||||||
{
|
public struct VersionedEnumerator : IEnumerator<T>
|
||||||
|
{
|
||||||
private int _currentItemIndex;
|
private int _currentItemIndex;
|
||||||
private readonly ulong _enumeratorVersion;
|
private readonly ulong _enumeratorVersion;
|
||||||
private readonly RecyclableList<T> _list;
|
private readonly RecyclableList<T> _list;
|
||||||
|
|||||||
@@ -363,14 +363,29 @@ namespace Recyclable.Collections
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public Enumerator GetEnumerator() => new(this);
|
[VersionedCollectionsGenerator.CloneForVersioned]
|
||||||
|
#if WITH_VERSIONING
|
||||||
|
public VersionedEnumerator GetEnumerator() => new(this);
|
||||||
|
#else
|
||||||
|
public Enumerator GetEnumerator() => new(this);
|
||||||
|
#endif
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
IEnumerator IEnumerable.GetEnumerator() => new Enumerator(this);
|
[VersionedCollectionsGenerator.CloneForVersioned]
|
||||||
|
#if WITH_VERSIONING
|
||||||
|
IEnumerator IEnumerable.GetEnumerator() => new VersionedEnumerator(this);
|
||||||
|
#else
|
||||||
|
IEnumerator IEnumerable.GetEnumerator() => new Enumerator(this);
|
||||||
|
#endif
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
IEnumerator<T> IEnumerable<T>.GetEnumerator() => new Enumerator(this);
|
[VersionedCollectionsGenerator.CloneForVersioned]
|
||||||
|
#if WITH_VERSIONING
|
||||||
|
IEnumerator<T> IEnumerable<T>.GetEnumerator() => new VersionedEnumerator(this);
|
||||||
|
#else
|
||||||
|
IEnumerator<T> IEnumerable<T>.GetEnumerator() => new Enumerator(this);
|
||||||
|
#endif
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -5,8 +5,9 @@ namespace Recyclable.Collections
|
|||||||
{
|
{
|
||||||
public partial class RecyclableLongList<T>
|
public partial class RecyclableLongList<T>
|
||||||
{
|
{
|
||||||
public struct Enumerator : IEnumerator<T>
|
[VersionedCollectionsGenerator.CloneForVersioned]
|
||||||
{
|
public struct Enumerator : IEnumerator<T>
|
||||||
|
{
|
||||||
#nullable disable
|
#nullable disable
|
||||||
private static readonly T _default = default;
|
private static readonly T _default = default;
|
||||||
#nullable restore
|
#nullable restore
|
||||||
|
|||||||
@@ -3,8 +3,9 @@ using System.Runtime.CompilerServices;
|
|||||||
|
|
||||||
namespace Recyclable.Collections
|
namespace Recyclable.Collections
|
||||||
{
|
{
|
||||||
public static class RecyclableLongListExtensions
|
[VersionedCollectionsGenerator.GenerateVersioned]
|
||||||
{
|
public static class RecyclableLongListExtensions
|
||||||
|
{
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static RecyclableLongList<T> ToRecyclableLongList<T>(this Array values, int minBlockSize = RecyclableDefaults.BlockSize) => new(values, minBlockSize);
|
public static RecyclableLongList<T> ToRecyclableLongList<T>(this Array values, int minBlockSize = RecyclableDefaults.BlockSize) => new(values, minBlockSize);
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Recyclable.Collections.Pools;
|
using Recyclable.Collections.Pools;
|
||||||
|
using System.Numerics;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
|
|
||||||
namespace Recyclable.Collections
|
namespace Recyclable.Collections
|
||||||
@@ -76,11 +77,11 @@ namespace Recyclable.Collections
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReadOnlySpan<T> sourceBlockMemory;
|
ReadOnlySpan<T> sourceBlockMemory;
|
||||||
Span<T> destinationArrayMemory;
|
Span<T> destinationArrayMemory;
|
||||||
// TODO: Replace with bit-shifting
|
int blockSizePow2Shift = BitOperations.TrailingZeroCount((uint)blockSize);
|
||||||
int startingBlockIndex = (int)(startingIndex / blockSize);
|
int startingBlockIndex = (int)(startingIndex >> blockSizePow2Shift);
|
||||||
int lastBlockIndex = (int)((itemsCount / blockSize) + (itemsCount % blockSize != 0 ? 1 : 0)) - 1;
|
int lastBlockIndex = (int)((itemsCount >> blockSizePow2Shift) + ((itemsCount & (blockSize - 1)) != 0 ? 1 : 0)) - 1;
|
||||||
ReadOnlySpan<T[]> sourceMemoryBlocksSpan = new(sourceMemoryBlocks, startingBlockIndex, lastBlockIndex + 1);
|
ReadOnlySpan<T[]> sourceMemoryBlocksSpan = new(sourceMemoryBlocks, startingBlockIndex, lastBlockIndex + 1);
|
||||||
destinationArrayMemory = new Span<T>(destinationArray, destinationArrayIndex, (int)Math.Min(destinationArray.Length - destinationArrayIndex, itemsCount));
|
destinationArrayMemory = new Span<T>(destinationArray, destinationArrayIndex, (int)Math.Min(destinationArray.Length - destinationArrayIndex, itemsCount));
|
||||||
int memoryBlockIndex;
|
int memoryBlockIndex;
|
||||||
@@ -105,9 +106,9 @@ namespace Recyclable.Collections
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Replace with bit-shifting
|
int blockSizePow2Shift = BitOperations.TrailingZeroCount((uint)blockSize);
|
||||||
int startingBlockIndex = (int)(startingIndex / blockSize);
|
int startingBlockIndex = (int)(startingIndex >> blockSizePow2Shift);
|
||||||
int lastBlockIndex = (int)((itemsCount / blockSize) + (itemsCount % blockSize != 0 ? 1 : 0)) - 1;
|
int lastBlockIndex = (int)((itemsCount >> blockSizePow2Shift) + ((itemsCount & (blockSize - 1)) != 0 ? 1 : 0)) - 1;
|
||||||
|
|
||||||
var destinationIndex = destinationArrayIndex;
|
var destinationIndex = destinationArrayIndex;
|
||||||
ReadOnlySpan<T[]> sourceMemoryBlocksSpan = new(sourceMemoryBlocks, startingBlockIndex, lastBlockIndex + 1);
|
ReadOnlySpan<T[]> sourceMemoryBlocksSpan = new(sourceMemoryBlocks, startingBlockIndex, lastBlockIndex + 1);
|
||||||
|
|||||||
@@ -5,11 +5,14 @@ namespace Recyclable.Collections
|
|||||||
{
|
{
|
||||||
public partial class RecyclableLongList<T> : IRecyclableVersionedLongList<T>
|
public partial class RecyclableLongList<T> : IRecyclableVersionedLongList<T>
|
||||||
{
|
{
|
||||||
public VersionedEnumerator GetVersionedEnumerator() => new(this);
|
[VersionedCollectionsGenerator.CloneForVersioned]
|
||||||
VersionedEnumerator IRecyclableVersionedLongList<T>.GetEnumerator() => new(this);
|
public VersionedEnumerator GetVersionedEnumerator() => new(this);
|
||||||
|
[VersionedCollectionsGenerator.CloneForVersioned]
|
||||||
|
VersionedEnumerator IRecyclableVersionedLongList<T>.GetEnumerator() => new(this);
|
||||||
|
|
||||||
public struct VersionedEnumerator : IEnumerator<T>
|
[VersionedCollectionsGenerator.CloneForVersioned]
|
||||||
{
|
public struct VersionedEnumerator : IEnumerator<T>
|
||||||
|
{
|
||||||
#nullable disable
|
#nullable disable
|
||||||
private static readonly T _default = default;
|
private static readonly T _default = default;
|
||||||
#nullable restore
|
#nullable restore
|
||||||
|
|||||||
@@ -372,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);
|
||||||
|
|
||||||
public Enumerator GetEnumerator() => new(this);
|
[VersionedCollectionsGenerator.CloneForVersioned]
|
||||||
IEnumerator IEnumerable.GetEnumerator() => new Enumerator(this);
|
#if WITH_VERSIONING
|
||||||
IEnumerator<T> IEnumerable<T>.GetEnumerator() => new Enumerator(this);
|
public VersionedEnumerator GetEnumerator() => new(this);
|
||||||
|
#else
|
||||||
|
public Enumerator GetEnumerator() => new(this);
|
||||||
|
#endif
|
||||||
|
[VersionedCollectionsGenerator.CloneForVersioned]
|
||||||
|
#if WITH_VERSIONING
|
||||||
|
IEnumerator IEnumerable.GetEnumerator() => new VersionedEnumerator(this);
|
||||||
|
#else
|
||||||
|
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);
|
||||||
|
#endif
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||||
public int IndexOf(T item)
|
public int IndexOf(T item)
|
||||||
|
|||||||
Reference in new issue
Block a user