From 329ac27dfa84e9a07760bea75b36476dddcf29a7 Mon Sep 17 00:00:00 2001 From: Kristóf Marussy Date: Tue, 14 Jul 2020 10:45:03 +0200 Subject: Optimizations --- .../neighbourhood/Descriptor.xtend | 106 ++++++--------------- 1 file changed, 28 insertions(+), 78 deletions(-) (limited to 'Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage/neighbourhood/Descriptor.xtend') diff --git a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage/neighbourhood/Descriptor.xtend b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage/neighbourhood/Descriptor.xtend index e4bdb086..685a1f5a 100644 --- a/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage/neighbourhood/Descriptor.xtend +++ b/Solvers/VIATRA-Solver/hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage/src/hu/bme/mit/inf/dslreasoner/viatrasolver/partialinterpretationlanguage/neighbourhood/Descriptor.xtend @@ -7,7 +7,7 @@ import org.eclipse.xtend.lib.annotations.Data import org.eclipse.xtend2.lib.StringConcatenationClient @Data abstract class AbstractNodeDescriptor { - long dataHash + int dataHash protected def StringConcatenationClient prettyPrint() { '''(«dataHash»)[«class.simpleName»]''' @@ -57,7 +57,7 @@ import org.eclipse.xtend2.lib.StringConcatenationClient } override hashCode() { - return this.dataHash.hashCode + return this.dataHash } override equals(Object other) { @@ -119,7 +119,6 @@ import org.eclipse.xtend2.lib.StringConcatenationClient } @Data class FurtherNodeDescriptor extends AbstractNodeDescriptor { - NodeRep previousRepresentation Map, Integer> incomingEdges Map, Integer> outgoingEdges @@ -128,8 +127,8 @@ import org.eclipse.xtend2.lib.StringConcatenationClient Map, Integer> outgoingEdges) { super(calculateDataHash(previousRepresentation, incomingEdges, outgoingEdges)) this.previousRepresentation = previousRepresentation - this.incomingEdges = new HashMap(incomingEdges) - this.outgoingEdges = new HashMap(outgoingEdges) + this.incomingEdges = incomingEdges + this.outgoingEdges = outgoingEdges } static def private int calculateDataHash(NodeRep previousRepresentation, @@ -137,14 +136,14 @@ import org.eclipse.xtend2.lib.StringConcatenationClient val int prime = 31; var int result = previousRepresentation.hashCode; if (incomingEdges !== null) - result = prime * result + incomingEdges.hashCode(); + result = prime * result + hashIncomingNeighborhood(incomingEdges) if (outgoingEdges !== null) - result = prime * result + outgoingEdges.hashCode(); + result = prime * result + hashOutgoingNeighborhood(outgoingEdges) return result; } override hashCode() { - return this.dataHash.hashCode + return this.dataHash } override equals(Object other) { @@ -179,80 +178,31 @@ import org.eclipse.xtend2.lib.StringConcatenationClient '''«rep»''' } } + + private static def hashIncomingNeighborhood(Map, Integer> neighborhood) { + val int prime = 31 + var int hash = 0 + for (entry : neighborhood.entrySet) { + val relation = entry.key + hash += (prime * relation.from.hashCode + relation.type.hashCode).bitwiseXor(entry.value.hashCode) + } + hash + } + + private static def hashOutgoingNeighborhood(Map, Integer> neighborhood) { + val int prime = 31 + var int hash = 0 + for (entry : neighborhood.entrySet) { + val relation = entry.key + hash += (prime * relation.to.hashCode + relation.type.hashCode).bitwiseXor(entry.value.hashCode) + } + hash + } override toString() { ''' «prettyPrint» ''' } - -// @Pure -// @Override -// override public boolean equals(Object obj) { -// if (this === obj) -// return true; -// if (obj === null) -// return false; -// if (getClass() != obj.getClass()) -// return false; -// val AbstractNodeDescriptor other = obj as AbstractNodeDescriptor; -// if (other.dataHash != this.dataHash) -// return false; -// return true; -// } -// @Pure -// override public boolean equals(Object obj) { -// if (this === obj) -// return true; -// if (obj === null) -// return false; -// if (getClass() != obj.getClass()) -// return false; -// if (!super.equals(obj)) -// return false; -// val FurtherNodeDescriptor other = obj as FurtherNodeDescriptor; -// if (this.previousRepresentation === null) { -// if (other.previousRepresentation != null) -// return false; -// -// } -//// } else if (!this.previousRepresentation.equals(other.previousRepresentation)) -//// return false; -// if (this.incomingEdges === null) { -// if (other.incomingEdges != null) -// return false; -// } else if (!this.incomingEdges.equals(other.incomingEdges)) -// return false; -// if (this.outgoingEdges === null) { -// if (other.outgoingEdges != null) -// return false; -// } else if (!this.outgoingEdges.equals(other.outgoingEdges)) -// return false; -// if (this.attributeValues === null) { -// if (other.attributeValues != null) -// return false; -// } else if (!this.attributeValues.equals(other.attributeValues)) -// return false; -// return true; -// } } -/* - * @Data - * class ModelDescriptor { - * int dataHash - * int unknownElements - * Map knownElements - * - * public new(Map knownElements, int unknownElements) { - * this.dataHash = calculateDataHash(knownElements,unknownElements) - * this.unknownElements = unknownElements - * this.knownElements = knownElements - * } - * - * def private static calculateDataHash(Map knownElements, int unknownElements) - * { - * val int prime = 31; - * return knownElements.hashCode * prime + unknownElements.hashCode - * } - * } - */ + -- cgit v1.2.3-70-g09d2