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