Skip to content

Commit d4c8b54

Browse files
committed
implement IEquatable interface
1 parent edce36b commit d4c8b54

File tree

1 file changed

+23
-1
lines changed
  • src/Dijkstra.NET/Dijkstra.NET/Model

1 file changed

+23
-1
lines changed

src/Dijkstra.NET/Dijkstra.NET/Model/Edge.cs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
namespace Dijkstra.NET.Model
22
{
3+
using System;
34
using Contract;
4-
public struct Edge<T, TCustom> where TCustom: class
5+
public struct Edge<T, TCustom>: IEquatable<Edge<T, TCustom>> where TCustom: class
56
{
67
public Edge(INode<T, TCustom> node, uint cost, TCustom custom)
78
{
@@ -13,5 +14,26 @@ public Edge(INode<T, TCustom> node, uint cost, TCustom custom)
1314
public INode<T, TCustom> Node { get; }
1415
public uint Cost { get; }
1516
public TCustom Item { get; }
17+
18+
public bool Equals(Edge<T, TCustom> other) => Node.Key == other.Node.Key && Cost == other.Cost && ReferenceEquals(Item, other.Item);
19+
20+
public override int GetHashCode()
21+
{
22+
int hash = 13;
23+
hash = hash * 7 + (int)Cost;
24+
hash = hash * 7 + (int)Node.Key;
25+
return hash;
26+
}
27+
28+
public override bool Equals(object obj)
29+
{
30+
var other = obj as Edge<T, TCustom>?;
31+
32+
if (other == null)
33+
return false;
34+
35+
return Equals(other.Value);
36+
}
37+
1638
}
1739
}

0 commit comments

Comments
 (0)