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/store-query/src/main/java/tools/refinery/store/query/equality/SubstitutingLiteralHashCodeHelper.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/store-query/src/main/java/tools/refinery/store/query/equality/SubstitutingLiteralHashCodeHelper.java')
-rw-r--r-- | subprojects/store-query/src/main/java/tools/refinery/store/query/equality/SubstitutingLiteralHashCodeHelper.java | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/subprojects/store-query/src/main/java/tools/refinery/store/query/equality/SubstitutingLiteralHashCodeHelper.java b/subprojects/store-query/src/main/java/tools/refinery/store/query/equality/SubstitutingLiteralHashCodeHelper.java new file mode 100644 index 00000000..754f6976 --- /dev/null +++ b/subprojects/store-query/src/main/java/tools/refinery/store/query/equality/SubstitutingLiteralHashCodeHelper.java | |||
@@ -0,0 +1,42 @@ | |||
1 | /* | ||
2 | * SPDX-FileCopyrightText: 2023 The Refinery Authors <https://refinery.tools/> | ||
3 | * | ||
4 | * SPDX-License-Identifier: EPL-2.0 | ||
5 | */ | ||
6 | package tools.refinery.store.query.equality; | ||
7 | |||
8 | import tools.refinery.store.query.dnf.SymbolicParameter; | ||
9 | import tools.refinery.store.query.term.Variable; | ||
10 | |||
11 | import java.util.LinkedHashMap; | ||
12 | import java.util.List; | ||
13 | import java.util.Map; | ||
14 | |||
15 | public class SubstitutingLiteralHashCodeHelper implements LiteralHashCodeHelper { | ||
16 | private final Map<Variable, Integer> assignedHashCodes = new LinkedHashMap<>(); | ||
17 | |||
18 | // 0 is for {@code null}, so we start with 1. | ||
19 | private int next = 1; | ||
20 | |||
21 | public SubstitutingLiteralHashCodeHelper() { | ||
22 | this(List.of()); | ||
23 | } | ||
24 | |||
25 | public SubstitutingLiteralHashCodeHelper(List<SymbolicParameter> parameters) { | ||
26 | for (var parameter : parameters) { | ||
27 | getVariableHashCode(parameter.getVariable()); | ||
28 | } | ||
29 | } | ||
30 | |||
31 | @Override | ||
32 | public int getVariableHashCode(Variable variable) { | ||
33 | if (variable == null) { | ||
34 | return 0; | ||
35 | } | ||
36 | return assignedHashCodes.computeIfAbsent(variable, key -> { | ||
37 | int sequenceNumber = next; | ||
38 | next++; | ||
39 | return variable.hashCodeWithSubstitution(sequenceNumber); | ||
40 | }); | ||
41 | } | ||
42 | } | ||