diff options
author | Oszkár Semeráth <semerath@mit.bme.hu> | 2023-08-06 18:47:53 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-06 18:47:53 +0200 |
commit | 693a12c77f70792b1985941e05dba3bcaa543e13 (patch) | |
tree | db4ef00eee16f3804025b58dea4352b83ba604c5 /subprojects | |
parent | Merge pull request #33 from OszkarSemerath/datastructure (diff) | |
parent | Performance++: ModelVersion.equals is fast and simple and ModelVersion.hash c... (diff) | |
download | refinery-693a12c77f70792b1985941e05dba3bcaa543e13.tar.gz refinery-693a12c77f70792b1985941e05dba3bcaa543e13.tar.zst refinery-693a12c77f70792b1985941e05dba3bcaa543e13.zip |
Merge pull request #34 from OszkarSemerath/datastructure
Performance++: ModelVersion.equals is fast, and hash is cached
Diffstat (limited to 'subprojects')
-rw-r--r-- | subprojects/store/src/main/java/tools/refinery/store/model/internal/ModelImpl.java | 8 | ||||
-rw-r--r-- | subprojects/store/src/main/java/tools/refinery/store/model/internal/ModelVersion.java | 22 |
2 files changed, 14 insertions, 16 deletions
diff --git a/subprojects/store/src/main/java/tools/refinery/store/model/internal/ModelImpl.java b/subprojects/store/src/main/java/tools/refinery/store/model/internal/ModelImpl.java index 92694af4..2b12d5a6 100644 --- a/subprojects/store/src/main/java/tools/refinery/store/model/internal/ModelImpl.java +++ b/subprojects/store/src/main/java/tools/refinery/store/model/internal/ModelImpl.java | |||
@@ -105,7 +105,7 @@ public class ModelImpl implements Model { | |||
105 | // Doing the commit on the interpretations | 105 | // Doing the commit on the interpretations |
106 | Version[] interpretationVersions = new Version[interpretations.size()]; | 106 | Version[] interpretationVersions = new Version[interpretations.size()]; |
107 | int j = 0; | 107 | int j = 0; |
108 | for(var interpretationEntry : interpretations.entrySet()) { | 108 | for (var interpretationEntry : interpretations.entrySet()) { |
109 | interpretationVersions[j++] = interpretationEntry.getValue().commit(); | 109 | interpretationVersions[j++] = interpretationEntry.getValue().commit(); |
110 | } | 110 | } |
111 | ModelVersion modelVersion = new ModelVersion(interpretationVersions); | 111 | ModelVersion modelVersion = new ModelVersion(interpretationVersions); |
@@ -140,7 +140,7 @@ public class ModelImpl implements Model { | |||
140 | } | 140 | } |
141 | int j = 0; | 141 | int j = 0; |
142 | for (var interpretation : interpretations.values()) { | 142 | for (var interpretation : interpretations.values()) { |
143 | interpretation.restore(ModelVersion.getInternalVersion(version,j++)); | 143 | interpretation.restore(ModelVersion.getInternalVersion(version, j++)); |
144 | } | 144 | } |
145 | 145 | ||
146 | setState(version); | 146 | setState(version); |
@@ -187,8 +187,4 @@ public class ModelImpl implements Model { | |||
187 | public void removeListener(ModelListener listener) { | 187 | public void removeListener(ModelListener listener) { |
188 | listeners.remove(listener); | 188 | listeners.remove(listener); |
189 | } | 189 | } |
190 | |||
191 | public Map<? extends AnySymbol, ? extends Interpretation<?>> getInterpretations() { | ||
192 | return interpretations; | ||
193 | } | ||
194 | } | 190 | } |
diff --git a/subprojects/store/src/main/java/tools/refinery/store/model/internal/ModelVersion.java b/subprojects/store/src/main/java/tools/refinery/store/model/internal/ModelVersion.java index cf3b7fc6..f81386f1 100644 --- a/subprojects/store/src/main/java/tools/refinery/store/model/internal/ModelVersion.java +++ b/subprojects/store/src/main/java/tools/refinery/store/model/internal/ModelVersion.java | |||
@@ -9,25 +9,27 @@ import tools.refinery.store.map.Version; | |||
9 | 9 | ||
10 | import java.util.Arrays; | 10 | import java.util.Arrays; |
11 | 11 | ||
12 | public record ModelVersion(Version[] mapVersions) implements Version{ | 12 | public class ModelVersion implements Version { |
13 | final Version[] mapVersions; | ||
14 | final int hash; | ||
15 | |||
16 | public ModelVersion(Version[] mapVersions) { | ||
17 | this.mapVersions = mapVersions; | ||
18 | this.hash = Arrays.hashCode(mapVersions); | ||
19 | } | ||
13 | 20 | ||
14 | public static Version getInternalVersion(Version modelVersion, int interpretationIndex) { | 21 | public static Version getInternalVersion(Version modelVersion, int interpretationIndex) { |
15 | return ((ModelVersion)modelVersion).mapVersions()[interpretationIndex]; | 22 | return ((ModelVersion) modelVersion).mapVersions[interpretationIndex]; |
16 | } | 23 | } |
17 | 24 | ||
18 | @Override | 25 | @Override |
19 | public int hashCode() { | 26 | public int hashCode() { |
20 | return Arrays.hashCode(mapVersions); | 27 | return hash; |
21 | } | 28 | } |
22 | 29 | ||
23 | @Override | 30 | @Override |
24 | public boolean equals(Object o) { | 31 | public boolean equals(Object obj) { |
25 | if (this == o) return true; | 32 | return super.equals(obj); |
26 | if (o == null || getClass() != o.getClass()) return false; | ||
27 | |||
28 | ModelVersion that = (ModelVersion) o; | ||
29 | |||
30 | return Arrays.equals(mapVersions, that.mapVersions); | ||
31 | } | 33 | } |
32 | 34 | ||
33 | @Override | 35 | @Override |