List<T> compatibility code moved to Recyclable.Collections.Compatibility.List package. Cleanup.
This commit is contained in:
1 parent
ec69b1c406
commit
203b13268f
61 files changed
+1634
-4375
No files matched your search
@@ -1,33 +0,0 @@
|
||||
using System.Collections;
|
||||
|
||||
namespace Recyclable.CollectionsTests
|
||||
{
|
||||
public class CustomIList<T> : IList<T>
|
||||
{
|
||||
protected List<T> _list;
|
||||
|
||||
public CustomIList()
|
||||
{
|
||||
_list = new List<T>();
|
||||
}
|
||||
|
||||
public CustomIList(IEnumerable<T> items)
|
||||
{
|
||||
_list = new List<T>(items);
|
||||
}
|
||||
|
||||
public T this[int index] { get => _list[index]; set => _list[index] = value; }
|
||||
public int Count => _list.Count;
|
||||
public bool IsReadOnly => false;
|
||||
public void Add(T item) => _list.Add(item);
|
||||
public void Clear() => _list.Clear();
|
||||
public bool Contains(T item) => _list.Contains(item);
|
||||
public void CopyTo(T[] array, int arrayIndex) => _list.CopyTo(0, array, arrayIndex, _list.Count);
|
||||
public IEnumerator<T> GetEnumerator() => _list.GetEnumerator();
|
||||
public int IndexOf(T item) => _list.IndexOf(item);
|
||||
public void Insert(int index, T item) => _list.Insert(index, item);
|
||||
public bool Remove(T item) => _list.Remove(item);
|
||||
public void RemoveAt(int index) => _list.RemoveAt(index);
|
||||
IEnumerator IEnumerable.GetEnumerator() => _list.GetEnumerator();
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
using System.Collections;
|
||||
|
||||
namespace Recyclable.CollectionsTests
|
||||
{
|
||||
public class EnumerableWithoutCount<T> : IEnumerable<T>
|
||||
{
|
||||
private readonly IEnumerable<T> _testData;
|
||||
|
||||
public EnumerableWithoutCount(IEnumerable<T> testData)
|
||||
{
|
||||
_testData = testData;
|
||||
}
|
||||
|
||||
public IEnumerator<T> GetEnumerator() => _testData.GetEnumerator();
|
||||
IEnumerator IEnumerable.GetEnumerator() => _testData.GetEnumerator();
|
||||
}
|
||||
}
|
||||
@@ -9,20 +9,19 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="FluentAssertions" Version="6.11.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.2" />
|
||||
<PackageReference Include="morelinq" Version="3.4.2" />
|
||||
<PackageReference Include="FluentAssertions" Version="6.12.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.0">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Open.Numeric.Primes" Version="3.0.0" />
|
||||
<PackageReference Include="xunit" Version="2.4.2" />
|
||||
<PackageReference Include="xunit.runner.console" Version="2.5.0">
|
||||
<PackageReference Include="Recyclable.Collections.TestData" Version="0.0.2" />
|
||||
<PackageReference Include="xunit" Version="2.5.3" />
|
||||
<PackageReference Include="xunit.runner.console" Version="2.5.3">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -1,282 +0,0 @@
|
||||
using MoreLinq;
|
||||
using Open.Numeric.Primes;
|
||||
using Recyclable.Collections;
|
||||
using System.Numerics;
|
||||
|
||||
namespace Recyclable.CollectionsTests
|
||||
{
|
||||
public static class RecyclableLongListTestData
|
||||
{
|
||||
|
||||
private static readonly object[] _sourceRefData = Enumerable.Range(1, 100).Cast<object>().ToArray();
|
||||
public static object[] SourceRefData => _sourceRefData;
|
||||
|
||||
public static IEnumerable<long> CreateTestData(long itemsCount)
|
||||
{
|
||||
for (long index = 1; index <= itemsCount; index++)
|
||||
{
|
||||
yield return index;
|
||||
}
|
||||
}
|
||||
|
||||
public static IEnumerable<object> CreateRefTestData(long itemsCount)
|
||||
{
|
||||
for (long index = 1; index <= itemsCount; index++)
|
||||
{
|
||||
yield return index;
|
||||
}
|
||||
}
|
||||
|
||||
public static readonly IEnumerable<long> ItemsCountVariants = new long[]
|
||||
{
|
||||
//RecyclableDefaults.MinPooledArrayLength - 5, RecyclableDefaults.MinPooledArrayLength - 1, RecyclableDefaults.MinPooledArrayLength, RecyclableDefaults.MinPooledArrayLength + 1, RecyclableDefaults.MinPooledArrayLength + 5, 127, 128, 129, RecyclableDefaults.MinItemsCountForParallelization
|
||||
0, 1, 2, 3, 7, 10, 16, RecyclableDefaults.MinPooledArrayLength - 5, RecyclableDefaults.MinPooledArrayLength - 1, RecyclableDefaults.MinPooledArrayLength, RecyclableDefaults.MinPooledArrayLength + 1, RecyclableDefaults.MinPooledArrayLength + 5, RecyclableDefaults.MinPooledArrayLength * 100
|
||||
};
|
||||
|
||||
public static readonly IEnumerable<object[]> ItemsCountTestCases = ItemsCountVariants.Select(x => new object[] { (int)x });
|
||||
|
||||
public static readonly IEnumerable<int> BlockSizeVariants = new int[]
|
||||
{
|
||||
1, 2, 4, 16, RecyclableDefaults.MinPooledArrayLength - 5, (int)BitOperations.RoundUpToPowerOf2(RecyclableDefaults.MinPooledArrayLength)
|
||||
};
|
||||
|
||||
private static bool IsValidBlockSize(long itemsCount, long blockSize) => itemsCount is < 1024 || blockSize is > 8;
|
||||
|
||||
private static IEnumerable<object[]> GetTargetDataVariants()
|
||||
{
|
||||
foreach (var itemsCount in ItemsCountVariants)
|
||||
{
|
||||
foreach (var targetBlockSize in BlockSizeVariants)
|
||||
{
|
||||
if (!IsValidBlockSize(itemsCount, targetBlockSize))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
yield return new object[] { itemsCount, targetBlockSize };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> TargetDataVariants => GetTargetDataVariants();
|
||||
|
||||
private static IEnumerable<object[]> CombineSourceDataWithBlockSize(IEnumerable<object[]> sourceData)
|
||||
{
|
||||
foreach (var testData in sourceData)
|
||||
{
|
||||
foreach (var targetBlockSize in BlockSizeVariants)
|
||||
{
|
||||
if (!IsValidBlockSize((long)testData[2], targetBlockSize))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
yield return new object[] { testData[0], testData[1], testData[2], targetBlockSize };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static IEnumerable<object[]> CreateSourceDataVariants(long itemsCount, bool refType)
|
||||
{
|
||||
GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced, true, true);
|
||||
|
||||
switch (refType)
|
||||
{
|
||||
case false:
|
||||
long[] testData = CreateTestData(itemsCount).ToArray();
|
||||
|
||||
yield return new object[] { $"Array[{itemsCount}]", testData, itemsCount };
|
||||
yield return new object[] { $"ICollection[{itemsCount}]", testData, itemsCount };
|
||||
yield return new object[] { $"ICollection<T>[{itemsCount}]", testData, itemsCount };
|
||||
yield return new object[] { $"IEnumerable[{itemsCount}]", testData, itemsCount };
|
||||
yield return new object[] { $"IEnumerable<T>[{itemsCount}] without non-enumerated count", new EnumerableWithoutCount<long>(testData), itemsCount };
|
||||
yield return new object[] { $"IList<T>[{itemsCount}]", new CustomIList<long>(testData), itemsCount };
|
||||
yield return new object[] { $"IReadOnlyList<T>[{itemsCount}])", testData, itemsCount };
|
||||
yield return new object[] { $"List<T>[{itemsCount}]", testData.ToList(), itemsCount };
|
||||
yield return new object[] { $"ReadOnlySpan<T>[{itemsCount}]", testData, itemsCount };
|
||||
yield return new object[] { $"RecyclableList<T>[{itemsCount}]", testData.ToRecyclableList(), itemsCount };
|
||||
|
||||
foreach (var sourceBlockSize in BlockSizeVariants)
|
||||
{
|
||||
if (!IsValidBlockSize(itemsCount, sourceBlockSize))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
yield return new object[]
|
||||
{
|
||||
$"RecyclableLongList<T>[itemsCount: {itemsCount}, minBlockSize: {sourceBlockSize}]",
|
||||
testData.ToRecyclableLongList(sourceBlockSize),
|
||||
itemsCount
|
||||
};
|
||||
}
|
||||
|
||||
yield return new object[] { $"Span<T>[{itemsCount}]", testData, itemsCount };
|
||||
yield return new object[] { $"T[{itemsCount}]", testData, itemsCount };
|
||||
break;
|
||||
|
||||
case true:
|
||||
IEnumerable<object> testRefData = CreateRefTestData(itemsCount).ToArray();
|
||||
|
||||
yield return new object[] { $"Array[{itemsCount}]", testRefData, itemsCount };
|
||||
yield return new object[] { $"ICollection(itemsCount: {itemsCount}", testRefData, itemsCount };
|
||||
yield return new object[] { $"ICollection<T>(itemsCount: {itemsCount}", testRefData, itemsCount };
|
||||
yield return new object[] { $"IEnumerable(itemsCount: {itemsCount})", testRefData, itemsCount };
|
||||
yield return new object[] { $"IEnumerable<T>(itemsCount: {itemsCount}) without non-enumerated count", new EnumerableWithoutCount<object>(testRefData), itemsCount };
|
||||
yield return new object[] { $"IList<T>(itemsCount: {itemsCount})", new CustomIList<object>(testRefData), itemsCount };
|
||||
yield return new object[] { $"IReadOnlyList<T>(itemsCount: {itemsCount})", testRefData, itemsCount };
|
||||
yield return new object[] { $"List<T>(itemsCount: {itemsCount}", testRefData.ToList(), itemsCount };
|
||||
yield return new object[] { $"ReadOnlySpan<T>[{itemsCount}]", testRefData, itemsCount };
|
||||
yield return new object[] { $"RecyclableList<T>(itemsCount: {itemsCount})", testRefData.ToRecyclableList(), itemsCount };
|
||||
|
||||
foreach (var sourceBlockSize in BlockSizeVariants)
|
||||
{
|
||||
if (!IsValidBlockSize(itemsCount, sourceBlockSize))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
yield return new object[]
|
||||
{
|
||||
$"RecyclableLongList<T>(itemsCount: {itemsCount}, minBlockSize: {sourceBlockSize})",
|
||||
testRefData.ToRecyclableLongList(sourceBlockSize),
|
||||
itemsCount
|
||||
};
|
||||
}
|
||||
|
||||
yield return new object[] { $"Span<T>[{itemsCount}]", testRefData, itemsCount };
|
||||
yield return new object[] { $"T[{itemsCount}]", testRefData, itemsCount };
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private static IEnumerable<object[]> CreateSourceDataVariants(bool refType)
|
||||
{
|
||||
foreach (var itemsCount in ItemsCountVariants)
|
||||
{
|
||||
foreach (var variant in CreateSourceDataVariants(itemsCount, refType))
|
||||
{
|
||||
yield return variant;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> EmptySourceDataVariants => CreateSourceDataVariants(0, false);
|
||||
public static IEnumerable<object[]> SourceDataVariants => CreateSourceDataVariants(false);
|
||||
public static IEnumerable<object[]> SourceDataWithItemIndexVariants
|
||||
{
|
||||
get
|
||||
{
|
||||
foreach (var testCase in CreateSourceDataVariants(false).Where(testCase => (long)testCase[2] > 0))
|
||||
{
|
||||
var itemIndexes = CreateItemIndexVariants((long)testCase[2], RecyclableDefaults.BlockSize).ToArray();
|
||||
yield return new object[] { testCase[0], testCase[1], testCase[2], itemIndexes };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> SourceRefDataWithItemIndexVariants
|
||||
{
|
||||
get
|
||||
{
|
||||
IEnumerable<object[]> testCases = CreateSourceDataVariants(true).Where(testCase => (long)testCase[2] > 0);
|
||||
foreach (var testCase in testCases)
|
||||
{
|
||||
var itemIndexes = CreateItemIndexVariants((long)testCase[2], RecyclableDefaults.BlockSize).ToArray();
|
||||
|
||||
yield return new object[] { testCase[0], testCase[1], testCase[2], itemIndexes };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> SourceDataWithBlockSizeVariants => CombineSourceDataWithBlockSize(SourceDataVariants);
|
||||
public static IEnumerable<object[]> SourceRefDataVariants => CreateSourceDataVariants(true);
|
||||
public static IEnumerable<object[]> SourceRefDataWithBlockSizeVariants { get; } = CombineSourceDataWithBlockSize(SourceRefDataVariants);
|
||||
|
||||
private static IEnumerable<long> _initialItemIndexVariants => new long[] { 0, 1, 2, 3, 4, 5 };
|
||||
private static IEnumerable<long> CreateItemIndexVariants(long itemsCount, int blockSize)
|
||||
{
|
||||
IEnumerable<long> primes = _initialItemIndexVariants.Concat(
|
||||
_initialItemIndexVariants.SelectMany(index => new long[] { blockSize - index, blockSize + index })
|
||||
//new long[] { blockSize - 3, blockSize - 2, blockSize - 1, blockSize, blockSize + 1, blockSize + 2, blockSize + 3 }
|
||||
).ToArray();
|
||||
|
||||
IEnumerable<long> second = Prime.Numbers.StartingAt(7)
|
||||
.TakeUntil(prime =>
|
||||
prime > ((blockSize * 2) - 1) ||
|
||||
prime >= itemsCount
|
||||
);
|
||||
|
||||
primes = primes.Concat(second).ToArray();
|
||||
|
||||
primes = primes.Concat(
|
||||
primes.Select(index => itemsCount - index - 1)
|
||||
)
|
||||
.Where(index => itemsCount > 0 && index >= 0 && index < itemsCount).ToArray()
|
||||
.Distinct().ToArray();
|
||||
|
||||
return primes;
|
||||
|
||||
//IEnumerable<long> CreateItemIndexVariants()
|
||||
//{
|
||||
//if (itemsCount > 0)
|
||||
//{
|
||||
// yield return 0;
|
||||
//}
|
||||
|
||||
//foreach (long prime in primes)
|
||||
//{
|
||||
// yield return prime;
|
||||
|
||||
// long index = itemsCount - prime;
|
||||
// if (index >= 0)
|
||||
// {
|
||||
// yield return index;
|
||||
// }
|
||||
//}
|
||||
|
||||
//for (long index = itemsCount - (blockSize * 2) - 1; index < itemsCount; index++)
|
||||
//{
|
||||
// if (index >= 0)
|
||||
// {
|
||||
// yield return index;
|
||||
// }
|
||||
//}
|
||||
|
||||
//if ((blockSize / 16 * 16) + 1 < itemsCount)
|
||||
//{
|
||||
// yield return (blockSize / 16 * 16) + 1;
|
||||
//}
|
||||
//}
|
||||
|
||||
//return CreateItemIndexVariants();
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> CombineSourceRefDataWithBlockSizeWithItemIndex(bool refType)
|
||||
{
|
||||
IEnumerable<object[]> sourceData = refType switch
|
||||
{
|
||||
false => SourceDataWithBlockSizeVariants,
|
||||
true => SourceRefDataWithBlockSizeVariants
|
||||
};
|
||||
|
||||
foreach (var testCase in sourceData)
|
||||
{
|
||||
long itemsCount = (long)testCase[2];
|
||||
if (itemsCount == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
long[] itemIndexes = CreateItemIndexVariants(itemsCount, (int)testCase[3])
|
||||
.Where(_ => IsValidBlockSize((long)testCase[2], (int)testCase[3]))
|
||||
.ToArray();
|
||||
|
||||
yield return new object[] { testCase[0], testCase[1], (long)testCase[2], (int)testCase[3], itemIndexes };
|
||||
}
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> SourceDataWithBlockSizeWithItemIndexVariants { get; } = CombineSourceRefDataWithBlockSizeWithItemIndex(false);
|
||||
public static IEnumerable<object[]> SourceRefDataWithBlockSizeWithItemIndexVariants { get; } = CombineSourceRefDataWithBlockSizeWithItemIndex(true);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using FluentAssertions;
|
||||
using Recyclable.Collections;
|
||||
using Recyclable.Collections.TestData;
|
||||
using Recyclable.Collections.Linq;
|
||||
using System.Collections;
|
||||
using System.Numerics;
|
||||
|
||||
Reference in new issue
Block a user