forked from Mirror/Ryujinx
0a75b73fa4
* dotnet format style --severity info Some changes were manually reverted. * dotnet format analyzers --serverity info Some changes have been minimally adapted. * Silence dotnet format IDE0059 warnings * Address or silence dotnet format IDE1006 warnings * Address dotnet format CA1816 warnings * Address or silence dotnet format CA1069 warnings * Address remaining dotnet format analyzer warnings * Address review comments * Address most dotnet format whitespace warnings * Apply dotnet format whitespace formatting A few of them have been manually reverted and the corresponding warning was silenced * Format if-blocks correctly * Another rebase, another dotnet format run * Run dotnet format after rebase and remove unused usings - analyzers - style - whitespace * Add comments to disabled warnings * Simplify properties and array initialization, Use const when possible, Remove trailing commas * Revert "Simplify properties and array initialization, Use const when possible, Remove trailing commas" This reverts commit 9462e4136c0a2100dc28b20cf9542e06790aa67e. * dotnet format whitespace after rebase * Address review feedback * Assign Decommit to ReplacePlaceholder * Run final dotnet format pass * Organize imports again * Add trailing commas * Add missing newline
87 lines
2.1 KiB
C#
87 lines
2.1 KiB
C#
using Ryujinx.Common.Collections;
|
|
using System;
|
|
|
|
namespace Ryujinx.Memory.WindowsShared
|
|
{
|
|
/// <summary>
|
|
/// A intrusive Red-Black Tree that also supports getting nodes overlapping a given range.
|
|
/// </summary>
|
|
/// <typeparam name="T">Type of the value stored on the node</typeparam>
|
|
class MappingTree<T> : IntrusiveRedBlackTree<RangeNode<T>>
|
|
{
|
|
private const int ArrayGrowthSize = 16;
|
|
|
|
public int GetNodes(ulong start, ulong end, ref RangeNode<T>[] overlaps, int overlapCount = 0)
|
|
{
|
|
RangeNode<T> node = this.GetNodeByKey(start);
|
|
|
|
for (; node != null; node = node.Successor)
|
|
{
|
|
if (overlaps.Length <= overlapCount)
|
|
{
|
|
Array.Resize(ref overlaps, overlapCount + ArrayGrowthSize);
|
|
}
|
|
|
|
overlaps[overlapCount++] = node;
|
|
|
|
if (node.End >= end)
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
|
|
return overlapCount;
|
|
}
|
|
}
|
|
|
|
class RangeNode<T> : IntrusiveRedBlackTreeNode<RangeNode<T>>, IComparable<RangeNode<T>>, IComparable<ulong>
|
|
{
|
|
public ulong Start { get; }
|
|
public ulong End { get; private set; }
|
|
public T Value { get; }
|
|
|
|
public RangeNode(ulong start, ulong end, T value)
|
|
{
|
|
Start = start;
|
|
End = end;
|
|
Value = value;
|
|
}
|
|
|
|
public void Extend(ulong sizeDelta)
|
|
{
|
|
End += sizeDelta;
|
|
}
|
|
|
|
public int CompareTo(RangeNode<T> other)
|
|
{
|
|
if (Start < other.Start)
|
|
{
|
|
return -1;
|
|
}
|
|
else if (Start <= other.End - 1UL)
|
|
{
|
|
return 0;
|
|
}
|
|
else
|
|
{
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
public int CompareTo(ulong address)
|
|
{
|
|
if (address < Start)
|
|
{
|
|
return 1;
|
|
}
|
|
else if (address <= End - 1UL)
|
|
{
|
|
return 0;
|
|
}
|
|
else
|
|
{
|
|
return -1;
|
|
}
|
|
}
|
|
}
|
|
}
|