Skip to content

Commit 5a4aa86

Browse files
committed
feat: add compare for HighLevelILFlowGraphEdge
1 parent 32d0adb commit 5a4aa86

File tree

3 files changed

+90
-5
lines changed

3 files changed

+90
-5
lines changed

Handle/BNFlowGraphNode.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,5 @@ public void SetOutgoingEdgePoints(ulong edgeNum, Point[] points)
155155
(ulong)points.Length
156156
);
157157
}
158-
159-
160-
161158
}
162159
}

HighLevelIL/HighLevelILFlowGraphEdge.cs

Lines changed: 88 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1+
using System;
2+
13
namespace BinaryNinja
24
{
3-
public sealed class HighLevelILFlowGraphEdge : AbstractFlowGraphEdge<HighLevelILFlowGraphNode>
5+
public sealed class HighLevelILFlowGraphEdge
6+
: AbstractFlowGraphEdge<HighLevelILFlowGraphNode>,
7+
IEquatable<HighLevelILFlowGraphEdge>,
8+
IComparable<HighLevelILFlowGraphEdge>
49
{
510
internal HighLevelILFlowGraphEdge(
611
BNFlowGraphEdge native,
@@ -37,5 +42,87 @@ bool outgoing
3742
);
3843
}
3944
}
45+
46+
public override bool Equals(object? other)
47+
{
48+
return this.Equals(other as HighLevelILFlowGraphEdge);
49+
}
50+
51+
public bool Equals(HighLevelILFlowGraphEdge? other)
52+
{
53+
if (other is null)
54+
{
55+
return false;
56+
}
57+
58+
if (ReferenceEquals(this , other))
59+
{
60+
return true;
61+
}
62+
63+
if (this.Type != other.Type)
64+
{
65+
return false;
66+
}
67+
68+
if (this.Source != other.Source)
69+
{
70+
return false;
71+
}
72+
73+
if (this.Target != other.Target)
74+
{
75+
return false;
76+
}
77+
78+
return true;
79+
}
80+
81+
[System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2218:OverrideGetHashCodeOnOverridingEquals")]
82+
public override int GetHashCode()
83+
{
84+
return HashCode.Combine<uint,int,int>(
85+
(uint)this.Type,
86+
this.Source.GetHashCode(),
87+
this.Target.GetHashCode()
88+
);
89+
}
90+
91+
public static bool operator ==(HighLevelILFlowGraphEdge? left, HighLevelILFlowGraphEdge? right)
92+
{
93+
if (left is null)
94+
{
95+
return right is null;
96+
}
97+
98+
return left.Equals(right);
99+
}
100+
101+
public static bool operator !=(HighLevelILFlowGraphEdge? left, HighLevelILFlowGraphEdge? right)
102+
{
103+
return !(left == right);
104+
}
105+
106+
public int CompareTo(HighLevelILFlowGraphEdge? other)
107+
{
108+
if (other is null)
109+
{
110+
return 1;
111+
}
112+
113+
int result = this.Type.CompareTo(other.Type);
114+
115+
if (0 == result)
116+
{
117+
result = this.Source.CompareTo(other.Source);
118+
}
119+
120+
if (0 == result)
121+
{
122+
result = this.Target.CompareTo(other.Target);
123+
}
124+
125+
return result;
126+
}
40127
}
41128
}

Struct/BNFlowGraphEdge.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ public unsafe struct BNFlowGraphEdge
3939
internal BNEdgeStyle style;
4040
}
4141

42-
public abstract class AbstractFlowGraphEdge<T_FLOW_GRAPH_NODE> : INativeWrapperEx<BNFlowGraphEdge>
42+
public abstract class AbstractFlowGraphEdge<T_FLOW_GRAPH_NODE>
43+
: INativeWrapperEx<BNFlowGraphEdge>
4344
where T_FLOW_GRAPH_NODE : FlowGraphNode
4445
{
4546
public BranchType Type {get;} = BranchType.UnconditionalBranch;

0 commit comments

Comments
 (0)