aboutsummaryrefslogtreecommitdiff
path: root/src/Ryujinx.Horizon/Sdk/Ngc/Detail/Bp.cs
blob: d24fab63a0d76a6ebb0e15f850ed060ee864a219 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
namespace Ryujinx.Horizon.Sdk.Ngc.Detail
{
    class Bp
    {
        private readonly BpNode _firstNode = new();
        private readonly SbvSelect _sbvSelect = new();

        public bool Import(ref BinaryReader reader)
        {
            return _firstNode.Import(ref reader) && _sbvSelect.Import(ref reader);
        }

        public int ToPos(int index)
        {
            return _sbvSelect.Select(_firstNode.Set, index);
        }

        public int Enclose(int index)
        {
            if ((uint)index < (uint)_firstNode.Set.BitVector.BitLength)
            {
                if (!_firstNode.Set.Has(index))
                {
                    index = _firstNode.FindOpen(index);
                }

                if (index > 0)
                {
                    return _firstNode.Enclose(index);
                }
            }

            return -1;
        }

        public int ToNodeId(int index)
        {
            if ((uint)index < (uint)_firstNode.Set.BitVector.BitLength)
            {
                if (!_firstNode.Set.Has(index))
                {
                    index = _firstNode.FindOpen(index);
                }

                if (index >= 0)
                {
                    return _firstNode.Set.Rank1(index) - 1;
                }
            }

            return -1;
        }
    }
}