Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
ByteSequenceComparer.cs
Go to the documentation of this file.
3
5
6internal sealed class ByteSequenceComparer : IEqualityComparer<byte[]>, IEqualityComparer<ImmutableArray<byte>>
7{
8 internal static readonly ByteSequenceComparer Instance = new ByteSequenceComparer();
9
11 {
12 }
13
15 {
16 if (x == y)
17 {
18 return true;
19 }
20 if (x.IsDefault || y.IsDefault || x.Length != y.Length)
21 {
22 return false;
23 }
24 for (int i = 0; i < x.Length; i++)
25 {
26 if (x[i] != y[i])
27 {
28 return false;
29 }
30 }
31 return true;
32 }
33
34 internal static bool Equals(byte[] left, int leftStart, byte[] right, int rightStart, int length)
35 {
36 if (left == null || right == null)
37 {
38 return left == right;
39 }
40 if (left == right && leftStart == rightStart)
41 {
42 return true;
43 }
44 for (int i = 0; i < length; i++)
45 {
46 if (left[leftStart + i] != right[rightStart + i])
47 {
48 return false;
49 }
50 }
51 return true;
52 }
53
54 internal static bool Equals(byte[]? left, byte[]? right)
55 {
56 if (left == right)
57 {
58 return true;
59 }
60 if (left == null || right == null || left.Length != right.Length)
61 {
62 return false;
63 }
64 for (int i = 0; i < left.Length; i++)
65 {
66 if (left[i] != right[i])
67 {
68 return false;
69 }
70 }
71 return true;
72 }
73
74 internal static int GetHashCode(byte[] x)
75 {
76 return Hash.GetFNVHashCode(x);
77 }
78
79 internal static int GetHashCode(ImmutableArray<byte> x)
80 {
81 return Hash.GetFNVHashCode(x);
82 }
83
84 bool IEqualityComparer<byte[]>.Equals(byte[] x, byte[] y)
85 {
86 return Equals(x, y);
87 }
88
89 int IEqualityComparer<byte[]>.GetHashCode(byte[] x)
90 {
91 return GetHashCode(x);
92 }
93
98
100 {
101 return GetHashCode(x);
102 }
103}
static bool Equals(ImmutableArray< byte > x, ImmutableArray< byte > y)
static int GetHashCode(ImmutableArray< byte > x)
static readonly ByteSequenceComparer Instance
static bool Equals(byte[]? left, byte[]? right)
static bool Equals(byte[] left, int leftStart, byte[] right, int rightStart, int length)
static int GetFNVHashCode(byte[] data)
Definition Hash.cs:26