mirror of
https://git.ryujinx.app/ryubing/ryujinx.git
synced 2025-06-28 00:16:23 +02:00
remove duplicate function
BinarySearchLeftEdge(ulong address) matches BinarySearch(ulong address), so the former is not needed
This commit is contained in:
parent
14a542ec5f
commit
bc37866ac9
1 changed files with 3 additions and 72 deletions
|
@ -93,7 +93,7 @@ namespace Ryujinx.Memory.Range
|
|||
/// <returns>True if the item was located and updated, false otherwise</returns>
|
||||
protected bool Update(T item)
|
||||
{
|
||||
int index = BinarySearchLeftEdge(item.Address);
|
||||
int index = BinarySearch(item.Address);
|
||||
|
||||
if (index >= 0)
|
||||
{
|
||||
|
@ -184,7 +184,7 @@ namespace Ryujinx.Memory.Range
|
|||
/// <returns>True if the item was removed, or false if it was not found</returns>
|
||||
public bool Remove(T item)
|
||||
{
|
||||
int index = BinarySearchLeftEdge(item.Address);
|
||||
int index = BinarySearch(item.Address);
|
||||
|
||||
if (index >= 0)
|
||||
{
|
||||
|
@ -264,7 +264,7 @@ namespace Ryujinx.Memory.Range
|
|||
|
||||
ulong endAddress = address + size;
|
||||
|
||||
int startIndex = BinarySearchLeftEdge(address);
|
||||
int startIndex = BinarySearch(address);
|
||||
if (startIndex < 0)
|
||||
startIndex = ~startIndex;
|
||||
int endIndex = -1;
|
||||
|
@ -444,75 +444,6 @@ namespace Ryujinx.Memory.Range
|
|||
return ~left;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Performs binary search on the internal list of items.
|
||||
/// </summary>
|
||||
/// <param name="address">Address to find</param>
|
||||
/// <returns>List index of the left-most item that overlaps, or complement index of nearest item with lower value on the list</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private int BinarySearchLeftEdge(ulong address)
|
||||
{
|
||||
if (Count == 0)
|
||||
return ~0;
|
||||
|
||||
if (Count == 1)
|
||||
{
|
||||
ref RangeItem<T> item = ref _items[0];
|
||||
|
||||
if (address == item.Address)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (address < item.Address)
|
||||
{
|
||||
return ~0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return ~1;
|
||||
}
|
||||
}
|
||||
|
||||
int left = 0;
|
||||
int right = Count - 1;
|
||||
|
||||
while (left <= right)
|
||||
{
|
||||
int range = right - left;
|
||||
|
||||
int middle = left + (range >> 1);
|
||||
|
||||
ref RangeItem<T> item = ref _items[middle];
|
||||
|
||||
bool match = item.Address == address;
|
||||
|
||||
if (range == 0)
|
||||
{
|
||||
if (match)
|
||||
return middle;
|
||||
else if (address < item.Address)
|
||||
return ~(right);
|
||||
else
|
||||
return ~(right + 1);
|
||||
}
|
||||
|
||||
if (match)
|
||||
{
|
||||
right = middle;
|
||||
}
|
||||
else if (address < item.Address)
|
||||
{
|
||||
right = middle - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
left = middle + 1;
|
||||
}
|
||||
}
|
||||
|
||||
return ~left;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Performs binary search on the internal list of items.
|
||||
/// </summary>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue