4
4
namespace JL . Core . Deconjugation ;
5
5
6
6
[ method: JsonConstructor ]
7
- internal readonly struct Rule ( string type , string [ ] decEnd , string [ ] conEnd , string detail , string ? contextRule = null , string [ ] ? decTag = null , string [ ] ? conTag = null )
7
+ internal readonly struct Rule ( string type , string [ ] decEnd , string [ ] conEnd , string detail , string ? contextRule = null , string [ ] ? decTag = null , string [ ] ? conTag = null ) : IEquatable < Rule >
8
8
{
9
9
[ JsonPropertyName ( "type" ) ] public string Type { get ; } = type . GetPooledString ( ) ;
10
10
[ JsonPropertyName ( "dec_end" ) ] public string [ ] DecEnd { get ; } = decEnd ;
@@ -13,4 +13,76 @@ internal readonly struct Rule(string type, string[] decEnd, string[] conEnd, str
13
13
[ JsonPropertyName ( "contextrule" ) ] public string ? ContextRule { get ; } = contextRule ? . GetPooledString ( ) ;
14
14
[ JsonPropertyName ( "dec_tag" ) ] public string [ ] ? DecTag { get ; } = decTag ;
15
15
[ JsonPropertyName ( "con_tag" ) ] public string [ ] ? ConTag { get ; } = conTag ;
16
+
17
+ public override int GetHashCode ( )
18
+ {
19
+ unchecked
20
+ {
21
+ int hash = ( 17 * 37 ) + Type . GetHashCode ( StringComparison . Ordinal ) ;
22
+ hash = ( hash * 37 ) + Detail . GetHashCode ( StringComparison . Ordinal ) ;
23
+ hash = ( hash * 37 ) + ContextRule ? . GetHashCode ( StringComparison . Ordinal ) ?? 37 ;
24
+
25
+ foreach ( string decEnd in DecEnd )
26
+ {
27
+ hash = ( hash * 37 ) + decEnd . GetHashCode ( StringComparison . Ordinal ) ;
28
+ }
29
+
30
+ foreach ( string conEnd in ConEnd )
31
+ {
32
+ hash = ( hash * 37 ) + conEnd . GetHashCode ( StringComparison . Ordinal ) ;
33
+ }
34
+
35
+ if ( DecTag is not null )
36
+ {
37
+ foreach ( string decTag in DecTag )
38
+ {
39
+ hash = ( hash * 37 ) + decTag . GetHashCode ( StringComparison . Ordinal ) ;
40
+ }
41
+ }
42
+ else
43
+ {
44
+ hash *= 37 ;
45
+ }
46
+
47
+ if ( ConTag is not null )
48
+ {
49
+ foreach ( string conTag in ConTag )
50
+ {
51
+ hash = ( hash * 37 ) + conTag . GetHashCode ( StringComparison . Ordinal ) ;
52
+ }
53
+ }
54
+ else
55
+ {
56
+ hash *= 37 ;
57
+ }
58
+
59
+ return hash ;
60
+ }
61
+ }
62
+
63
+ public override bool Equals ( object ? obj )
64
+ {
65
+ return obj is Rule rule
66
+ && Type == rule . Type
67
+ && Detail == rule . Detail
68
+ && ContextRule == rule . ContextRule
69
+ && DecEnd . SequenceEqual ( rule . DecEnd )
70
+ && ConEnd . SequenceEqual ( rule . ConEnd )
71
+ && ( rule . DecTag is not null ? ( DecTag ? . SequenceEqual ( rule . DecTag ) ?? false ) : DecTag is null )
72
+ && ( rule . ConTag is not null ? ( ConTag ? . SequenceEqual ( rule . ConTag ) ?? false ) : ConTag is null ) ;
73
+ }
74
+
75
+ public bool Equals ( Rule other )
76
+ {
77
+ return Type == other . Type
78
+ && Detail == other . Detail
79
+ && ContextRule == other . ContextRule
80
+ && DecEnd . SequenceEqual ( other . DecEnd )
81
+ && ConEnd . SequenceEqual ( other . ConEnd )
82
+ && ( other . DecTag is not null ? ( DecTag ? . SequenceEqual ( other . DecTag ) ?? false ) : DecTag is null )
83
+ && ( other . ConTag is not null ? ( ConTag ? . SequenceEqual ( other . ConTag ) ?? false ) : ConTag is null ) ;
84
+ }
85
+
86
+ public static bool operator == ( Rule left , Rule right ) => left . Equals ( right ) ;
87
+ public static bool operator != ( Rule left , Rule right ) => ! left . Equals ( right ) ;
16
88
}
0 commit comments