Mocks for desired RecyclableLongList compatibility methods added.

This commit is contained in:
mlemanczyk committed 2023-10-22 14:37:26 +02:00
1 parent 896e2d4000
commit d31fc31384
5 files changed
+2173

No files matched your search

@@ -0,0 +1,296 @@
// Ignore Spelling: zzz
using System.Numerics;
namespace Recyclable.Collections
{
#pragma warning disable IDE1006 // This intentional so that it shows at the end of IntelliSense list
public static class zzzRecyclableLongListCompatibilityListFind
#pragma warning restore IDE1006 // Naming Styles
{
public static bool Exists<T>(this RecyclableLongList<T> list, Predicate<T> match)
{
//int sourceItemsCount = list._count;
//if (sourceItemsCount == 0)
//{
// return false;
//}
//ReadOnlySpan<T> sourceSpan = list._memoryBlock;
//for (var itemIndex = 0; itemIndex < sourceItemsCount; itemIndex++)
//{
// if (match(sourceSpan[itemIndex]))
// {
// return true;
// }
//}
//return false;
throw new NotImplementedException();
}
public static T? Find<T>(this RecyclableLongList<T> list, Predicate<T> match)
{
//int sourceItemsCount = list._count;
//if (sourceItemsCount == 0)
//{
// return default;
//}
//ReadOnlySpan<T> sourceSpan = list._memoryBlock;
//for (var itemIndex = 0; itemIndex < sourceItemsCount; itemIndex++)
//{
// if (match(sourceSpan[itemIndex]))
// {
// return sourceSpan[itemIndex];
// }
//}
//return default;
throw new NotImplementedException();
}
public static RecyclableList<T> FindAll<T>(this RecyclableLongList<T> list, Predicate<T> match)
{
//int sourceItemsCount = list._count;
//if (sourceItemsCount == 0)
//{
// return new();
//}
//ReadOnlySpan<T> sourceSpan = list._memoryBlock;
//RecyclableList<T> result = new(sourceItemsCount >> 3);
//Span<T> resultSpan = result._memoryBlock;
//int capacity = result._capacity,
// resultItemsCount = 0;
//for (var itemIndex = 0; itemIndex < sourceItemsCount; itemIndex++)
//{
// if (match(sourceSpan[itemIndex]))
// {
// if (resultItemsCount + 1 > capacity)
// {
// capacity = checked((int)BitOperations.RoundUpToPowerOf2((uint)resultItemsCount + 1));
// _ = RecyclableListHelpers<T>.EnsureCapacity(result, resultItemsCount, capacity);
// resultSpan = result._memoryBlock;
// }
// resultSpan[resultItemsCount++] = sourceSpan[itemIndex];
// }
//}
//result._capacity = capacity;
//result._count = resultItemsCount;
//return result;
throw new NotImplementedException();
}
public static RecyclableList<int> FindAllIndexes<T>(this RecyclableLongList<T> list, Predicate<T> match)
{
//int sourceItemsCount = list._count;
//if (sourceItemsCount == 0)
//{
// return new();
//}
//ReadOnlySpan<T> sourceSpan = list._memoryBlock;
//RecyclableList<int> result = new(sourceItemsCount >> 3);
//Span<int> resultSpan = result._memoryBlock;
//int capacity = result._capacity,
// resultItemsCount = 0;
//for (var itemIndex = 0; itemIndex < sourceItemsCount; itemIndex++)
//{
// if (match(sourceSpan[itemIndex]))
// {
// if (resultItemsCount + 1 > capacity)
// {
// capacity = checked((int)BitOperations.RoundUpToPowerOf2((uint)resultItemsCount + 1));
// _ = RecyclableListHelpers<int>.EnsureCapacity(result, resultItemsCount, capacity);
// resultSpan = result._memoryBlock;
// }
// resultSpan[resultItemsCount++] = itemIndex;
// }
//}
//result._capacity = capacity;
//result._count = resultItemsCount;
//return result;
throw new NotImplementedException();
}
public static int FindIndex<T>(this RecyclableLongList<T> list, int startIndex, int count, Predicate<T> match)
{
//int sourceItemsCount = Math.Min(startIndex + count, list._count);
//if (sourceItemsCount == 0 || startIndex >= sourceItemsCount)
//{
// return RecyclableDefaults.ItemNotFoundIndex;
//}
//ReadOnlySpan<T> sourceSpan = list._memoryBlock;
//for (var itemIndex = startIndex; itemIndex < sourceItemsCount; itemIndex++)
//{
// if (match(sourceSpan[itemIndex]))
// {
// return itemIndex;
// }
//}
//return RecyclableDefaults.ItemNotFoundIndex;
throw new NotImplementedException();
}
public static int FindIndex<T>(this RecyclableLongList<T> list, int startIndex, Predicate<T> match)
{
//int sourceItemsCount = list._count;
//if (sourceItemsCount == 0 || startIndex >= sourceItemsCount)
//{
// return RecyclableDefaults.ItemNotFoundIndex;
//}
//sourceItemsCount = Math.Min(sourceItemsCount, startIndex + sourceItemsCount);
//ReadOnlySpan<T> sourceSpan = list._memoryBlock;
//for (var itemIndex = startIndex; itemIndex < sourceItemsCount; itemIndex++)
//{
// if (match(sourceSpan[itemIndex]))
// {
// return itemIndex;
// }
//}
//return RecyclableDefaults.ItemNotFoundIndex;
throw new NotImplementedException();
}
public static int FindIndex<T>(this RecyclableLongList<T> list, Predicate<T> match)
{
//int sourceItemsCount = list._count;
//if (sourceItemsCount == 0)
//{
// return RecyclableDefaults.ItemNotFoundIndex;
//}
//ReadOnlySpan<T> sourceSpan = list._memoryBlock;
//for (var itemIndex = 0; itemIndex < sourceItemsCount; itemIndex++)
//{
// if (match(sourceSpan[itemIndex]))
// {
// return itemIndex;
// }
//}
//return RecyclableDefaults.ItemNotFoundIndex;
throw new NotImplementedException();
}
public static T? FindLast<T>(this RecyclableLongList<T> list, Predicate<T> match)
{
//if (list._count == 0)
//{
// return default;
//}
//ReadOnlySpan<T> sourceSpan = list._memoryBlock;
//for (var itemIndex = list._count - 1; itemIndex >= 0; itemIndex--)
//{
// if (match(sourceSpan[itemIndex]))
// {
// return sourceSpan[itemIndex];
// }
//}
//return default;
throw new NotImplementedException();
}
public static int FindLastIndex<T>(this RecyclableLongList<T> list, int startIndex, int count, Predicate<T> match)
{
//if (count == 0)
//{
// if (startIndex != -1)
// {
// ThrowHelper.ThrowArgumentOutOfRangeException_Index();
// }
//}
//else if (count < 0 || startIndex - count + 1 < 0)
//{
// ThrowHelper.ThrowArgumentOutOfRangeException_Count();
//}
//if (startIndex < 0)
//{
// return RecyclableDefaults.ItemNotFoundIndex;
//}
//int sourceItemsCount = count; // startIndex - count + 1 >= 0 ? count : startIndex + 1;
//if (sourceItemsCount == 0)
//{
// return RecyclableDefaults.ItemNotFoundIndex;
//}
//int lastItemIndex = startIndex - sourceItemsCount;
//ReadOnlySpan<T> sourceSpan = list._memoryBlock;
//for (var itemIndex = startIndex; itemIndex > lastItemIndex; itemIndex--)
//{
// if (match(sourceSpan[itemIndex]))
// {
// return itemIndex;
// }
//}
//return RecyclableDefaults.ItemNotFoundIndex;
throw new NotImplementedException();
}
public static int FindLastIndex<T>(this RecyclableLongList<T> list, int startIndex, Predicate<T> match)
{
//if (list._count == 0 || startIndex < 0)
//{
// return RecyclableDefaults.ItemNotFoundIndex;
//}
//ReadOnlySpan<T> sourceSpan = list._memoryBlock;
//for (var itemIndex = startIndex; itemIndex >= 0; itemIndex--)
//{
// if (match(sourceSpan[itemIndex]))
// {
// return itemIndex;
// }
//}
//return RecyclableDefaults.ItemNotFoundIndex;
throw new NotImplementedException();
}
public static int FindLastIndex<T>(this RecyclableLongList<T> list, Predicate<T> match)
{
//if (list._count == 0)
//{
// return RecyclableDefaults.ItemNotFoundIndex;
//}
//ReadOnlySpan<T> sourceSpan = list._memoryBlock;
//for (var itemIndex = list._count - 1; itemIndex >= 0; itemIndex--)
//{
// if (match(sourceSpan[itemIndex]))
// {
// return itemIndex;
// }
//}
//return RecyclableDefaults.ItemNotFoundIndex;
throw new NotImplementedException();
}
}
}
@@ -0,0 +1,39 @@
// Ignore Spelling: zzz
namespace Recyclable.Collections
{
#pragma warning disable IDE1006 // This intentional so that it shows at the end of IntelliSense list
public static class zzzRecyclableLongListCompatibilityListIndexOf
#pragma warning restore IDE1006 // Naming Styles
{
public static int IndexOf<T>(this RecyclableLongList<T> list, T item, int index)
//=> list._count != 0
// ? Array.IndexOf(list._memoryBlock, item, index, list._count - index)
// : RecyclableDefaults.ItemNotFoundIndex;
=> throw new NotImplementedException();
public static int IndexOf<T>(this RecyclableLongList<T> list, T item, int index, int count)
//=> list._count != 0
// ? Array.IndexOf(list._memoryBlock, item, index, count)
// : RecyclableDefaults.ItemNotFoundIndex;
=> throw new NotImplementedException();
public static int LastIndexOf<T>(this RecyclableLongList<T> list, T item)
//=> list._count != 0
// ? Array.LastIndexOf(list._memoryBlock, item, list._count - 1)
// : RecyclableDefaults.ItemNotFoundIndex;
=> throw new NotImplementedException();
public static int LastIndexOf<T>(this RecyclableLongList<T> list, T item, int index)
//=> list._count != 0
// ? Array.LastIndexOf(list._memoryBlock, item, index)
// : RecyclableDefaults.ItemNotFoundIndex;
=> throw new NotImplementedException();
public static int LastIndexOf<T>(this RecyclableLongList<T> list, T item, int index, int count)
//=> list._count != 0
// ? Array.LastIndexOf(list._memoryBlock, item, index, count)
// : RecyclableDefaults.ItemNotFoundIndex;
=> throw new NotImplementedException();
}
}
@@ -0,0 +1,420 @@
// Ignore Spelling: zzz
using System.Collections;
using System.Numerics;
using System.Runtime.CompilerServices;
namespace Recyclable.Collections
{
#pragma warning disable IDE1006 // This intentional so that it shows at the end of IntelliSense list
public static class zzzRecyclableLongListCompatibilityListInsertRange
#pragma warning restore IDE1006 // Naming Styles
{
private static void InsertRangeEnumerated<T>(this RecyclableLongList<T> list, int index, IEnumerable<T> items, int growByCount)
{
//var enumerator = items.GetEnumerator();
//if (!enumerator.MoveNext())
//{
// return;
//}
//int capacity = list._capacity,
// added = 0,
// available = capacity - list._count,
// i,
// movingBlockLength = list._count - index;
//T[] memoryBlock = list._memoryBlock;
//if (available > 0)
//{
// Array.Copy(memoryBlock, index, memoryBlock, capacity - movingBlockLength, movingBlockLength);
//}
//Span<T> memorySpan = memoryBlock;
//do
//{
// if (index + available + movingBlockLength > capacity)
// {
// var capacityBeforeIncrease = capacity;
// capacity = checked((int)BitOperations.RoundUpToPowerOf2((uint)(capacity + growByCount)));
// _ = RecyclableListHelpers<T>.EnsureCapacity(list, memoryBlock.Length, capacity);
// memorySpan = memoryBlock = list._memoryBlock;
// available = capacity - index - movingBlockLength;
// Array.Copy(memoryBlock, capacityBeforeIncrease - movingBlockLength, memoryBlock, capacity - movingBlockLength, movingBlockLength);
// }
// for (i = 0; i < available; i++)
// {
// memorySpan[index++] = enumerator.Current;
// if (!enumerator.MoveNext())
// {
// added++;
// break;
// }
// }
// added += i;
//}
//while (i == available);
//if (i != available)
//{
// Array.Copy(memoryBlock, capacity - movingBlockLength, memoryBlock, index, movingBlockLength);
// if (RecyclableList<T>._needsClearing)
// {
// Array.Clear(memoryBlock, capacity - movingBlockLength, movingBlockLength);
// }
//}
//list._count += added;
//list._capacity = capacity;
throw new NotImplementedException();
}
private static void InsertRangeWithKnownCount<T>(this RecyclableLongList<T> list, int index, IEnumerable<T> items, int currentItemsCount, int requiredAdditionalCapacity)
{
//list._capacity = RecyclableListHelpers<T>.EnsureCapacity(list, currentItemsCount, checked((int)BitOperations.RoundUpToPowerOf2((uint)(currentItemsCount + requiredAdditionalCapacity))));
//// TODO: Count should be requiredAdditionalCapacity, we need to move as many items as many we're inserting
//Array.Copy(list._memoryBlock, index, list._memoryBlock, index + requiredAdditionalCapacity, list._count - index);
//Span<T> memorySpan = list._memoryBlock;
//foreach (var item in items)
//{
// memorySpan[index++] = item;
//}
//list._count += requiredAdditionalCapacity;
//list._version++;
throw new NotImplementedException();
}
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
public static void InsertRange<T>(this RecyclableLongList<T> list, int index, in Array items)
{
//if (list._capacity < list._count + items.Length)
//{
// list._capacity = RecyclableListHelpers<T>.EnsureCapacity(list, list._count, checked((int)BitOperations.RoundUpToPowerOf2((uint)(list._count + items.Length))));
//}
//T[] memoryBlock = list._memoryBlock;
//// TODO: Count should be items.Count, we need to move as many items as many we're inserting
//Array.Copy(memoryBlock, index, memoryBlock, index + items.Length, list._count - index);
//Array.Copy(items, items.GetLowerBound(0), memoryBlock, index, items.Length);
//list._count += items.Length;
//list._version++;
throw new NotImplementedException();
}
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
public static void InsertRange<T>(this RecyclableLongList<T> list, int index, in T[] items)
{
//if (list._capacity < list._count + items.Length)
//{
// list._capacity = RecyclableListHelpers<T>.EnsureCapacity(list, list._count, checked((int)BitOperations.RoundUpToPowerOf2((uint)(list._count + items.Length))));
//}
//T[] memoryBlock = list._memoryBlock;
//// TODO: Count should be items.Count, we need to move as many items as many we're inserting
//Array.Copy(memoryBlock, index, memoryBlock, index + items.Length, list._count - index);
//new ReadOnlySpan<T>(items).CopyTo(new Span<T>(memoryBlock, index, items.Length));
//list._count += items.Length;
//list._version++;
throw new NotImplementedException();
}
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
public static void InsertRange<T>(this RecyclableLongList<T> list, int index, ReadOnlySpan<T> items)
{
//if (list._capacity < list._count + items.Length)
//{
// list._capacity = RecyclableListHelpers<T>.EnsureCapacity(list, list._count, checked((int)BitOperations.RoundUpToPowerOf2((uint)(list._count + items.Length))));
//}
//T[] memoryBlock = list._memoryBlock;
//// TODO: Count should be items.Count, we need to move as many items as many we're inserting
//Array.Copy(memoryBlock, index, memoryBlock, index + items.Length, list._count - index);
//items.CopyTo(new Span<T>(memoryBlock, index, items.Length));
//list._count += items.Length;
//list._version++;
throw new NotImplementedException();
}
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
public static void InsertRange<T>(this RecyclableLongList<T> list, int index, Span<T> items)
{
//if (list._capacity < list._count + items.Length)
//{
// list._capacity = RecyclableListHelpers<T>.EnsureCapacity(list, list._count, checked((int)BitOperations.RoundUpToPowerOf2((uint)(list._count + items.Length))));
//}
//T[] memoryBlock = list._memoryBlock;
//// TODO: Count should be items.Count, we need to move as many items as many we're inserting
//Array.Copy(memoryBlock, index, memoryBlock, index + items.Length, list._count - index);
//items.CopyTo(new Span<T>(memoryBlock, index, items.Length));
//list._count += items.Length;
//list._version++;
throw new NotImplementedException();
}
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
public static void InsertRange<T>(this RecyclableLongList<T> list, int index, List<T> items)
{
//if (list._capacity < list._count + items.Count)
//{
// list._capacity = RecyclableListHelpers<T>.EnsureCapacity(list, list._count, checked((int)BitOperations.RoundUpToPowerOf2((uint)(list._count + items.Count))));
//}
//T[] memoryBlock = list._memoryBlock;
//// TODO: Count should be items.Count, we need to move as many items as many we're inserting
//Array.Copy(memoryBlock, index, memoryBlock, index + items.Count, list._count - index);
//items.CopyTo(memoryBlock, index);
//list._count += items.Count;
//list._version++;
throw new NotImplementedException();
}
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
public static void InsertRange<T>(this RecyclableLongList<T> list, int index, ICollection items)
{
//if (list._capacity < list._count + items.Count)
//{
// list._capacity = RecyclableListHelpers<T>.EnsureCapacity(list, list._count, checked((int)BitOperations.RoundUpToPowerOf2((uint)(list._count + items.Count))));
//}
//T[] memoryBlock = list._memoryBlock;
//// TODO: Count should be items.Count, we need to move as many items as many we're inserting
//Array.Copy(memoryBlock, index, memoryBlock, index + items.Count, list._count - index);
//items.CopyTo(list._memoryBlock, index);
//list._count += items.Count;
//list._version++;
throw new NotImplementedException();
}
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
public static void InsertRange<T>(this RecyclableLongList<T> list, int index, ICollection<T> items)
{
//if (list._capacity < list._count + items.Count)
//{
// list._capacity = RecyclableListHelpers<T>.EnsureCapacity(list, list._count, checked((int)BitOperations.RoundUpToPowerOf2((uint)(list._count + items.Count))));
//}
//T[] memoryBlock = list._memoryBlock;
//// TODO: Count should be items.Count, we need to move as many items as many we're inserting
//Array.Copy(memoryBlock, index, memoryBlock, index + items.Count, list._count - index);
//items.CopyTo(memoryBlock, index);
//list._count += items.Count;
//list._version++;
throw new NotImplementedException();
}
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
public static void InsertRange<T>(this RecyclableLongList<T> list, int index, RecyclableList<T> items)
{
//if (list._capacity < list._count + items._count)
//{
// list._capacity = RecyclableListHelpers<T>.EnsureCapacity(list, list._count, checked((int)BitOperations.RoundUpToPowerOf2((uint)(list._count + items._count))));
//}
//T[] memoryBlock = list._memoryBlock;
//// TODO: Count should be items.Count, we need to move as many items as many we're inserting
//Array.Copy(memoryBlock, index, memoryBlock, index + items.Count, list._count - index);
//new ReadOnlySpan<T>(items._memoryBlock, 0, items._count).CopyTo(new(list._memoryBlock, index, items._count));
//list._count += items._count;
//list._version++;
throw new NotImplementedException();
}
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
public static void InsertRange<T>(this RecyclableLongList<T> list, int index, RecyclableLongList<T> items)
{
//if (items._longCount == 0)
//{
// return;
//}
//int oldCount = list._count;
//long sourceItemsCount = items._longCount;
//if (oldCount + sourceItemsCount > int.MaxValue)
//{
// ThrowHelper.ThrowArgumentOutOfRangeException(nameof(items), $"The total number of items in source and target table exceeds the maximum capacity of {nameof(RecyclableList<T>)}, equal {int.MaxValue}. Please consider using {nameof(RecyclableLongList<T>)}, instead");
//}
//int targetCapacity = oldCount + (int)sourceItemsCount;
//if (list._capacity < targetCapacity)
//{
// list._capacity = RecyclableListHelpers<T>.EnsureCapacity(list, oldCount, checked((int)BitOperations.RoundUpToPowerOf2((uint)targetCapacity)));
//}
//T[] memoryBlock = list._memoryBlock;
//Array.Copy(memoryBlock, index, memoryBlock, index + items.Count, oldCount - index);
//Span<T> targetSpan = new(list._memoryBlock, index, list._capacity - index),
// itemsSpan;
//int blockIndex,
// sourceBlockSize = items._blockSize,
// lastBlockIndex = (int)(sourceItemsCount >> items._blockSizePow2BitShift) - 1;
//for (blockIndex = 0; blockIndex <= lastBlockIndex; blockIndex++)
//{
// itemsSpan = new(items._memoryBlocks[blockIndex], 0, sourceBlockSize);
// itemsSpan.CopyTo(targetSpan);
// targetSpan = targetSpan[sourceBlockSize..];
//}
//if (blockIndex == 0)
//{
// itemsSpan = new(items._memoryBlocks[blockIndex], 0, (int)sourceItemsCount);
// itemsSpan.CopyTo(targetSpan);
//}
//else if (blockIndex <= items._lastBlockWithData)
//{
// itemsSpan = new(items._memoryBlocks[blockIndex], 0, items._nextItemIndex > 0 ? items._nextItemIndex : sourceBlockSize);
// itemsSpan.CopyTo(targetSpan);
//}
//list._count = targetCapacity;
//list._version++;
throw new NotImplementedException();
}
public static void InsertRange<T>(this RecyclableLongList<T> list, int index, IEnumerable items, int growByCount = RecyclableDefaults.MinPooledArrayLength)
{
//var enumerator = items.GetEnumerator();
//if (!enumerator.MoveNext())
//{
// return;
//}
//int capacity = list._capacity,
// added = 0,
// available = capacity - list._count,
// i,
// movingBlockLength = list._count - index;
//T[] memoryBlock = list._memoryBlock;
//if (available > 0)
//{
// Array.Copy(memoryBlock, index, memoryBlock, capacity - movingBlockLength, movingBlockLength);
//}
//Span<T> memorySpan = memoryBlock;
//do
//{
// if (index + available + movingBlockLength > capacity)
// {
// var capacityBeforeIncrease = capacity;
// capacity = checked((int)BitOperations.RoundUpToPowerOf2((uint)(capacity + growByCount)));
// _ = RecyclableListHelpers<T>.EnsureCapacity(list, memoryBlock.Length, capacity);
// memorySpan = memoryBlock = list._memoryBlock;
// available = capacity - index - movingBlockLength;
// Array.Copy(memoryBlock, capacityBeforeIncrease - movingBlockLength, memoryBlock, capacity - movingBlockLength, movingBlockLength);
// }
// for (i = 0; i < available; i++)
// {
// memorySpan[index++] = (T)enumerator.Current;
// if (!enumerator.MoveNext())
// {
// added++;
// break;
// }
// }
// added += i;
//}
//while (i == available);
//if (i != available)
//{
// Array.Copy(memoryBlock, capacity - movingBlockLength, memoryBlock, index, movingBlockLength);
// if (RecyclableList<T>._needsClearing)
// {
// Array.Clear(memoryBlock, capacity - movingBlockLength, movingBlockLength);
// }
//}
//list._count += added;
//list._capacity = capacity;
throw new NotImplementedException();
}
public static void InsertRange<T>(this RecyclableLongList<T> list, int index, IReadOnlyList<T> items)
{
//int sourceItemsCount = items.Count;
//if (list._capacity < list._count + sourceItemsCount)
//{
// list._capacity = RecyclableListHelpers<T>.EnsureCapacity(list, list._count, checked((int)BitOperations.RoundUpToPowerOf2((uint)(list._count + sourceItemsCount))));
//}
//Array.Copy(list._memoryBlock, index, list._memoryBlock, index + sourceItemsCount, Math.Min(list.Count - index, sourceItemsCount));
//Span<T> memorySpan = new(list._memoryBlock, index, sourceItemsCount);
//for (var sourceItemIndex = 0; sourceItemIndex < sourceItemsCount; sourceItemIndex++)
//{
// memorySpan[sourceItemIndex] = items[sourceItemIndex];
//}
//list._count += sourceItemsCount;
throw new NotImplementedException();
}
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
public static void InsertRange<T>(this RecyclableLongList<T> list, int index, IEnumerable<T> items, int growByCount = RecyclableDefaults.MinPooledArrayLength)
{
//if (items is RecyclableList<T> sourceRecyclableList)
//{
// InsertRange(list, index, sourceRecyclableList);
//}
//else if (items is RecyclableLongList<T> sourceRecyclableLongList)
//{
// InsertRange(list, index, sourceRecyclableLongList);
//}
//else if (items is T[] sourceArray)
//{
// InsertRange(list, index, sourceArray);
//}
//else if (items is Array sourceArrayWithObjects)
//{
// InsertRange(list, index, sourceArrayWithObjects);
//}
//else if (items is List<T> sourceList)
//{
// InsertRange(list, index, sourceList);
//}
//else if (items is ICollection<T> sourceICollection)
//{
// InsertRange(list, index, sourceICollection);
//}
//else if (items is ICollection sourceICollectionWithObjects)
//{
// InsertRange(list, index, sourceICollectionWithObjects);
//}
//else if (items is IReadOnlyList<T> sourceIReadOnlyList)
//{
// InsertRange(list, index, sourceIReadOnlyList);
//}
//else if (items.TryGetNonEnumeratedCount(out var requiredAdditionalCapacity) && requiredAdditionalCapacity != 0)
//{
// InsertRangeWithKnownCount(list, index, items, list._count, requiredAdditionalCapacity);
//}
//else
//{
// InsertRangeEnumerated(list, index, items, growByCount);
//}
throw new NotImplementedException();
}
}
}
@@ -0,0 +1,289 @@
// Ignore Spelling: zzz
using System.Collections.ObjectModel;
using System.Numerics;
using System.Runtime.CompilerServices;
using Recyclable.Collections.Pools;
namespace Recyclable.Collections
{
#pragma warning disable IDE1006 // This intentional so that it shows at the end of IntelliSense list
public static class zzzRecyclableLongListCompatibilityList
#pragma warning restore IDE1006 // Naming Styles
{
public static ReadOnlyCollection<T> AsReadOnly<T>(this RecyclableLongList<T> list) => new(list);
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static int BinarySearch<T>(this RecyclableLongList<T> list, T item)
{
if (list._longCount == 0)
{
return RecyclableDefaults.ItemNotFoundIndex;
}
int blockIndex = 0,
blockSize = list._blockSize,
itemIndex;
var comparer = Comparer<T>.Default;
var lastFullBlockIndex = list._lastBlockWithData;
Span<T[]> memoryBlocksSpan = list._memoryBlocks;
while (blockIndex < lastFullBlockIndex)
{
itemIndex = new Span<T>(memoryBlocksSpan[blockIndex], 0, blockSize).BinarySearch(item, comparer);
if (itemIndex >= 0)
{
return (blockIndex << list._blockSizePow2BitShift) + itemIndex;
}
blockIndex++;
}
itemIndex = new Span<T>(memoryBlocksSpan[blockIndex], 0, list._nextItemIndex != 0 ? list._nextItemIndex : blockSize).BinarySearch(item, comparer);
return itemIndex >= 0 ? (blockIndex << list._blockSizePow2BitShift) + itemIndex : RecyclableDefaults.ItemNotFoundIndex;
}
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static int BinarySearch<T>(this RecyclableLongList<T> list, T item, IComparer<T>? comparer)
//=> Array.BinarySearch(list._memoryBlock, 0, list._count, item, comparer);
=> throw new NotImplementedException();
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static int BinarySearch<T>(this RecyclableLongList<T> list, int index, int count, T item, IComparer<T>? comparer)
//=> Array.BinarySearch(list._memoryBlock, index, count, item, comparer);
=> throw new NotImplementedException();
public static RecyclableList<TOutput> ConvertAll<T, TOutput>(this RecyclableLongList<T> list, Converter<T, TOutput> converter)
{
//int itemsCount = list._count;
//if (itemsCount == 0)
//{
// return new();
//}
//RecyclableList<TOutput> result = new(itemsCount);
//TOutput[] resultSpan = result._memoryBlock;
//ReadOnlySpan<T> sourceSpan = list._memoryBlock;
//for (int bufferIndex = 0; bufferIndex < itemsCount; bufferIndex++)
//{
// resultSpan[bufferIndex] = converter(sourceSpan[bufferIndex]);
//}
//result._count = itemsCount;
//return result;
throw new NotImplementedException();
}
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static void CopyTo<T>(this RecyclableLongList<T> list, T[] array)
//=> Array.Copy(list._memoryBlock, array, list._count);
=> throw new NotImplementedException();
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static void CopyTo<T>(this RecyclableLongList<T> list, int index, T[] array, int arrayIndex, int count)
//=> Array.Copy(list._memoryBlock, index, array, arrayIndex, count);
=> throw new NotImplementedException();
public static void ForEach<T>(this RecyclableLongList<T> list, Action<T> action)
{
//int sourceItemsCount = list._count;
//if (sourceItemsCount == 0)
//{
// return;
//}
//ReadOnlySpan<T> sourceSpan = list._memoryBlock;
//for (var itemIndex = 0; itemIndex < sourceItemsCount; itemIndex++)
//{
// action(sourceSpan[itemIndex]);
//}
throw new NotImplementedException();
}
public static RecyclableList<T> GetRange<T>(this RecyclableLongList<T> list, int index, int count)
{
//int sourceItemsCount = index + count <= list._count ? count : list._count - index;
//if (sourceItemsCount <= 0)
//{
// return new();
//}
//ReadOnlySpan<T> sourceSpan = list._memoryBlock;
//RecyclableList<T> result = new(sourceItemsCount);
//Span<T> targetSpan = result._memoryBlock;
//int resultItemsCount = 0;
//sourceItemsCount += index;
//for (var itemIndex = index; itemIndex < sourceItemsCount; itemIndex++)
//{
// targetSpan[resultItemsCount++] = sourceSpan[itemIndex];
//}
//result._count = resultItemsCount;
//return result;
throw new NotImplementedException();
}
public static int RemoveAll<T>(this RecyclableLongList<T> list, Predicate<T> match)
{
//using var allIndexes = zzzRecyclableListCompatibilityListFind.FindAllIndexes(list, match);
//int foundItemsCount = allIndexes._count;
//if (foundItemsCount == 0)
//{
// return foundItemsCount;
//}
//for (int removed = 0; removed < foundItemsCount; removed++)
//{
// var indexToRemove = allIndexes[removed] - removed;
// Array.Copy(list._memoryBlock, indexToRemove + 1, list._memoryBlock, indexToRemove, list._count - indexToRemove - removed - 1);
//}
//if (RecyclableList<T>._needsClearing)
//{
// Array.Clear(list._memoryBlock, list._count - foundItemsCount, foundItemsCount);
//}
//list._count -= foundItemsCount;
//list._version++;
//return foundItemsCount;
throw new NotImplementedException();
}
public static void RemoveRange<T>(this RecyclableLongList<T> list, int index, int count)
{
//int oldCount = list._count;
//count = count - index + 1 <= oldCount ? count : oldCount - index + 1;
//if (count == 0)
//{
// return;
//}
//if (index + count < oldCount)
//{
// Array.Copy(list._memoryBlock, index + count, list._memoryBlock, index, oldCount - count - index);
//}
//if (RecyclableList<T>._needsClearing)
//{
// Array.Clear(list._memoryBlock, oldCount - count, count);
//}
//list._count -= count;
//list._version++;
throw new NotImplementedException();
}
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static void Reverse<T>(this RecyclableLongList<T> list)
{
//Array.Reverse(list._memoryBlock, 0, list._count);
//list._version++;
throw new NotImplementedException();
}
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static void Reverse<T>(this RecyclableLongList<T> list, int index, int count)
{
//Array.Reverse(list._memoryBlock, index, count);
//list._version++;
throw new NotImplementedException();
}
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static void Sort<T>(this RecyclableLongList<T> list)
{
//Array.Sort(list._memoryBlock, 0, list._count);
//list._version++;
throw new NotImplementedException();
}
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static void Sort<T>(this RecyclableLongList<T> list, Comparison<T> comparison)
{
//Array.Sort(list._memoryBlock, 0, list._count, new ComparisonToComparerAdapter<T>(comparison));
//list._version++;
throw new NotImplementedException();
}
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static void Sort<T>(this RecyclableLongList<T> list, IComparer<T>? comparer)
{
//Array.Sort(list._memoryBlock, 0, list._count, comparer);
//list._version++;
throw new NotImplementedException();
}
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static void Sort<T>(this RecyclableLongList<T> list, int index, int count, IComparer<T>? comparer)
{
//Array.Sort(list._memoryBlock, index, count, comparer);
//list._version++;
throw new NotImplementedException();
}
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static T[] ToArray<T>(this RecyclableLongList<T> list)
{
//T[] result = new T[list._count];
//new ReadOnlySpan<T>(list._memoryBlock, 0, list._count).CopyTo(result);
//return result;
throw new NotImplementedException();
}
public static void TrimExcess<T>(this RecyclableLongList<T> list)
{
//var requiredCapacity = list._count >= RecyclableDefaults.InitialCapacity ? list._count : RecyclableDefaults.InitialCapacity;
//T[] oldMemoryBlock = list._memoryBlock;
//T[] result = requiredCapacity >= RecyclableDefaults.MinPooledArrayLength && BitOperations.IsPow2(requiredCapacity)
// ? RecyclableArrayPool<T>.RentShared(requiredCapacity)
// : new T[requiredCapacity];
//new ReadOnlySpan<T>(oldMemoryBlock, 0, list._count).CopyTo(result);
//if (oldMemoryBlock.Length >= RecyclableDefaults.MinPooledArrayLength)
//{
// RecyclableArrayPool<T>.ReturnShared(oldMemoryBlock, RecyclableList<T>._needsClearing);
//}
//list._memoryBlock = result;
//list._capacity = requiredCapacity;
throw new NotImplementedException();
}
public static bool TrueForAll<T>(this RecyclableLongList<T> list, Predicate<T> match)
{
//int sourceItemsCount = list._count;
//if (sourceItemsCount == 0)
//{
// return false;
//}
//ReadOnlySpan<T> sourceSpan = list._memoryBlock;
//for (var itemIndex = 0; itemIndex < sourceItemsCount; itemIndex++)
//{
// if (!match(sourceSpan[itemIndex]))
// {
// return false;
// }
//}
//return true;
throw new NotImplementedException();
}
}
}