1 module antlr.v4.runtime.atn.ATNConfigObjectEqualityComparator;
2 
3 import antlr.v4.runtime.atn.ATNConfig;
4 import antlr.v4.runtime.misc.MurmurHash;
5 
6 // Singleton ATNConfigObjectEqualityComparator
7 /**
8  * TODO add class description
9  */
10 class ATNConfigObjectEqualityComparator
11 {
12 
13     /**
14      * The single instance of ATNConfigObjectEqualityComparator.
15      */
16     private static __gshared ATNConfigObjectEqualityComparator instance_;
17 
18     public static bool opEquals(Object a, Object b)
19     {
20         if (a is b) {
21             return true;
22         } else
23             if (a is null || b is null) {
24                 return false;
25             }
26         auto objA = cast(ATNConfig)a;
27         auto objB = cast(ATNConfig)b;
28         bool scEqual = false;
29         if (objA.semanticContext is objB.semanticContext)
30             scEqual = true;
31         else
32             if (objA.semanticContext is null || objB.semanticContext is null)
33                 return false;
34         return objA.state.stateNumber == objB.state.stateNumber
35             && objA.alt == objB.alt
36             && (objA.context is objB.context ||
37                 (objA.context !is null && objB.context !is null &&
38                  objA.context.opEquals(objB.context)))
39             && scEqual
40             && objA.isPrecedenceFilterSuppressed == objB.isPrecedenceFilterSuppressed;
41     }
42 
43     /**
44      * @uml
45      * @trusted
46      * @nothrow
47      */
48     public static size_t toHash(Object o) @trusted nothrow
49     {
50         if (cast(ATNConfig)o)
51             {
52                 auto obj = cast(ATNConfig)o;
53                 size_t hashCode = MurmurHash.initialize(7);
54                 hashCode = MurmurHash.update(hashCode, obj.state.stateNumber);
55                 hashCode = MurmurHash.update(hashCode, obj.alt);
56                 hashCode = MurmurHash.update(hashCode, obj.context);
57                 hashCode = MurmurHash.update(hashCode, obj.semanticContext);
58                 hashCode = MurmurHash.finish(hashCode, 4);
59                 return hashCode;
60             }
61         return false;
62     }
63 
64     /**
65      * Creates the single instance of ATNConfigObjectEqualityComparator.
66      */
67     private shared static this()
68     {
69         instance_ = new ATNConfigObjectEqualityComparator;
70     }
71 
72     /**
73      * Returns: A single instance of ATNConfigObjectEqualityComparator.
74      */
75     public static ATNConfigObjectEqualityComparator instance()
76     {
77         return instance_;
78     }
79 
80 }