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