RecyclableLongList.Compatibility.List.Exists() implemented.
This commit is contained in:
1 parent
f77d5024c3
commit
02153bea2a
1 file changed
+46
-15
+46
-15
@@ -8,24 +8,55 @@ namespace Recyclable.Collections
|
|||||||
{
|
{
|
||||||
public static bool Exists<T>(this RecyclableLongList<T> list, Predicate<T> match)
|
public static bool Exists<T>(this RecyclableLongList<T> list, Predicate<T> match)
|
||||||
{
|
{
|
||||||
//int sourceItemsCount = list._count;
|
if (list._longCount == 0)
|
||||||
//if (sourceItemsCount == 0)
|
{
|
||||||
//{
|
return false;
|
||||||
// return false;
|
}
|
||||||
//}
|
|
||||||
|
|
||||||
//ReadOnlySpan<T> sourceSpan = list._memoryBlock;
|
int blockIndex = 0,
|
||||||
//for (var itemIndex = 0; itemIndex < sourceItemsCount; itemIndex++)
|
blockSize = list._blockSize;
|
||||||
//{
|
ReadOnlySpan<T[]> sourceMemoryBlocksSpan = list._memoryBlocks;
|
||||||
// if (match(sourceSpan[itemIndex]))
|
ReadOnlySpan<T> sourceMemoryBlockSpan = sourceMemoryBlocksSpan[0];
|
||||||
// {
|
var itemIndex = 0;
|
||||||
// return true;
|
int lastBlockWithData = list._lastBlockWithData;
|
||||||
// }
|
while (blockIndex < lastBlockWithData)
|
||||||
//}
|
{
|
||||||
|
if (match(sourceMemoryBlockSpan[itemIndex]))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
//return false;
|
if (itemIndex + 1 == blockSize)
|
||||||
|
{
|
||||||
|
itemIndex = 0;
|
||||||
|
blockIndex++;
|
||||||
|
sourceMemoryBlockSpan = sourceMemoryBlocksSpan[blockIndex];
|
||||||
|
|
||||||
throw new NotImplementedException();
|
if (blockIndex == lastBlockWithData)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
itemIndex++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (blockIndex == lastBlockWithData)
|
||||||
|
{
|
||||||
|
// We're re-using another variable for better performance
|
||||||
|
lastBlockWithData = list._nextItemIndex > 0 ? list._nextItemIndex : blockSize;
|
||||||
|
while (itemIndex < lastBlockWithData)
|
||||||
|
{
|
||||||
|
if (match(sourceMemoryBlockSpan[itemIndex++]))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static T? Find<T>(this RecyclableLongList<T> list, Predicate<T> match)
|
public static T? Find<T>(this RecyclableLongList<T> list, Predicate<T> match)
|
||||||
|
|||||||
Reference in new issue
Block a user