-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMstNode.cs
More file actions
66 lines (47 loc) · 1.3 KB
/
Copy pathMstNode.cs
File metadata and controls
66 lines (47 loc) · 1.3 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
namespace dnproto.mst;
/// <summary>
/// Represents a node in MST.
/// </summary>
public class MstNode
{
public required int KeyDepth;
public MstNode? LeftTree = null;
public required List<MstEntry> Entries;
#region EQUALITY
/// <summary>
/// Equality members, so that we can use MstNode as a key in a dictionary.
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
public override bool Equals(object? obj)
{
if (obj is not MstNode other)
return false;
if (KeyDepth != other.KeyDepth)
return false;
if (LeftTree is null != other.LeftTree is null)
return false;
if (LeftTree is not null && !LeftTree.Equals(other.LeftTree))
return false;
if (Entries.Count != other.Entries.Count)
return false;
for (int i = 0; i < Entries.Count; i++)
{
if (!Entries[i].Equals(other.Entries[i]))
return false;
}
return true;
}
public override int GetHashCode()
{
var hash = new HashCode();
hash.Add(KeyDepth);
hash.Add(LeftTree);
foreach (var entry in Entries)
{
hash.Add(entry);
}
return hash.ToHashCode();
}
#endregion
}