Several hints removed & code cleaned up.
This commit is contained in:
1 parent
b038bcfdc9
commit
dfb671aff7
22 files changed
+46
-78
No files matched your search
@@ -63,6 +63,5 @@ namespace Recyclable.Collections.Benchmarks
|
|||||||
DoNothing(list.Contains(data[^(i + 1)]));
|
DoNothing(list.Contains(data[^(i + 1)]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -78,7 +78,6 @@ namespace Recyclable.Collections.Benchmarks
|
|||||||
|
|
||||||
if (nextItemBlockIndex == data.LastBlockWithData)
|
if (nextItemBlockIndex == data.LastBlockWithData)
|
||||||
{
|
{
|
||||||
|
|
||||||
var memoryBlock = new Span<long>(memoryBlocks[nextItemBlockIndex], 0, data.NextItemIndex);
|
var memoryBlock = new Span<long>(memoryBlocks[nextItemBlockIndex], 0, data.NextItemIndex);
|
||||||
for (var itemIndex = 0; itemIndex < memoryBlock.Length; itemIndex++)
|
for (var itemIndex = 0; itemIndex < memoryBlock.Length; itemIndex++)
|
||||||
{
|
{
|
||||||
@@ -119,8 +118,6 @@ namespace Recyclable.Collections.Benchmarks
|
|||||||
public void RecyclableList_GetItem_AsForEach()
|
public void RecyclableList_GetItem_AsForEach()
|
||||||
{
|
{
|
||||||
var data = TestObjectsAsRecyclableList;
|
var data = TestObjectsAsRecyclableList;
|
||||||
var dataCount = TestObjectCount;
|
|
||||||
|
|
||||||
foreach (var item in data)
|
foreach (var item in data)
|
||||||
{
|
{
|
||||||
DoNothing(item);
|
DoNothing(item);
|
||||||
|
|||||||
@@ -75,6 +75,5 @@ namespace Recyclable.Collections.Benchmarks
|
|||||||
DoNothing(list.LongIndexOf(data[i]));
|
DoNothing(list.LongIndexOf(data[i]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -75,6 +75,5 @@ namespace Recyclable.Collections.Benchmarks
|
|||||||
DoNothing(list.LongIndexOf(data[i]));
|
DoNothing(list.LongIndexOf(data[i]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -75,6 +75,5 @@ namespace Recyclable.Collections.Benchmarks
|
|||||||
DoNothing(list.LongIndexOf(data[^(i + 1)]));
|
DoNothing(list.LongIndexOf(data[^(i + 1)]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -17,6 +17,5 @@ namespace Recyclable.Collections.Benchmarks
|
|||||||
var data = TestObjectsAsRecyclableList;
|
var data = TestObjectsAsRecyclableList;
|
||||||
DoNothing(data.LongCount);
|
DoNothing(data.LongCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -52,6 +52,5 @@ namespace Recyclable.Collections.Benchmarks
|
|||||||
DoNothing(list.Remove(data[i]));
|
DoNothing(list.Remove(data[i]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
using BenchmarkDotNet.Attributes;
|
using BenchmarkDotNet.Attributes;
|
||||||
using Collections.Pooled;
|
using Collections.Pooled;
|
||||||
|
|
||||||
|
|
||||||
namespace Recyclable.Collections.Benchmarks
|
namespace Recyclable.Collections.Benchmarks
|
||||||
{
|
{
|
||||||
public partial class RecyclableCollectionsBenchmarks
|
public partial class RecyclableCollectionsBenchmarks
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
namespace Recyclable.Collections.Benchmarks.Core
|
namespace Recyclable.Collections.Benchmarks.Core
|
||||||
{
|
{
|
||||||
public class DataGenerator
|
public static class DataGenerator
|
||||||
{
|
{
|
||||||
public static long[] EnumerateTestObjects(long testObjectCount)
|
public static long[] EnumerateTestObjects(long testObjectCount)
|
||||||
{
|
{
|
||||||
@@ -15,6 +15,5 @@ namespace Recyclable.Collections.Benchmarks.Core
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -18,8 +18,8 @@ namespace Recyclable.Collections.Benchmarks.POC
|
|||||||
//Console.WriteLine($"{callerName}: result = {result}");
|
//Console.WriteLine($"{callerName}: result = {result}");
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool _testBool = true;
|
private readonly bool _testBool = true;
|
||||||
private int _blockSize = 8;
|
private readonly int _blockSize = 8;
|
||||||
|
|
||||||
[Benchmark(Baseline = false)]
|
[Benchmark(Baseline = false)]
|
||||||
public void Bool()
|
public void Bool()
|
||||||
|
|||||||
@@ -64,13 +64,13 @@ namespace Recyclable.Collections.Benchmarks.POC
|
|||||||
|
|
||||||
private const int _objectCount = 1_000_000;
|
private const int _objectCount = 1_000_000;
|
||||||
private static readonly IEnumerable<long> _testObjects = Enumerable.Range(1, _objectCount).Select(x => (long)x);
|
private static readonly IEnumerable<long> _testObjects = Enumerable.Range(1, _objectCount).Select(x => (long)x);
|
||||||
private static readonly IEnumerable<Func<long, long, int>> _testListOfFunctions = _testObjects.Select<long, Func<long, long, int>>(static x => new MyComparer().Compare);
|
private static readonly IEnumerable<Func<long, long, int>> _testListOfFunctions = _testObjects.Select<long, Func<long, long, int>>(static _ => new MyComparer().Compare);
|
||||||
private static readonly IEnumerable<IComparer<long>> _testListOfComparers = _testObjects.Select(x => (IComparer<long>)new MyComparer());
|
private static readonly IEnumerable<IComparer<long>> _testListOfComparers = _testObjects.Select(_ => (IComparer<long>)new MyComparer());
|
||||||
private static readonly IEnumerable<Compare<long>> _testListOfDelegates = _testObjects.Select(x => new Compare<long>((x, y) => new MyComparer().Compare(x, y)));
|
private static readonly IEnumerable<Compare<long>> _testListOfDelegates = _testObjects.Select(_ => new Compare<long>((x, y) => new MyComparer().Compare(x, y)));
|
||||||
private static readonly IEnumerable<Func<long, long, int>> _testListOfLocalFunctions = GetLocalFunctions(_testObjects);
|
private static readonly IEnumerable<Func<long, long, int>> _testListOfLocalFunctions = GetLocalFunctions(_testObjects);
|
||||||
private static readonly IEnumerable<MyComparer> _testListOfClasses = _testObjects.Select(x => new MyComparer());
|
private static readonly IEnumerable<MyComparer> _testListOfClasses = _testObjects.Select(_ => new MyComparer());
|
||||||
private static readonly IEnumerable<MyComparerStruct<long>> _testListOfStructs = _testObjects.Select(x => new MyComparerStruct<long>());
|
private static readonly IEnumerable<MyComparerStruct<long>> _testListOfStructs = _testObjects.Select(_ => new MyComparerStruct<long>());
|
||||||
private static readonly IEnumerable<IComparer<long>> _testListOfBoxedStructs = _testObjects.Select(x => (IComparer<long>)new MyComparerStruct<long>());
|
private static readonly IEnumerable<IComparer<long>> _testListOfBoxedStructs = _testObjects.Select(_ => (IComparer<long>)new MyComparerStruct<long>());
|
||||||
private static IEnumerable<TComparer> _testListOfUnboxedStructs<TComparer, TValue>() where TComparer : IComparer<TValue>, new()
|
private static IEnumerable<TComparer> _testListOfUnboxedStructs<TComparer, TValue>() where TComparer : IComparer<TValue>, new()
|
||||||
{
|
{
|
||||||
foreach (var item in _testObjects)
|
foreach (var item in _testObjects)
|
||||||
|
|||||||
+8
-10
@@ -586,7 +586,6 @@ namespace Recyclable.Collections.Benchmarks.POC
|
|||||||
{
|
{
|
||||||
_nextItemIndex = (int)(targetCapacity & (blockSize - 1));
|
_nextItemIndex = (int)(targetCapacity & (blockSize - 1));
|
||||||
_nextItemBlockIndex = targetBlockIndex;
|
_nextItemBlockIndex = targetBlockIndex;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_longCount = targetCapacity;
|
_longCount = targetCapacity;
|
||||||
@@ -872,7 +871,6 @@ namespace Recyclable.Collections.Benchmarks.POC
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region RecyclableList v2
|
#region RecyclableList v2
|
||||||
@@ -1117,10 +1115,11 @@ namespace Recyclable.Collections.Benchmarks.POC
|
|||||||
/// <param name="minBlockSize">Minimal requested block size. It MUST be rounded to the power of 2, see remarks.</param>
|
/// <param name="minBlockSize">Minimal requested block size. It MUST be rounded to the power of 2, see remarks.</param>
|
||||||
/// <param name="minBlockSizeBitShift">Pre-calculated bit shifting value for left & right shift operations against<paramref name="minBlockSize"/>.</param>
|
/// <param name="minBlockSizeBitShift">Pre-calculated bit shifting value for left & right shift operations against<paramref name="minBlockSize"/>.</param>
|
||||||
/// <param name="newCapacity">The minimum no. of items <paramref name="list"/> MUST be able to store after <see cref="RecyclableListV2{T}.Resize(RecyclableListV2{T}, int, byte, long)"/>.</param>
|
/// <param name="newCapacity">The minimum no. of items <paramref name="list"/> MUST be able to store after <see cref="RecyclableListV2{T}.Resize(RecyclableListV2{T}, int, byte, long)"/>.</param>
|
||||||
/// <remarks>For performance reasons, <paramref name="minBlockSize"/> MUST a power of 2. This simplifies a lot block & item
|
/// <remarks><para>
|
||||||
|
/// For performance reasons, <paramref name="minBlockSize"/> MUST a power of 2. This simplifies a lot block & item
|
||||||
/// index calculations, i.e. makes them logical operations on bits.
|
/// index calculations, i.e. makes them logical operations on bits.
|
||||||
///
|
/// </para>
|
||||||
/// This method checks for integral overflow.
|
/// <para>This method checks for integral overflow.</para>
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
/// <returns>The maximum no. of items <paramref name="list"/> can store.</returns>
|
/// <returns>The maximum no. of items <paramref name="list"/> can store.</returns>
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||||
@@ -1485,7 +1484,6 @@ namespace Recyclable.Collections.Benchmarks.POC
|
|||||||
{
|
{
|
||||||
_nextItemIndex = checked((int)(targetCapacity & (blockSize - 1)));
|
_nextItemIndex = checked((int)(targetCapacity & (blockSize - 1)));
|
||||||
_nextItemBlockIndex = targetBlockIndex;
|
_nextItemBlockIndex = targetBlockIndex;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_longCount = targetCapacity;
|
_longCount = targetCapacity;
|
||||||
@@ -2089,10 +2087,11 @@ namespace Recyclable.Collections.Benchmarks.POC
|
|||||||
/// <param name="minBlockSize">Minimal requested block size. It MUST be rounded to the power of 2, see remarks.</param>
|
/// <param name="minBlockSize">Minimal requested block size. It MUST be rounded to the power of 2, see remarks.</param>
|
||||||
/// <param name="minBlockSizePow2Shift">Pre-calculated bit shifting value for left & right shift operations against<paramref name="minBlockSize"/>.</param>
|
/// <param name="minBlockSizePow2Shift">Pre-calculated bit shifting value for left & right shift operations against<paramref name="minBlockSize"/>.</param>
|
||||||
/// <param name="newCapacity">The minimum no. of items <paramref name="list"/> MUST be able to store after <see cref="RecyclableList{T}.Resize(RecyclableList{T}, int, byte, long)"/>.</param>
|
/// <param name="newCapacity">The minimum no. of items <paramref name="list"/> MUST be able to store after <see cref="RecyclableList{T}.Resize(RecyclableList{T}, int, byte, long)"/>.</param>
|
||||||
/// <remarks>For performance reasons, <paramref name="minBlockSize"/> MUST a power of 2. This simplifies a lot block & item
|
/// <remarks><para>
|
||||||
|
/// For performance reasons, <paramref name="minBlockSize"/> MUST a power of 2. This simplifies a lot block & item
|
||||||
/// index calculations, i.e. makes them logical operations on bits.
|
/// index calculations, i.e. makes them logical operations on bits.
|
||||||
///
|
/// </para>
|
||||||
/// This method checks for integral overflow.
|
/// <para>This method checks for integral overflow.</para>
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
/// <returns>The maximum no. of items <paramref name="list"/> can store.</returns>
|
/// <returns>The maximum no. of items <paramref name="list"/> can store.</returns>
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||||
@@ -2446,7 +2445,6 @@ namespace Recyclable.Collections.Benchmarks.POC
|
|||||||
{
|
{
|
||||||
_nextItemIndex = checked((int)(targetCapacity & _blockSizeMinus1));
|
_nextItemIndex = checked((int)(targetCapacity & _blockSizeMinus1));
|
||||||
_nextItemBlockIndex = targetBlockIndex;
|
_nextItemBlockIndex = targetBlockIndex;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_longCount = targetCapacity;
|
_longCount = targetCapacity;
|
||||||
|
|||||||
@@ -404,10 +404,11 @@ namespace Recyclable.Collections.Benchmarks.POC
|
|||||||
/// <param name="minBlockSize">Minimal requested block size. It MUST be rounded to the power of 2, see remarks.</param>
|
/// <param name="minBlockSize">Minimal requested block size. It MUST be rounded to the power of 2, see remarks.</param>
|
||||||
/// <param name="minBlockSizePow2Shift">Pre-calculated bit shifting value for left & right shift operations against<paramref name="minBlockSize"/>.</param>
|
/// <param name="minBlockSizePow2Shift">Pre-calculated bit shifting value for left & right shift operations against<paramref name="minBlockSize"/>.</param>
|
||||||
/// <param name="newCapacity">The minimum no. of items <paramref name="list"/> MUST be able to store after <see cref="RecyclableList{T}.Resize(RecyclableList{T}, int, byte, long)"/>.</param>
|
/// <param name="newCapacity">The minimum no. of items <paramref name="list"/> MUST be able to store after <see cref="RecyclableList{T}.Resize(RecyclableList{T}, int, byte, long)"/>.</param>
|
||||||
/// <remarks>For performance reasons, <paramref name="minBlockSize"/> MUST a power of 2. This simplifies a lot block & item
|
/// <remarks><para>
|
||||||
|
/// For performance reasons, <paramref name="minBlockSize"/> MUST a power of 2. This simplifies a lot block & item
|
||||||
/// index calculations, i.e. makes them logical operations on bits.
|
/// index calculations, i.e. makes them logical operations on bits.
|
||||||
///
|
/// </para>
|
||||||
/// This method checks for integral overflow.
|
/// <para>This method checks for integral overflow.</para>
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// This method doesn't support downsizing the memory block. As such it doesn't release excessive blocks. This is to for additional performance
|
/// This method doesn't support downsizing the memory block. As such it doesn't release excessive blocks. This is to for additional performance
|
||||||
@@ -457,7 +458,7 @@ namespace Recyclable.Collections.Benchmarks.POC
|
|||||||
}
|
}
|
||||||
|
|
||||||
blockIndex = sourceBlockCount;
|
blockIndex = sourceBlockCount;
|
||||||
do
|
while (true)
|
||||||
{
|
{
|
||||||
newMemoryBlocks[blockIndex] = blockArrayPool.Rent(minBlockSize);
|
newMemoryBlocks[blockIndex] = blockArrayPool.Rent(minBlockSize);
|
||||||
if (blockIndex + 1 < requiredBlockCount)
|
if (blockIndex + 1 < requiredBlockCount)
|
||||||
@@ -468,12 +469,12 @@ namespace Recyclable.Collections.Benchmarks.POC
|
|||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} while (true);
|
};
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
blockIndex = sourceBlockCount;
|
blockIndex = sourceBlockCount;
|
||||||
do
|
while (true)
|
||||||
{
|
{
|
||||||
newMemoryBlocks[blockIndex] = new T[minBlockSize];
|
newMemoryBlocks[blockIndex] = new T[minBlockSize];
|
||||||
if (blockIndex + 1 < requiredBlockCount)
|
if (blockIndex + 1 < requiredBlockCount)
|
||||||
@@ -484,7 +485,7 @@ namespace Recyclable.Collections.Benchmarks.POC
|
|||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} while (true);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -773,7 +774,6 @@ namespace Recyclable.Collections.Benchmarks.POC
|
|||||||
{
|
{
|
||||||
_nextItemIndex = checked((int)(targetCapacity & _blockSizeMinus1));
|
_nextItemIndex = checked((int)(targetCapacity & _blockSizeMinus1));
|
||||||
_nextItemBlockIndex = targetBlockIndex;
|
_nextItemBlockIndex = targetBlockIndex;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_longCount = targetCapacity;
|
_longCount = targetCapacity;
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ namespace Recyclable.Collections.Benchmarks.POC
|
|||||||
//[Params(329_000, 512_000, 750_000, 1_000_000, 3_290_000)]
|
//[Params(329_000, 512_000, 750_000, 1_000_000, 3_290_000)]
|
||||||
//public int Step { get; set; } = 329_000; // This was the fastest so far
|
//public int Step { get; set; } = 329_000; // This was the fastest so far
|
||||||
|
|
||||||
private static readonly int _numberOfProcessors = Environment.ProcessorCount;
|
|
||||||
private RecyclableList<long>? _testData;
|
private RecyclableList<long>? _testData;
|
||||||
|
|
||||||
public object? ItemToFind { get; set; }
|
public object? ItemToFind { get; set; }
|
||||||
@@ -40,7 +39,6 @@ namespace Recyclable.Collections.Benchmarks.POC
|
|||||||
_testData = default;
|
_testData = default;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
[Benchmark(Baseline = true)]
|
[Benchmark(Baseline = true)]
|
||||||
public void IndexOfSequentially()
|
public void IndexOfSequentially()
|
||||||
{
|
{
|
||||||
@@ -262,7 +260,6 @@ namespace Recyclable.Collections.Benchmarks.POC
|
|||||||
|
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
|
||||||
// if (threadIndex + 1 < numberOfRanges && blockIndex <= _testData.LastBlockWithData)
|
// if (threadIndex + 1 < numberOfRanges && blockIndex <= _testData.LastBlockWithData)
|
||||||
// {
|
// {
|
||||||
// threadIndex++;
|
// threadIndex++;
|
||||||
|
|||||||
@@ -5,13 +5,13 @@ namespace Recyclable.Collections
|
|||||||
{
|
{
|
||||||
public static class MathUtils
|
public static class MathUtils
|
||||||
{
|
{
|
||||||
private static readonly long[] Pow2 = new long[]
|
// private static readonly long[] Pow2 = new long[]
|
||||||
{
|
// {
|
||||||
1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384,
|
// 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384,
|
||||||
32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304,
|
// 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304,
|
||||||
8388608, 16777216, 33554432, 67108864, 134217728, 268435456,
|
// 8388608, 16777216, 33554432, 67108864, 134217728, 268435456,
|
||||||
536870912, 1073741824, 2147483648
|
// 536870912, 1073741824, 2147483648
|
||||||
};
|
// };
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static bool IsPow2(long value) => (value != 0) && ((value & (value - 1)) == 0);
|
public static bool IsPow2(long value) => (value != 0) && ((value & (value - 1)) == 0);
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ namespace Recyclable.Collections
|
|||||||
{
|
{
|
||||||
private const int ItemNotFound = -1;
|
private const int ItemNotFound = -1;
|
||||||
private static readonly ArrayPool<T> _arrayPool = ArrayPool<T>.Create();
|
private static readonly ArrayPool<T> _arrayPool = ArrayPool<T>.Create();
|
||||||
private static readonly IEqualityComparer<T> _equalityComparer = EqualityComparer<T>.Default;
|
|
||||||
|
|
||||||
protected static readonly bool NeedsClearing = !typeof(T).IsValueType;
|
protected static readonly bool NeedsClearing = !typeof(T).IsValueType;
|
||||||
|
|
||||||
@@ -340,7 +339,7 @@ namespace Recyclable.Collections
|
|||||||
if (enumerator.MoveNext())
|
if (enumerator.MoveNext())
|
||||||
{
|
{
|
||||||
int available = capacity - targetItemIdx;
|
int available = capacity - targetItemIdx;
|
||||||
while (true)
|
do
|
||||||
{
|
{
|
||||||
if (targetItemIdx + growByCount > capacity)
|
if (targetItemIdx + growByCount > capacity)
|
||||||
{
|
{
|
||||||
@@ -357,12 +356,8 @@ namespace Recyclable.Collections
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i < available)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
while (i >= available);
|
||||||
}
|
}
|
||||||
|
|
||||||
_count = targetItemIdx;
|
_count = targetItemIdx;
|
||||||
@@ -459,6 +454,7 @@ namespace Recyclable.Collections
|
|||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerator<T> GetEnumerator() => Enumerate(this).GetEnumerator();
|
public IEnumerator<T> GetEnumerator() => Enumerate(this).GetEnumerator();
|
||||||
|
|
||||||
IEnumerator IEnumerable.GetEnumerator() => Enumerate(this).GetEnumerator();
|
IEnumerator IEnumerable.GetEnumerator() => Enumerate(this).GetEnumerator();
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
|
|||||||
@@ -373,10 +373,11 @@ namespace Recyclable.Collections
|
|||||||
/// <param name="minBlockSize">Minimal requested block size. It MUST be rounded to the power of 2, see remarks.</param>
|
/// <param name="minBlockSize">Minimal requested block size. It MUST be rounded to the power of 2, see remarks.</param>
|
||||||
/// <param name="minBlockSizePow2Shift">Pre-calculated bit shifting value for left & right shift operations against<paramref name="minBlockSize"/>.</param>
|
/// <param name="minBlockSizePow2Shift">Pre-calculated bit shifting value for left & right shift operations against<paramref name="minBlockSize"/>.</param>
|
||||||
/// <param name="newCapacity">The minimum no. of items <paramref name="list"/> MUST be able to store after <see cref="RecyclableList{T}.Resize(RecyclableList{T}, int, byte, long)"/>.</param>
|
/// <param name="newCapacity">The minimum no. of items <paramref name="list"/> MUST be able to store after <see cref="RecyclableList{T}.Resize(RecyclableList{T}, int, byte, long)"/>.</param>
|
||||||
/// <remarks>For performance reasons, <paramref name="minBlockSize"/> MUST a power of 2. This simplifies a lot block & item
|
/// <remarks><para>
|
||||||
|
/// For performance reasons, <paramref name="minBlockSize"/> MUST a power of 2. This simplifies a lot block & item
|
||||||
/// index calculations, i.e. makes them logical operations on bits.
|
/// index calculations, i.e. makes them logical operations on bits.
|
||||||
///
|
/// </para>
|
||||||
/// This method checks for integral overflow.
|
/// <para>This method checks for integral overflow.</para>
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// This method doesn't support downsizing the memory block. As such it doesn't release excessive blocks. This is to for additional performance
|
/// This method doesn't support downsizing the memory block. As such it doesn't release excessive blocks. This is to for additional performance
|
||||||
@@ -426,7 +427,7 @@ namespace Recyclable.Collections
|
|||||||
}
|
}
|
||||||
|
|
||||||
blockIndex = sourceBlockCount;
|
blockIndex = sourceBlockCount;
|
||||||
do
|
while (true)
|
||||||
{
|
{
|
||||||
newMemoryBlocks[blockIndex] = blockArrayPool.Rent(minBlockSize);
|
newMemoryBlocks[blockIndex] = blockArrayPool.Rent(minBlockSize);
|
||||||
if (blockIndex + 1 < requiredBlockCount)
|
if (blockIndex + 1 < requiredBlockCount)
|
||||||
@@ -437,12 +438,12 @@ namespace Recyclable.Collections
|
|||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} while (true);
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
blockIndex = sourceBlockCount;
|
blockIndex = sourceBlockCount;
|
||||||
do
|
while (true)
|
||||||
{
|
{
|
||||||
newMemoryBlocks[blockIndex] = new T[minBlockSize];
|
newMemoryBlocks[blockIndex] = new T[minBlockSize];
|
||||||
if (blockIndex + 1 < requiredBlockCount)
|
if (blockIndex + 1 < requiredBlockCount)
|
||||||
@@ -453,7 +454,7 @@ namespace Recyclable.Collections
|
|||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} while (true);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -742,7 +743,6 @@ namespace Recyclable.Collections
|
|||||||
{
|
{
|
||||||
_nextItemIndex = checked((int)(targetCapacity & _blockSizeMinus1));
|
_nextItemIndex = checked((int)(targetCapacity & _blockSizeMinus1));
|
||||||
_nextItemBlockIndex = targetBlockIndex;
|
_nextItemBlockIndex = targetBlockIndex;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_longCount = targetCapacity;
|
_longCount = targetCapacity;
|
||||||
|
|||||||
@@ -193,19 +193,14 @@ namespace Recyclable.Collections
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void Dispose(bool disposing)
|
public void Dispose()
|
||||||
{
|
{
|
||||||
if (!_disposedValue)
|
if (!_disposedValue)
|
||||||
{
|
{
|
||||||
Clear();
|
Clear();
|
||||||
_disposedValue = true;
|
_disposedValue = true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public void Dispose()
|
|
||||||
{
|
|
||||||
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
|
|
||||||
Dispose(disposing: true);
|
|
||||||
GC.SuppressFinalize(this);
|
GC.SuppressFinalize(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ namespace Recyclable.CollectionsTests
|
|||||||
{
|
{
|
||||||
public class EnumerableWithoutCount<T> : IEnumerable<T>
|
public class EnumerableWithoutCount<T> : IEnumerable<T>
|
||||||
{
|
{
|
||||||
private IEnumerable<T> _testData;
|
private readonly IEnumerable<T> _testData;
|
||||||
|
|
||||||
public EnumerableWithoutCount(IEnumerable<T> testData)
|
public EnumerableWithoutCount(IEnumerable<T> testData)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -127,7 +127,6 @@ namespace Recyclable.CollectionsTests
|
|||||||
(9, 0, 1),
|
(9, 0, 1),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -217,7 +217,6 @@ namespace Recyclable.CollectionsTests
|
|||||||
// Validate
|
// Validate
|
||||||
_ = list.Count.Should().Be(0);
|
_ = list.Count.Should().Be(0);
|
||||||
_ = list.Should().BeEmpty();
|
_ = list.Should().BeEmpty();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
@@ -350,10 +349,7 @@ namespace Recyclable.CollectionsTests
|
|||||||
|
|
||||||
// Act
|
// Act
|
||||||
var yieldedItems = new List<long>((int)itemsCount);
|
var yieldedItems = new List<long>((int)itemsCount);
|
||||||
foreach (var item in list)
|
yieldedItems.AddRange(list);
|
||||||
{
|
|
||||||
yieldedItems.Add(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Validate
|
// Validate
|
||||||
_ = yieldedItems.Count.Should().Be((int)itemsCount);
|
_ = yieldedItems.Count.Should().Be((int)itemsCount);
|
||||||
@@ -549,7 +545,6 @@ namespace Recyclable.CollectionsTests
|
|||||||
// Validate
|
// Validate
|
||||||
_ = list.Count.Should().Be((int)(itemsCount - deleted));
|
_ = list.Count.Should().Be((int)(itemsCount - deleted));
|
||||||
_ = list.Should().ContainInConsecutiveOrder(testData.Take((int)(itemsCount - deleted)));
|
_ = list.Should().ContainInConsecutiveOrder(testData.Take((int)(itemsCount - deleted)));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,7 +54,6 @@ namespace Recyclable.CollectionsTests
|
|||||||
CreateTestData(itemsCount).ToRecyclableList(sourceBlockSize),
|
CreateTestData(itemsCount).ToRecyclableList(sourceBlockSize),
|
||||||
itemsCount
|
itemsCount
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
yield return new object[] { $"IList<int>(itemsCount: {itemsCount})", new CustomIList<long>(CreateTestData(itemsCount)), itemsCount };
|
yield return new object[] { $"IList<int>(itemsCount: {itemsCount})", new CustomIList<long>(CreateTestData(itemsCount)), itemsCount };
|
||||||
|
|||||||
Reference in new issue
Block a user