diff options
author | Kristóf Marussy <marussy@mit.bme.hu> | 2023-09-14 19:29:36 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-14 19:29:36 +0200 |
commit | 98ed3b6db5f4e51961a161050cc31c66015116e8 (patch) | |
tree | 8bfd6d9bc8d6ed23b9eb0f889dd40b6c24fe8f92 /subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/tuple/LeftInheritanceTuple2.java | |
parent | Merge pull request #38 from nagilooh/design-space-exploration (diff) | |
parent | Merge remote-tracking branch 'upstream/main' into partial-interpretation (diff) | |
download | refinery-98ed3b6db5f4e51961a161050cc31c66015116e8.tar.gz refinery-98ed3b6db5f4e51961a161050cc31c66015116e8.tar.zst refinery-98ed3b6db5f4e51961a161050cc31c66015116e8.zip |
Merge pull request #39 from kris7t/partial-interpretation
Implement partial interpretation based model generation
Diffstat (limited to 'subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/tuple/LeftInheritanceTuple2.java')
-rw-r--r-- | subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/tuple/LeftInheritanceTuple2.java | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/tuple/LeftInheritanceTuple2.java b/subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/tuple/LeftInheritanceTuple2.java new file mode 100644 index 00000000..e9fb98e8 --- /dev/null +++ b/subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/tuple/LeftInheritanceTuple2.java | |||
@@ -0,0 +1,73 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2010-2017, Gabor Bergmann, IncQueryLabs Ltd. | ||
3 | * This program and the accompanying materials are made available under the | ||
4 | * terms of the Eclipse Public License v. 2.0 which is available at | ||
5 | * http://www.eclipse.org/legal/epl-v20.html. | ||
6 | * | ||
7 | * SPDX-License-Identifier: EPL-2.0 | ||
8 | *******************************************************************************/ | ||
9 | package tools.refinery.viatra.runtime.matchers.tuple; | ||
10 | |||
11 | import java.util.Objects; | ||
12 | |||
13 | /** | ||
14 | * @author Gabor Bergmann | ||
15 | * @since 1.7 | ||
16 | */ | ||
17 | public final class LeftInheritanceTuple2 extends BaseLeftInheritanceTuple { | ||
18 | private final Object localElement0; | ||
19 | private final Object localElement1; | ||
20 | |||
21 | protected LeftInheritanceTuple2(Tuple ancestor, Object localElement0, Object localElement1) { | ||
22 | super(ancestor); | ||
23 | this.localElement0 = localElement0; | ||
24 | this.localElement1 = localElement1; | ||
25 | calcHash(); | ||
26 | } | ||
27 | |||
28 | @Override | ||
29 | public int getLocalSize() { | ||
30 | return 2; | ||
31 | } | ||
32 | |||
33 | @Override | ||
34 | public int getSize() { | ||
35 | return inheritedIndex + 2; | ||
36 | } | ||
37 | |||
38 | @Override | ||
39 | public Object get(int index) { | ||
40 | int local = index - inheritedIndex; | ||
41 | if (local < 0) | ||
42 | return ancestor.get(index); | ||
43 | else if (local == 0) return localElement0; | ||
44 | else if (local == 1) return localElement1; | ||
45 | else throw raiseIndexingError(index); | ||
46 | } | ||
47 | |||
48 | /** | ||
49 | * Optimized hash calculation | ||
50 | */ | ||
51 | @Override | ||
52 | void calcHash() { | ||
53 | final int PRIME = 31; | ||
54 | cachedHash = ancestor.hashCode(); | ||
55 | cachedHash = PRIME * cachedHash; | ||
56 | if (localElement0 != null) cachedHash += localElement0.hashCode(); | ||
57 | cachedHash = PRIME * cachedHash; | ||
58 | if (localElement1 != null) cachedHash += localElement1.hashCode(); | ||
59 | } | ||
60 | |||
61 | @Override | ||
62 | protected boolean localEquals(BaseLeftInheritanceTuple other) { | ||
63 | if (other instanceof LeftInheritanceTuple2) { | ||
64 | LeftInheritanceTuple2 lit = (LeftInheritanceTuple2)other; | ||
65 | return Objects.equals(this.localElement0, lit.localElement0) && | ||
66 | Objects.equals(this.localElement1, lit.localElement1); | ||
67 | } else { | ||
68 | return (2 == other.getLocalSize()) && | ||
69 | Objects.equals(localElement0, other.get(inheritedIndex)) && | ||
70 | Objects.equals(localElement1, other.get(inheritedIndex + 1)); | ||
71 | } | ||
72 | } | ||
73 | } | ||