aboutsummaryrefslogtreecommitdiff
path: root/src/Ryujinx.Common/Hash128.cs
blob: 28c0946b3f5522ec13b8df0f957413b32c1c6640 (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
using System;
using System.Runtime.InteropServices;

namespace Ryujinx.Common
{
    [StructLayout(LayoutKind.Sequential)]
    public struct Hash128 : IEquatable<Hash128>
    {
        public ulong Low;
        public ulong High;

        public Hash128(ulong low, ulong high)
        {
            Low = low;
            High = high;
        }

        public readonly override string ToString()
        {
            return $"{High:x16}{Low:x16}";
        }

        public static bool operator ==(Hash128 x, Hash128 y)
        {
            return x.Equals(y);
        }

        public static bool operator !=(Hash128 x, Hash128 y)
        {
            return !x.Equals(y);
        }

        public readonly override bool Equals(object obj)
        {
            return obj is Hash128 hash128 && Equals(hash128);
        }

        public readonly bool Equals(Hash128 cmpObj)
        {
            return Low == cmpObj.Low && High == cmpObj.High;
        }

        public readonly override int GetHashCode()
        {
            return HashCode.Combine(Low, High);
        }
    }
}