mirror of
https://git.ryujinx.app/projects/Kenji-NX.git
synced 2026-11-19 17:21:15 +01:00
Implement NGC service (#5681)
* Implement NGC service * Use raw byte arrays instead of string for _wordSeparators * Silence IDE0230 for _wordSeparators * Try to silence warning about _rangeValuesCount not being read on SparseSet * Make AcType enum private * Add abstract methods and one TODO that I forgot * PR feedback * More PR feedback * More PR feedback
This commit is contained in:
1 parent
4bd2ca3f0d
commit
01c2b8097c
44 files changed
+4630
-4
No files matched your search
@@ -0,0 +1,78 @@
|
||||
namespace Ryujinx.Horizon.Sdk.Ngc.Detail
|
||||
{
|
||||
class BitVector32
|
||||
{
|
||||
private const int BitsPerWord = Set.BitsPerWord;
|
||||
|
||||
private int _bitLength;
|
||||
private uint[] _array;
|
||||
|
||||
public int BitLength => _bitLength;
|
||||
public uint[] Array => _array;
|
||||
|
||||
public BitVector32()
|
||||
{
|
||||
_bitLength = 0;
|
||||
_array = null;
|
||||
}
|
||||
|
||||
public BitVector32(int length)
|
||||
{
|
||||
_bitLength = length;
|
||||
_array = new uint[(length + BitsPerWord - 1) / BitsPerWord];
|
||||
}
|
||||
|
||||
public bool Has(int index)
|
||||
{
|
||||
if ((uint)index < (uint)_bitLength)
|
||||
{
|
||||
int wordIndex = index / BitsPerWord;
|
||||
int wordBitOffset = index % BitsPerWord;
|
||||
|
||||
return ((_array[wordIndex] >> wordBitOffset) & 1u) != 0;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool TurnOn(int index, int count)
|
||||
{
|
||||
for (int bit = 0; bit < count; bit++)
|
||||
{
|
||||
if (!TurnOn(index + bit))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool TurnOn(int index)
|
||||
{
|
||||
if ((uint)index < (uint)_bitLength)
|
||||
{
|
||||
int wordIndex = index / BitsPerWord;
|
||||
int wordBitOffset = index % BitsPerWord;
|
||||
|
||||
_array[wordIndex] |= 1u << wordBitOffset;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool Import(ref BinaryReader reader)
|
||||
{
|
||||
if (!reader.Read(out _bitLength))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
int arrayLength = (_bitLength + BitsPerWord - 1) / BitsPerWord;
|
||||
|
||||
return reader.AllocateAndReadArray(ref _array, arrayLength) == arrayLength;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user