RecyclableLongList.Compatibility.List.FindAllIndexes() implemented. .FindAll() fixes.
This commit is contained in:
1 parent
3e66504e09
commit
95d497c903
1 file changed
+106
-30
+106
-30
@@ -116,7 +116,7 @@ namespace Recyclable.Collections
|
|||||||
if (fullBlocksItemsCount + targetItemIndex >= targetCapacity)
|
if (fullBlocksItemsCount + targetItemIndex >= targetCapacity)
|
||||||
{
|
{
|
||||||
targetCapacity = RecyclableLongList<T>.Helpers.Resize(result, blockSize, result._blockSizePow2BitShift, targetCapacity << 1);
|
targetCapacity = RecyclableLongList<T>.Helpers.Resize(result, blockSize, result._blockSizePow2BitShift, targetCapacity << 1);
|
||||||
resultMemoryBlocksSpan = new(list._memoryBlocks);
|
resultMemoryBlocksSpan = new(result._memoryBlocks);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (targetItemIndex == blockSize)
|
if (targetItemIndex == blockSize)
|
||||||
@@ -158,7 +158,7 @@ namespace Recyclable.Collections
|
|||||||
if (fullBlocksItemsCount + targetItemIndex >= targetCapacity)
|
if (fullBlocksItemsCount + targetItemIndex >= targetCapacity)
|
||||||
{
|
{
|
||||||
targetCapacity = RecyclableLongList<T>.Helpers.Resize(result, blockSize, result._blockSizePow2BitShift, targetCapacity << 1);
|
targetCapacity = RecyclableLongList<T>.Helpers.Resize(result, blockSize, result._blockSizePow2BitShift, targetCapacity << 1);
|
||||||
resultMemoryBlocksSpan = new(list._memoryBlocks);
|
resultMemoryBlocksSpan = new(result._memoryBlocks);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (targetItemIndex == blockSize)
|
if (targetItemIndex == blockSize)
|
||||||
@@ -191,40 +191,116 @@ namespace Recyclable.Collections
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static RecyclableList<int> FindAllIndexes<T>(this RecyclableLongList<T> list, Predicate<T> match)
|
public static RecyclableLongList<long> FindAllIndexes<T>(this RecyclableLongList<T> list, Predicate<T> match)
|
||||||
{
|
{
|
||||||
//int sourceItemsCount = list._count;
|
if (list._longCount == 0)
|
||||||
//if (sourceItemsCount == 0)
|
{
|
||||||
//{
|
return new();
|
||||||
// return new();
|
}
|
||||||
//}
|
|
||||||
|
|
||||||
//ReadOnlySpan<T> sourceSpan = list._memoryBlock;
|
int sourceBlockIndex = 0,
|
||||||
//RecyclableList<int> result = new(sourceItemsCount >> 3);
|
blockSize = list._blockSize,
|
||||||
//Span<int> resultSpan = result._memoryBlock;
|
targetBlockIndex = 0;
|
||||||
//int capacity = result._capacity,
|
var targetCapacity = Math.Max(list._longCount >> 3, RecyclableDefaults.InitialCapacity);
|
||||||
// resultItemsCount = 0;
|
if (!BitOperations.IsPow2(targetCapacity))
|
||||||
|
{
|
||||||
|
targetCapacity = checked((long)BitOperations.RoundUpToPowerOf2((ulong)targetCapacity));
|
||||||
|
}
|
||||||
|
|
||||||
//for (var itemIndex = 0; itemIndex < sourceItemsCount; itemIndex++)
|
RecyclableLongList<long> result = new(blockSize, targetCapacity);
|
||||||
//{
|
ReadOnlySpan<long[]> resultMemoryBlocksSpan = result._memoryBlocks;
|
||||||
// if (match(sourceSpan[itemIndex]))
|
Span<long> resultMemoryBlockSpan = resultMemoryBlocksSpan[0];
|
||||||
// {
|
ReadOnlySpan<T[]> sourceMemoryBlocksSpan = list._memoryBlocks;
|
||||||
// if (resultItemsCount + 1 > capacity)
|
ReadOnlySpan<T> sourceMemoryBlockSpan = sourceMemoryBlocksSpan[0];
|
||||||
// {
|
var sourceItemIndex = 0;
|
||||||
// capacity = checked((int)BitOperations.RoundUpToPowerOf2((uint)resultItemsCount + 1));
|
int lastBlockWithData = list._lastBlockWithData;
|
||||||
// _ = RecyclableListHelpers<int>.EnsureCapacity(result, resultItemsCount, capacity);
|
var targetItemIndex = 0;
|
||||||
// resultSpan = result._memoryBlock;
|
long sourceFullBlocksItemsCount = 0L,
|
||||||
// }
|
targetFullBlocksItemsCount = 0L;
|
||||||
|
while (sourceBlockIndex < lastBlockWithData)
|
||||||
|
{
|
||||||
|
var item = sourceMemoryBlockSpan[sourceItemIndex];
|
||||||
|
if (match(item))
|
||||||
|
{
|
||||||
|
if (targetFullBlocksItemsCount + targetItemIndex >= targetCapacity)
|
||||||
|
{
|
||||||
|
targetCapacity = RecyclableLongList<long>.Helpers.Resize(result, blockSize, result._blockSizePow2BitShift, targetCapacity << 1);
|
||||||
|
resultMemoryBlocksSpan = new(result._memoryBlocks);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (targetItemIndex == blockSize)
|
||||||
|
{
|
||||||
|
targetItemIndex = 0;
|
||||||
|
resultMemoryBlockSpan = resultMemoryBlocksSpan[++targetBlockIndex];
|
||||||
|
targetFullBlocksItemsCount += blockSize;
|
||||||
|
}
|
||||||
|
|
||||||
// resultSpan[resultItemsCount++] = itemIndex;
|
resultMemoryBlockSpan[targetItemIndex++] = sourceFullBlocksItemsCount + sourceItemIndex;
|
||||||
// }
|
}
|
||||||
//}
|
|
||||||
|
|
||||||
//result._capacity = capacity;
|
if (sourceItemIndex + 1 == blockSize)
|
||||||
//result._count = resultItemsCount;
|
{
|
||||||
//return result;
|
sourceItemIndex = 0;
|
||||||
|
sourceBlockIndex++;
|
||||||
|
sourceMemoryBlockSpan = sourceMemoryBlocksSpan[sourceBlockIndex];
|
||||||
|
sourceFullBlocksItemsCount += blockSize;
|
||||||
|
|
||||||
throw new NotImplementedException();
|
if (sourceBlockIndex == lastBlockWithData)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sourceItemIndex++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sourceBlockIndex == lastBlockWithData)
|
||||||
|
{
|
||||||
|
// We're re-using another variable for better performance
|
||||||
|
lastBlockWithData = list._nextItemIndex > 0 ? list._nextItemIndex : blockSize;
|
||||||
|
while (sourceItemIndex < lastBlockWithData)
|
||||||
|
{
|
||||||
|
var item = sourceMemoryBlockSpan[sourceItemIndex];
|
||||||
|
if (match(item))
|
||||||
|
{
|
||||||
|
if (targetFullBlocksItemsCount + targetItemIndex >= targetCapacity)
|
||||||
|
{
|
||||||
|
targetCapacity = RecyclableLongList<long>.Helpers.Resize(result, blockSize, result._blockSizePow2BitShift, targetCapacity << 1);
|
||||||
|
resultMemoryBlocksSpan = new(result._memoryBlocks);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (targetItemIndex == blockSize)
|
||||||
|
{
|
||||||
|
targetItemIndex = 0;
|
||||||
|
resultMemoryBlockSpan = resultMemoryBlocksSpan[++targetBlockIndex];
|
||||||
|
targetFullBlocksItemsCount += blockSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
resultMemoryBlockSpan[targetItemIndex++] = sourceFullBlocksItemsCount + sourceItemIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
sourceItemIndex++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (targetItemIndex == blockSize)
|
||||||
|
{
|
||||||
|
result._nextItemBlockIndex = targetBlockIndex + 1;
|
||||||
|
result._nextItemIndex = 0;
|
||||||
|
result._lastBlockWithData = targetBlockIndex;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
result._nextItemBlockIndex = targetBlockIndex;
|
||||||
|
result._nextItemIndex = targetItemIndex;
|
||||||
|
result._lastBlockWithData = targetBlockIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
result._longCount = targetFullBlocksItemsCount + targetItemIndex;
|
||||||
|
result._capacity = targetCapacity;
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int FindIndex<T>(this RecyclableLongList<T> list, int startIndex, int count, Predicate<T> match)
|
public static int FindIndex<T>(this RecyclableLongList<T> list, int startIndex, int count, Predicate<T> match)
|
||||||
|
|||||||
Reference in new issue
Block a user