diff options
author | 2022-09-27 02:08:44 +0200 | |
---|---|---|
committer | 2022-10-03 20:06:52 +0200 | |
commit | 7a310819cbbdd70767a9ed17e1bf84c2add9faed (patch) | |
tree | a381add842a69115d778ac902b47b40159a7feaf | |
parent | refactor: remove viatra dependency from store (diff) | |
download | refinery-7a310819cbbdd70767a9ed17e1bf84c2add9faed.tar.gz refinery-7a310819cbbdd70767a9ed17e1bf84c2add9faed.tar.zst refinery-7a310819cbbdd70767a9ed17e1bf84c2add9faed.zip |
refactor: tuples in QueryableModel
37 files changed, 364 insertions, 267 deletions
diff --git a/subprojects/language-semantics/src/main/java/tools/refinery/language/semantics/model/internal/DecisionTree.java b/subprojects/language-semantics/src/main/java/tools/refinery/language/semantics/model/internal/DecisionTree.java index 8c185509..d743ee2b 100644 --- a/subprojects/language-semantics/src/main/java/tools/refinery/language/semantics/model/internal/DecisionTree.java +++ b/subprojects/language-semantics/src/main/java/tools/refinery/language/semantics/model/internal/DecisionTree.java | |||
@@ -2,7 +2,7 @@ package tools.refinery.language.semantics.model.internal; | |||
2 | 2 | ||
3 | import org.eclipse.collections.api.factory.primitive.IntObjectMaps; | 3 | import org.eclipse.collections.api.factory.primitive.IntObjectMaps; |
4 | import tools.refinery.store.map.Cursor; | 4 | import tools.refinery.store.map.Cursor; |
5 | import tools.refinery.store.model.Tuple; | 5 | import tools.refinery.store.tuple.Tuple; |
6 | import tools.refinery.store.model.representation.TruthValue; | 6 | import tools.refinery.store.model.representation.TruthValue; |
7 | 7 | ||
8 | public class DecisionTree { | 8 | public class DecisionTree { |
diff --git a/subprojects/language-semantics/src/main/java/tools/refinery/language/semantics/model/internal/DecisionTreeCursor.java b/subprojects/language-semantics/src/main/java/tools/refinery/language/semantics/model/internal/DecisionTreeCursor.java index 8b02ba39..727a9528 100644 --- a/subprojects/language-semantics/src/main/java/tools/refinery/language/semantics/model/internal/DecisionTreeCursor.java +++ b/subprojects/language-semantics/src/main/java/tools/refinery/language/semantics/model/internal/DecisionTreeCursor.java | |||
@@ -2,7 +2,7 @@ package tools.refinery.language.semantics.model.internal; | |||
2 | 2 | ||
3 | import tools.refinery.store.map.Cursor; | 3 | import tools.refinery.store.map.Cursor; |
4 | import tools.refinery.store.map.VersionedMap; | 4 | import tools.refinery.store.map.VersionedMap; |
5 | import tools.refinery.store.model.Tuple; | 5 | import tools.refinery.store.tuple.Tuple; |
6 | import tools.refinery.store.model.representation.TruthValue; | 6 | import tools.refinery.store.model.representation.TruthValue; |
7 | 7 | ||
8 | import java.util.ArrayDeque; | 8 | import java.util.ArrayDeque; |
diff --git a/subprojects/language-semantics/src/main/java/tools/refinery/language/semantics/model/internal/DecisionTreeNode.java b/subprojects/language-semantics/src/main/java/tools/refinery/language/semantics/model/internal/DecisionTreeNode.java index 53954d62..7f38fc79 100644 --- a/subprojects/language-semantics/src/main/java/tools/refinery/language/semantics/model/internal/DecisionTreeNode.java +++ b/subprojects/language-semantics/src/main/java/tools/refinery/language/semantics/model/internal/DecisionTreeNode.java | |||
@@ -1,7 +1,7 @@ | |||
1 | package tools.refinery.language.semantics.model.internal; | 1 | package tools.refinery.language.semantics.model.internal; |
2 | 2 | ||
3 | import org.eclipse.collections.api.LazyIntIterable; | 3 | import org.eclipse.collections.api.LazyIntIterable; |
4 | import tools.refinery.store.model.Tuple; | 4 | import tools.refinery.store.tuple.Tuple; |
5 | import tools.refinery.store.model.representation.TruthValue; | 5 | import tools.refinery.store.model.representation.TruthValue; |
6 | 6 | ||
7 | abstract class DecisionTreeNode { | 7 | abstract class DecisionTreeNode { |
diff --git a/subprojects/language-semantics/src/main/java/tools/refinery/language/semantics/model/internal/IntermediateNode.java b/subprojects/language-semantics/src/main/java/tools/refinery/language/semantics/model/internal/IntermediateNode.java index acc53e73..7165197c 100644 --- a/subprojects/language-semantics/src/main/java/tools/refinery/language/semantics/model/internal/IntermediateNode.java +++ b/subprojects/language-semantics/src/main/java/tools/refinery/language/semantics/model/internal/IntermediateNode.java | |||
@@ -4,7 +4,7 @@ import org.eclipse.collections.api.LazyIntIterable; | |||
4 | import org.eclipse.collections.api.factory.primitive.IntObjectMaps; | 4 | import org.eclipse.collections.api.factory.primitive.IntObjectMaps; |
5 | import org.eclipse.collections.api.map.primitive.MutableIntObjectMap; | 5 | import org.eclipse.collections.api.map.primitive.MutableIntObjectMap; |
6 | import org.eclipse.collections.api.tuple.primitive.IntObjectPair; | 6 | import org.eclipse.collections.api.tuple.primitive.IntObjectPair; |
7 | import tools.refinery.store.model.Tuple; | 7 | import tools.refinery.store.tuple.Tuple; |
8 | import tools.refinery.store.model.representation.TruthValue; | 8 | import tools.refinery.store.model.representation.TruthValue; |
9 | 9 | ||
10 | final class IntermediateNode extends DecisionTreeNode { | 10 | final class IntermediateNode extends DecisionTreeNode { |
diff --git a/subprojects/language-semantics/src/main/java/tools/refinery/language/semantics/model/internal/TerminalNode.java b/subprojects/language-semantics/src/main/java/tools/refinery/language/semantics/model/internal/TerminalNode.java index 20dd6b20..f3adea61 100644 --- a/subprojects/language-semantics/src/main/java/tools/refinery/language/semantics/model/internal/TerminalNode.java +++ b/subprojects/language-semantics/src/main/java/tools/refinery/language/semantics/model/internal/TerminalNode.java | |||
@@ -4,7 +4,7 @@ import org.eclipse.collections.api.LazyIntIterable; | |||
4 | import org.eclipse.collections.api.factory.primitive.IntObjectMaps; | 4 | import org.eclipse.collections.api.factory.primitive.IntObjectMaps; |
5 | import org.eclipse.collections.api.map.primitive.MutableIntObjectMap; | 5 | import org.eclipse.collections.api.map.primitive.MutableIntObjectMap; |
6 | import org.eclipse.collections.api.tuple.primitive.IntObjectPair; | 6 | import org.eclipse.collections.api.tuple.primitive.IntObjectPair; |
7 | import tools.refinery.store.model.Tuple; | 7 | import tools.refinery.store.tuple.Tuple; |
8 | import tools.refinery.store.model.representation.TruthValue; | 8 | import tools.refinery.store.model.representation.TruthValue; |
9 | 9 | ||
10 | class TerminalNode extends DecisionTreeNode { | 10 | class TerminalNode extends DecisionTreeNode { |
diff --git a/subprojects/language-semantics/src/test/java/tools/refinery/language/semantics/model/tests/DecisionTreeTests.java b/subprojects/language-semantics/src/test/java/tools/refinery/language/semantics/model/tests/DecisionTreeTests.java index 8fe866af..5268eb8a 100644 --- a/subprojects/language-semantics/src/test/java/tools/refinery/language/semantics/model/tests/DecisionTreeTests.java +++ b/subprojects/language-semantics/src/test/java/tools/refinery/language/semantics/model/tests/DecisionTreeTests.java | |||
@@ -2,7 +2,7 @@ package tools.refinery.language.semantics.model.tests; | |||
2 | 2 | ||
3 | import org.junit.jupiter.api.Test; | 3 | import org.junit.jupiter.api.Test; |
4 | import tools.refinery.language.semantics.model.internal.DecisionTree; | 4 | import tools.refinery.language.semantics.model.internal.DecisionTree; |
5 | import tools.refinery.store.model.Tuple; | 5 | import tools.refinery.store.tuple.Tuple; |
6 | import tools.refinery.store.model.representation.TruthValue; | 6 | import tools.refinery.store.model.representation.TruthValue; |
7 | 7 | ||
8 | import java.util.LinkedHashMap; | 8 | import java.util.LinkedHashMap; |
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/ViatraTupleLike.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/ViatraTupleLike.java new file mode 100644 index 00000000..46c28434 --- /dev/null +++ b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/ViatraTupleLike.java | |||
@@ -0,0 +1,18 @@ | |||
1 | package tools.refinery.store.query.viatra; | ||
2 | |||
3 | import org.eclipse.viatra.query.runtime.matchers.tuple.ITuple; | ||
4 | import tools.refinery.store.tuple.Tuple1; | ||
5 | import tools.refinery.store.tuple.TupleLike; | ||
6 | |||
7 | public record ViatraTupleLike(ITuple wrappedTuple) implements TupleLike { | ||
8 | @Override | ||
9 | public int getSize() { | ||
10 | return wrappedTuple.getSize(); | ||
11 | } | ||
12 | |||
13 | @Override | ||
14 | public int get(int element) { | ||
15 | var wrappedValue = (Tuple1) wrappedTuple.get(element); | ||
16 | return wrappedValue.value0(); | ||
17 | } | ||
18 | } | ||
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/RawPatternMatcher.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/RawPatternMatcher.java index be348a63..2c488319 100644 --- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/RawPatternMatcher.java +++ b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/RawPatternMatcher.java | |||
@@ -2,8 +2,9 @@ package tools.refinery.store.query.viatra.internal; | |||
2 | 2 | ||
3 | import org.eclipse.viatra.query.runtime.api.GenericPatternMatcher; | 3 | import org.eclipse.viatra.query.runtime.api.GenericPatternMatcher; |
4 | import org.eclipse.viatra.query.runtime.api.GenericQuerySpecification; | 4 | import org.eclipse.viatra.query.runtime.api.GenericQuerySpecification; |
5 | import org.eclipse.viatra.query.runtime.matchers.tuple.AbstractTuple; | 5 | import tools.refinery.store.query.viatra.ViatraTupleLike; |
6 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; | 6 | import tools.refinery.store.tuple.Tuple; |
7 | import tools.refinery.store.tuple.TupleLike; | ||
7 | 8 | ||
8 | import java.util.Optional; | 9 | import java.util.Optional; |
9 | import java.util.stream.Stream; | 10 | import java.util.stream.Stream; |
@@ -13,39 +14,50 @@ public class RawPatternMatcher extends GenericPatternMatcher { | |||
13 | 14 | ||
14 | public RawPatternMatcher(GenericQuerySpecification<? extends GenericPatternMatcher> specification) { | 15 | public RawPatternMatcher(GenericQuerySpecification<? extends GenericPatternMatcher> specification) { |
15 | super(specification); | 16 | super(specification); |
16 | this.empty = new Object[specification.getParameterNames().size()]; | 17 | empty = new Object[specification.getParameterNames().size()]; |
17 | } | 18 | } |
18 | 19 | ||
19 | public boolean hasResult() { | 20 | public boolean hasResult() { |
20 | return hasResult(empty); | 21 | return backend.hasMatch(empty); |
21 | } | 22 | } |
22 | 23 | ||
23 | public boolean hasResult(Object[] parameters) { | 24 | public boolean hasResult(Tuple parameters) { |
24 | return this.backend.hasMatch(parameters); | 25 | return backend.hasMatch(toParametersArray(parameters)); |
25 | } | 26 | } |
26 | 27 | ||
27 | public Optional<Object[]> oneResult() { | 28 | public Optional<TupleLike> oneResult() { |
28 | return oneResult(empty); | 29 | return backend.getOneArbitraryMatch(empty).map(ViatraTupleLike::new); |
29 | } | 30 | } |
30 | 31 | ||
31 | public Optional<Object[]> oneResult(Object[] parameters) { | 32 | public Optional<TupleLike> oneResult(Tuple parameters) { |
32 | Optional<Tuple> tuple = this.backend.getOneArbitraryMatch(parameters); | 33 | return backend.getOneArbitraryMatch(toParametersArray(parameters)).map(ViatraTupleLike::new); |
33 | return tuple.map(AbstractTuple::getElements); | ||
34 | } | 34 | } |
35 | 35 | ||
36 | public Stream<Object[]> allResults() { | 36 | public Stream<TupleLike> allResults() { |
37 | return allResults(empty); | 37 | return backend.getAllMatches(empty).map(ViatraTupleLike::new); |
38 | } | 38 | } |
39 | 39 | ||
40 | public Stream<Object[]> allResults(Object[] parameters) { | 40 | public Stream<TupleLike> allResults(Tuple parameters) { |
41 | return this.backend.getAllMatches(parameters).map(AbstractTuple::getElements); | 41 | return backend.getAllMatches(toParametersArray(parameters)).map(ViatraTupleLike::new); |
42 | } | 42 | } |
43 | 43 | ||
44 | public int countResults() { | 44 | public int countResults() { |
45 | return countResults(empty); | 45 | return backend.countMatches(empty); |
46 | } | 46 | } |
47 | 47 | ||
48 | public int countResults(Object[] parameters) { | 48 | public int countResults(Tuple parameters) { |
49 | return backend.countMatches(parameters); | 49 | return backend.countMatches(toParametersArray(parameters)); |
50 | } | ||
51 | |||
52 | private Object[] toParametersArray(Tuple tuple) { | ||
53 | int size = tuple.getSize(); | ||
54 | var array = new Object[tuple.getSize()]; | ||
55 | for (int i = 0; i < size; i++) { | ||
56 | var value = tuple.get(i); | ||
57 | if (value >= 0) { | ||
58 | array[i] = Tuple.of(value); | ||
59 | } | ||
60 | } | ||
61 | return array; | ||
50 | } | 62 | } |
51 | } | 63 | } |
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/RelationalScope.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/RelationalScope.java index 8dfa22e0..5ddad67d 100644 --- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/RelationalScope.java +++ b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/RelationalScope.java | |||
@@ -6,7 +6,7 @@ import org.eclipse.viatra.query.runtime.api.scope.IEngineContext; | |||
6 | import org.eclipse.viatra.query.runtime.api.scope.IIndexingErrorListener; | 6 | import org.eclipse.viatra.query.runtime.api.scope.IIndexingErrorListener; |
7 | import org.eclipse.viatra.query.runtime.api.scope.QueryScope; | 7 | import org.eclipse.viatra.query.runtime.api.scope.QueryScope; |
8 | import tools.refinery.store.model.Model; | 8 | import tools.refinery.store.model.Model; |
9 | import tools.refinery.store.model.Tuple; | 9 | import tools.refinery.store.tuple.Tuple; |
10 | import tools.refinery.store.model.representation.Relation; | 10 | import tools.refinery.store.model.representation.Relation; |
11 | import tools.refinery.store.query.viatra.internal.context.RelationalEngineContext; | 11 | import tools.refinery.store.query.viatra.internal.context.RelationalEngineContext; |
12 | import tools.refinery.store.query.viatra.internal.viewupdate.ModelUpdateListener; | 12 | import tools.refinery.store.query.viatra.internal.viewupdate.ModelUpdateListener; |
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/ViatraQueryableModel.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/ViatraQueryableModel.java index 3803702d..1c15e8f9 100644 --- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/ViatraQueryableModel.java +++ b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/ViatraQueryableModel.java | |||
@@ -8,12 +8,13 @@ import tools.refinery.store.map.Cursor; | |||
8 | import tools.refinery.store.map.DiffCursor; | 8 | import tools.refinery.store.map.DiffCursor; |
9 | import tools.refinery.store.model.Model; | 9 | import tools.refinery.store.model.Model; |
10 | import tools.refinery.store.model.ModelDiffCursor; | 10 | import tools.refinery.store.model.ModelDiffCursor; |
11 | import tools.refinery.store.model.Tuple; | ||
12 | import tools.refinery.store.model.representation.DataRepresentation; | 11 | import tools.refinery.store.model.representation.DataRepresentation; |
13 | import tools.refinery.store.model.representation.Relation; | 12 | import tools.refinery.store.model.representation.Relation; |
14 | import tools.refinery.store.query.QueryableModel; | 13 | import tools.refinery.store.query.QueryableModel; |
15 | import tools.refinery.store.query.QueryableModelStore; | 14 | import tools.refinery.store.query.QueryableModelStore; |
16 | import tools.refinery.store.query.building.DNFPredicate; | 15 | import tools.refinery.store.query.building.DNFPredicate; |
16 | import tools.refinery.store.tuple.Tuple; | ||
17 | import tools.refinery.store.tuple.TupleLike; | ||
17 | 18 | ||
18 | import java.util.HashMap; | 19 | import java.util.HashMap; |
19 | import java.util.Map; | 20 | import java.util.Map; |
@@ -124,9 +125,9 @@ public class ViatraQueryableModel implements QueryableModel { | |||
124 | return result; | 125 | return result; |
125 | } | 126 | } |
126 | 127 | ||
127 | protected void validateParameters(DNFPredicate predicate, Object[] parameters) { | 128 | protected void validateParameters(DNFPredicate predicate, Tuple parameters) { |
128 | int predicateArity = predicate.getVariables().size(); | 129 | int predicateArity = predicate.getVariables().size(); |
129 | int parameterArity = parameters.length; | 130 | int parameterArity = parameters.getSize(); |
130 | if (parameterArity != predicateArity) { | 131 | if (parameterArity != predicateArity) { |
131 | throw new IllegalArgumentException( | 132 | throw new IllegalArgumentException( |
132 | "Predicate %s with %d arity called with different number of parameters (%d)" | 133 | "Predicate %s with %d arity called with different number of parameters (%d)" |
@@ -140,29 +141,29 @@ public class ViatraQueryableModel implements QueryableModel { | |||
140 | } | 141 | } |
141 | 142 | ||
142 | @Override | 143 | @Override |
143 | public boolean hasResult(DNFPredicate predicate, Object[] parameters) { | 144 | public boolean hasResult(DNFPredicate predicate, Tuple parameters) { |
144 | validateParameters(predicate, parameters); | 145 | validateParameters(predicate, parameters); |
145 | return getMatcher(predicate).hasResult(parameters); | 146 | return getMatcher(predicate).hasResult(parameters); |
146 | } | 147 | } |
147 | 148 | ||
148 | @Override | 149 | @Override |
149 | public Optional<Object[]> oneResult(DNFPredicate predicate) { | 150 | public Optional<TupleLike> oneResult(DNFPredicate predicate) { |
150 | return getMatcher(predicate).oneResult(); | 151 | return getMatcher(predicate).oneResult(); |
151 | } | 152 | } |
152 | 153 | ||
153 | @Override | 154 | @Override |
154 | public Optional<Object[]> oneResult(DNFPredicate predicate, Object[] parameters) { | 155 | public Optional<TupleLike> oneResult(DNFPredicate predicate, Tuple parameters) { |
155 | validateParameters(predicate, parameters); | 156 | validateParameters(predicate, parameters); |
156 | return getMatcher(predicate).oneResult(parameters); | 157 | return getMatcher(predicate).oneResult(parameters); |
157 | } | 158 | } |
158 | 159 | ||
159 | @Override | 160 | @Override |
160 | public Stream<Object[]> allResults(DNFPredicate predicate) { | 161 | public Stream<TupleLike> allResults(DNFPredicate predicate) { |
161 | return getMatcher(predicate).allResults(); | 162 | return getMatcher(predicate).allResults(); |
162 | } | 163 | } |
163 | 164 | ||
164 | @Override | 165 | @Override |
165 | public Stream<Object[]> allResults(DNFPredicate predicate, Object[] parameters) { | 166 | public Stream<TupleLike> allResults(DNFPredicate predicate, Tuple parameters) { |
166 | validateParameters(predicate, parameters); | 167 | validateParameters(predicate, parameters); |
167 | return getMatcher(predicate).allResults(parameters); | 168 | return getMatcher(predicate).allResults(parameters); |
168 | } | 169 | } |
@@ -173,7 +174,7 @@ public class ViatraQueryableModel implements QueryableModel { | |||
173 | } | 174 | } |
174 | 175 | ||
175 | @Override | 176 | @Override |
176 | public int countResults(DNFPredicate predicate, Object[] parameters) { | 177 | public int countResults(DNFPredicate predicate, Tuple parameters) { |
177 | validateParameters(predicate, parameters); | 178 | validateParameters(predicate, parameters); |
178 | return getMatcher(predicate).countResults(parameters); | 179 | return getMatcher(predicate).countResults(parameters); |
179 | 180 | ||
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/viewupdate/ModelUpdateListener.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/viewupdate/ModelUpdateListener.java index 5a0da315..1a2fcee7 100644 --- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/viewupdate/ModelUpdateListener.java +++ b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/viewupdate/ModelUpdateListener.java | |||
@@ -3,7 +3,7 @@ package tools.refinery.store.query.viatra.internal.viewupdate; | |||
3 | import org.eclipse.viatra.query.runtime.matchers.context.IInputKey; | 3 | import org.eclipse.viatra.query.runtime.matchers.context.IInputKey; |
4 | import org.eclipse.viatra.query.runtime.matchers.context.IQueryRuntimeContextListener; | 4 | import org.eclipse.viatra.query.runtime.matchers.context.IQueryRuntimeContextListener; |
5 | import org.eclipse.viatra.query.runtime.matchers.tuple.ITuple; | 5 | import org.eclipse.viatra.query.runtime.matchers.tuple.ITuple; |
6 | import tools.refinery.store.model.Tuple; | 6 | import tools.refinery.store.tuple.Tuple; |
7 | import tools.refinery.store.model.representation.Relation; | 7 | import tools.refinery.store.model.representation.Relation; |
8 | import tools.refinery.store.query.view.RelationView; | 8 | import tools.refinery.store.query.view.RelationView; |
9 | 9 | ||
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/viewupdate/ViewUpdateBuffer.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/viewupdate/ViewUpdateBuffer.java index e13a9cb8..49f4c501 100644 --- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/viewupdate/ViewUpdateBuffer.java +++ b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/viewupdate/ViewUpdateBuffer.java | |||
@@ -1,6 +1,6 @@ | |||
1 | package tools.refinery.store.query.viatra.internal.viewupdate; | 1 | package tools.refinery.store.query.viatra.internal.viewupdate; |
2 | 2 | ||
3 | import tools.refinery.store.model.Tuple; | 3 | import tools.refinery.store.tuple.Tuple; |
4 | 4 | ||
5 | import java.util.ArrayList; | 5 | import java.util.ArrayList; |
6 | import java.util.Arrays; | 6 | import java.util.Arrays; |
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/viewupdate/ViewUpdateTranslator.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/viewupdate/ViewUpdateTranslator.java index 62a10e45..74d0b366 100644 --- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/viewupdate/ViewUpdateTranslator.java +++ b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/viewupdate/ViewUpdateTranslator.java | |||
@@ -4,7 +4,7 @@ import org.eclipse.viatra.query.runtime.matchers.context.IInputKey; | |||
4 | import org.eclipse.viatra.query.runtime.matchers.context.IQueryRuntimeContextListener; | 4 | import org.eclipse.viatra.query.runtime.matchers.context.IQueryRuntimeContextListener; |
5 | import org.eclipse.viatra.query.runtime.matchers.tuple.ITuple; | 5 | import org.eclipse.viatra.query.runtime.matchers.tuple.ITuple; |
6 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; | 6 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; |
7 | import tools.refinery.store.model.Tuple; | 7 | import tools.refinery.store.tuple.Tuple; |
8 | import tools.refinery.store.query.view.RelationView; | 8 | import tools.refinery.store.query.view.RelationView; |
9 | 9 | ||
10 | import java.util.Objects; | 10 | import java.util.Objects; |
diff --git a/subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/tests/QueryTest.java b/subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/tests/QueryTest.java index 4307ab6b..d6213b02 100644 --- a/subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/tests/QueryTest.java +++ b/subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/tests/QueryTest.java | |||
@@ -1,7 +1,6 @@ | |||
1 | package tools.refinery.store.query.viatra.tests; | 1 | package tools.refinery.store.query.viatra.tests; |
2 | 2 | ||
3 | import org.junit.jupiter.api.Test; | 3 | import org.junit.jupiter.api.Test; |
4 | import tools.refinery.store.model.Tuple; | ||
5 | import tools.refinery.store.model.representation.Relation; | 4 | import tools.refinery.store.model.representation.Relation; |
6 | import tools.refinery.store.model.representation.TruthValue; | 5 | import tools.refinery.store.model.representation.TruthValue; |
7 | import tools.refinery.store.query.QueryableModel; | 6 | import tools.refinery.store.query.QueryableModel; |
@@ -11,6 +10,8 @@ import tools.refinery.store.query.viatra.ViatraQueryableModelStore; | |||
11 | import tools.refinery.store.query.view.FilteredRelationView; | 10 | import tools.refinery.store.query.view.FilteredRelationView; |
12 | import tools.refinery.store.query.view.KeyOnlyRelationView; | 11 | import tools.refinery.store.query.view.KeyOnlyRelationView; |
13 | import tools.refinery.store.query.view.RelationView; | 12 | import tools.refinery.store.query.view.RelationView; |
13 | import tools.refinery.store.tuple.Tuple; | ||
14 | import tools.refinery.store.tuple.TupleLike; | ||
14 | 15 | ||
15 | import java.util.*; | 16 | import java.util.*; |
16 | import java.util.stream.Stream; | 17 | import java.util.stream.Stream; |
@@ -40,15 +41,16 @@ class QueryTest { | |||
40 | 41 | ||
41 | model.flushChanges(); | 42 | model.flushChanges(); |
42 | assertEquals(2, model.countResults(predicate)); | 43 | assertEquals(2, model.countResults(predicate)); |
43 | compareMatchSets(model.allResults(predicate), Set.of(List.of(Tuple.of(0)), List.of(Tuple.of(1)))); | 44 | compareMatchSets(model.allResults(predicate), Set.of(Tuple.of(0), Tuple.of(1))); |
44 | } | 45 | } |
45 | 46 | ||
46 | @Test | 47 | @Test |
47 | void relationConstraintTest() { | 48 | void relationConstraintTest() { |
48 | Relation<Boolean> person = new Relation<Boolean>("Person", 1, false); | 49 | Relation<Boolean> person = new Relation<>("Person", 1, false); |
49 | Relation<TruthValue> friend = new Relation<>("friend", 2, TruthValue.FALSE); | 50 | Relation<TruthValue> friend = new Relation<>("friend", 2, TruthValue.FALSE); |
50 | RelationView<Boolean> personView = new KeyOnlyRelationView(person); | 51 | RelationView<Boolean> personView = new KeyOnlyRelationView(person); |
51 | RelationView<TruthValue> friendMustView = new FilteredRelationView<TruthValue>(friend, (k, v) -> v.must()); | 52 | RelationView<TruthValue> friendMustView = new FilteredRelationView<>(friend, "must", |
53 | TruthValue::must); | ||
52 | 54 | ||
53 | Variable p1 = new Variable("p1"); | 55 | Variable p1 = new Variable("p1"); |
54 | Variable p2 = new Variable("p2"); | 56 | Variable p2 = new Variable("p2"); |
@@ -78,16 +80,16 @@ class QueryTest { | |||
78 | 80 | ||
79 | model.flushChanges(); | 81 | model.flushChanges(); |
80 | assertEquals(3, model.countResults(predicate)); | 82 | assertEquals(3, model.countResults(predicate)); |
81 | compareMatchSets(model.allResults(predicate), Set.of(List.of(Tuple.of(0), Tuple.of(1)), | 83 | compareMatchSets(model.allResults(predicate), Set.of(Tuple.of(0, 1), Tuple.of(1, 0), Tuple.of(1, 2))); |
82 | List.of(Tuple.of(1), Tuple.of(0)), List.of(Tuple.of(1), Tuple.of(2)))); | ||
83 | } | 84 | } |
84 | 85 | ||
85 | @Test | 86 | @Test |
86 | void andTest() { | 87 | void andTest() { |
87 | Relation<Boolean> person = new Relation<Boolean>("Person", 1, false); | 88 | Relation<Boolean> person = new Relation<>("Person", 1, false); |
88 | Relation<TruthValue> friend = new Relation<>("friend", 2, TruthValue.FALSE); | 89 | Relation<TruthValue> friend = new Relation<>("friend", 2, TruthValue.FALSE); |
89 | RelationView<Boolean> personView = new KeyOnlyRelationView(person); | 90 | RelationView<Boolean> personView = new KeyOnlyRelationView(person); |
90 | RelationView<TruthValue> friendMustView = new FilteredRelationView<TruthValue>(friend, (k, v) -> v.must()); | 91 | RelationView<TruthValue> friendMustView = new FilteredRelationView<>(friend, "must", |
92 | TruthValue::must); | ||
91 | 93 | ||
92 | Variable p1 = new Variable("p1"); | 94 | Variable p1 = new Variable("p1"); |
93 | Variable p2 = new Variable("p2"); | 95 | Variable p2 = new Variable("p2"); |
@@ -120,23 +122,22 @@ class QueryTest { | |||
120 | model.put(friend, Tuple.of(1, 0), TruthValue.TRUE); | 122 | model.put(friend, Tuple.of(1, 0), TruthValue.TRUE); |
121 | model.flushChanges(); | 123 | model.flushChanges(); |
122 | assertEquals(2, model.countResults(predicate)); | 124 | assertEquals(2, model.countResults(predicate)); |
123 | compareMatchSets(model.allResults(predicate), | 125 | compareMatchSets(model.allResults(predicate), Set.of(Tuple.of(0, 1), Tuple.of(1, 0))); |
124 | Set.of(List.of(Tuple.of(0), Tuple.of(1)), List.of(Tuple.of(1), Tuple.of(0)))); | ||
125 | 126 | ||
126 | model.put(friend, Tuple.of(2, 0), TruthValue.TRUE); | 127 | model.put(friend, Tuple.of(2, 0), TruthValue.TRUE); |
127 | model.flushChanges(); | 128 | model.flushChanges(); |
128 | assertEquals(4, model.countResults(predicate)); | 129 | assertEquals(4, model.countResults(predicate)); |
129 | compareMatchSets(model.allResults(predicate), | 130 | compareMatchSets(model.allResults(predicate), Set.of(Tuple.of(0, 1), Tuple.of(1, 0), Tuple.of(0, 2), |
130 | Set.of(List.of(Tuple.of(0), Tuple.of(1)), List.of(Tuple.of(1), Tuple.of(0)), | 131 | Tuple.of(2, 0))); |
131 | List.of(Tuple.of(0), Tuple.of(2)), List.of(Tuple.of(2), Tuple.of(0)))); | ||
132 | } | 132 | } |
133 | 133 | ||
134 | @Test | 134 | @Test |
135 | void existTest() { | 135 | void existTest() { |
136 | Relation<Boolean> person = new Relation<Boolean>("Person", 1, false); | 136 | Relation<Boolean> person = new Relation<>("Person", 1, false); |
137 | Relation<TruthValue> friend = new Relation<>("friend", 2, TruthValue.FALSE); | 137 | Relation<TruthValue> friend = new Relation<>("friend", 2, TruthValue.FALSE); |
138 | RelationView<Boolean> personView = new KeyOnlyRelationView(person); | 138 | RelationView<Boolean> personView = new KeyOnlyRelationView(person); |
139 | RelationView<TruthValue> friendMustView = new FilteredRelationView<TruthValue>(friend, (k, v) -> v.must()); | 139 | RelationView<TruthValue> friendMustView = new FilteredRelationView<>(friend, "must", |
140 | TruthValue::must); | ||
140 | 141 | ||
141 | Variable p1 = new Variable("p1"); | 142 | Variable p1 = new Variable("p1"); |
142 | Variable p2 = new Variable("p2"); | 143 | Variable p2 = new Variable("p2"); |
@@ -166,7 +167,7 @@ class QueryTest { | |||
166 | 167 | ||
167 | model.flushChanges(); | 168 | model.flushChanges(); |
168 | assertEquals(2, model.countResults(predicate)); | 169 | assertEquals(2, model.countResults(predicate)); |
169 | compareMatchSets(model.allResults(predicate), Set.of(List.of(Tuple.of(0)), List.of(Tuple.of(1)))); | 170 | compareMatchSets(model.allResults(predicate), Set.of(Tuple.of(0), Tuple.of(1))); |
170 | } | 171 | } |
171 | 172 | ||
172 | @Test | 173 | @Test |
@@ -176,7 +177,8 @@ class QueryTest { | |||
176 | Relation<TruthValue> friend = new Relation<>("friend", 2, TruthValue.FALSE); | 177 | Relation<TruthValue> friend = new Relation<>("friend", 2, TruthValue.FALSE); |
177 | RelationView<Boolean> personView = new KeyOnlyRelationView(person); | 178 | RelationView<Boolean> personView = new KeyOnlyRelationView(person); |
178 | RelationView<Boolean> animalView = new KeyOnlyRelationView(animal); | 179 | RelationView<Boolean> animalView = new KeyOnlyRelationView(animal); |
179 | RelationView<TruthValue> friendMustView = new FilteredRelationView<TruthValue>(friend, (k, v) -> v.must()); | 180 | RelationView<TruthValue> friendMustView = new FilteredRelationView<>(friend, "must", |
181 | TruthValue::must); | ||
180 | 182 | ||
181 | Variable p1 = new Variable("p1"); | 183 | Variable p1 = new Variable("p1"); |
182 | Variable p2 = new Variable("p2"); | 184 | Variable p2 = new Variable("p2"); |
@@ -196,8 +198,7 @@ class QueryTest { | |||
196 | DNFAnd clause2 = new DNFAnd(Collections.emptySet(), | 198 | DNFAnd clause2 = new DNFAnd(Collections.emptySet(), |
197 | Arrays.asList(animalRelationAtom1, animalRelationAtom2, friendRelationAtom2)); | 199 | Arrays.asList(animalRelationAtom1, animalRelationAtom2, friendRelationAtom2)); |
198 | 200 | ||
199 | // No inter-species friendship | 201 | // No friendship between species |
200 | |||
201 | DNFPredicate predicate = new DNFPredicate("Or", parameters, Arrays.asList(clause1, clause2)); | 202 | DNFPredicate predicate = new DNFPredicate("Or", parameters, Arrays.asList(clause1, clause2)); |
202 | 203 | ||
203 | QueryableModelStore store = new ViatraQueryableModelStore(Set.of(person, animal, friend), | 204 | QueryableModelStore store = new ViatraQueryableModelStore(Set.of(person, animal, friend), |
@@ -215,13 +216,12 @@ class QueryTest { | |||
215 | 216 | ||
216 | model.flushChanges(); | 217 | model.flushChanges(); |
217 | assertEquals(2, model.countResults(predicate)); | 218 | assertEquals(2, model.countResults(predicate)); |
218 | compareMatchSets(model.allResults(predicate), | 219 | compareMatchSets(model.allResults(predicate), Set.of(Tuple.of(0, 1), Tuple.of(2, 3))); |
219 | Set.of(List.of(Tuple.of(0), Tuple.of(1)), List.of(Tuple.of(2), Tuple.of(3)))); | ||
220 | } | 220 | } |
221 | 221 | ||
222 | @Test | 222 | @Test |
223 | void equalityTest() { | 223 | void equalityTest() { |
224 | Relation<Boolean> person = new Relation<Boolean>("Person", 1, false); | 224 | Relation<Boolean> person = new Relation<>("Person", 1, false); |
225 | RelationView<Boolean> personView = new KeyOnlyRelationView(person); | 225 | RelationView<Boolean> personView = new KeyOnlyRelationView(person); |
226 | 226 | ||
227 | Variable p1 = new Variable("p1"); | 227 | Variable p1 = new Variable("p1"); |
@@ -244,16 +244,16 @@ class QueryTest { | |||
244 | 244 | ||
245 | model.flushChanges(); | 245 | model.flushChanges(); |
246 | assertEquals(3, model.countResults(predicate)); | 246 | assertEquals(3, model.countResults(predicate)); |
247 | compareMatchSets(model.allResults(predicate), Set.of(List.of(Tuple.of(0), Tuple.of(0)), | 247 | compareMatchSets(model.allResults(predicate), Set.of(Tuple.of(0, 0), Tuple.of(1, 1), Tuple.of(2, 2))); |
248 | List.of(Tuple.of(1), Tuple.of(1)), List.of(Tuple.of(2), Tuple.of(2)))); | ||
249 | } | 248 | } |
250 | 249 | ||
251 | @Test | 250 | @Test |
252 | void inequalityTest() { | 251 | void inequalityTest() { |
253 | Relation<Boolean> person = new Relation<Boolean>("Person", 1, false); | 252 | Relation<Boolean> person = new Relation<>("Person", 1, false); |
254 | Relation<TruthValue> friend = new Relation<>("friend", 2, TruthValue.FALSE); | 253 | Relation<TruthValue> friend = new Relation<>("friend", 2, TruthValue.FALSE); |
255 | RelationView<Boolean> personView = new KeyOnlyRelationView(person); | 254 | RelationView<Boolean> personView = new KeyOnlyRelationView(person); |
256 | RelationView<TruthValue> friendMustView = new FilteredRelationView<TruthValue>(friend, (k, v) -> v.must()); | 255 | RelationView<TruthValue> friendMustView = new FilteredRelationView<>(friend, "must", |
256 | TruthValue::must); | ||
257 | 257 | ||
258 | Variable p1 = new Variable("p1"); | 258 | Variable p1 = new Variable("p1"); |
259 | Variable p2 = new Variable("p2"); | 259 | Variable p2 = new Variable("p2"); |
@@ -281,16 +281,16 @@ class QueryTest { | |||
281 | 281 | ||
282 | model.flushChanges(); | 282 | model.flushChanges(); |
283 | assertEquals(2, model.countResults(predicate)); | 283 | assertEquals(2, model.countResults(predicate)); |
284 | compareMatchSets(model.allResults(predicate), | 284 | compareMatchSets(model.allResults(predicate), Set.of(Tuple.of(0, 1, 2), Tuple.of(1, 0, 2))); |
285 | Set.of(List.of(Tuple.of(0), Tuple.of(1), Tuple.of(2)), List.of(Tuple.of(1), Tuple.of(0), Tuple.of(2)))); | ||
286 | } | 285 | } |
287 | 286 | ||
288 | @Test | 287 | @Test |
289 | void patternCallTest() { | 288 | void patternCallTest() { |
290 | Relation<Boolean> person = new Relation<Boolean>("Person", 1, false); | 289 | Relation<Boolean> person = new Relation<>("Person", 1, false); |
291 | Relation<TruthValue> friend = new Relation<>("friend", 2, TruthValue.FALSE); | 290 | Relation<TruthValue> friend = new Relation<>("friend", 2, TruthValue.FALSE); |
292 | RelationView<Boolean> personView = new KeyOnlyRelationView(person); | 291 | RelationView<Boolean> personView = new KeyOnlyRelationView(person); |
293 | RelationView<TruthValue> friendMustView = new FilteredRelationView<TruthValue>(friend, (k, v) -> v.must()); | 292 | RelationView<TruthValue> friendMustView = new FilteredRelationView<>(friend, "must", |
293 | TruthValue::must); | ||
294 | 294 | ||
295 | Variable p1 = new Variable("p1"); | 295 | Variable p1 = new Variable("p1"); |
296 | Variable p2 = new Variable("p2"); | 296 | Variable p2 = new Variable("p2"); |
@@ -331,10 +331,11 @@ class QueryTest { | |||
331 | 331 | ||
332 | @Test | 332 | @Test |
333 | void negativePatternCallTest() { | 333 | void negativePatternCallTest() { |
334 | Relation<Boolean> person = new Relation<Boolean>("Person", 1, false); | 334 | Relation<Boolean> person = new Relation<>("Person", 1, false); |
335 | Relation<TruthValue> friend = new Relation<>("friend", 2, TruthValue.FALSE); | 335 | Relation<TruthValue> friend = new Relation<>("friend", 2, TruthValue.FALSE); |
336 | RelationView<Boolean> personView = new KeyOnlyRelationView(person); | 336 | RelationView<Boolean> personView = new KeyOnlyRelationView(person); |
337 | RelationView<TruthValue> friendMustView = new FilteredRelationView<TruthValue>(friend, (k, v) -> v.must()); | 337 | RelationView<TruthValue> friendMustView = new FilteredRelationView<>(friend, "must", |
338 | TruthValue::must); | ||
338 | 339 | ||
339 | Variable p1 = new Variable("p1"); | 340 | Variable p1 = new Variable("p1"); |
340 | Variable p2 = new Variable("p2"); | 341 | Variable p2 = new Variable("p2"); |
@@ -375,10 +376,11 @@ class QueryTest { | |||
375 | 376 | ||
376 | @Test | 377 | @Test |
377 | void transitivePatternCallTest() { | 378 | void transitivePatternCallTest() { |
378 | Relation<Boolean> person = new Relation<Boolean>("Person", 1, false); | 379 | Relation<Boolean> person = new Relation<>("Person", 1, false); |
379 | Relation<TruthValue> friend = new Relation<>("friend", 2, TruthValue.FALSE); | 380 | Relation<TruthValue> friend = new Relation<>("friend", 2, TruthValue.FALSE); |
380 | RelationView<Boolean> personView = new KeyOnlyRelationView(person); | 381 | RelationView<Boolean> personView = new KeyOnlyRelationView(person); |
381 | RelationView<TruthValue> friendMustView = new FilteredRelationView<TruthValue>(friend, (k, v) -> v.must()); | 382 | RelationView<TruthValue> friendMustView = new FilteredRelationView<>(friend, "must", |
383 | TruthValue::must); | ||
382 | 384 | ||
383 | Variable p1 = new Variable("p1"); | 385 | Variable p1 = new Variable("p1"); |
384 | Variable p2 = new Variable("p2"); | 386 | Variable p2 = new Variable("p2"); |
@@ -415,18 +417,14 @@ class QueryTest { | |||
415 | model.flushChanges(); | 417 | model.flushChanges(); |
416 | assertEquals(3, model.countResults(predicate)); | 418 | assertEquals(3, model.countResults(predicate)); |
417 | } | 419 | } |
418 | static void compareMatchSets(Stream<Object[]> matchSet, Set<List<Tuple>> expected) { | 420 | |
419 | Set<List<Tuple>> translatedMatchSet = new HashSet<>(); | 421 | static void compareMatchSets(Stream<TupleLike> matchSet, Set<Tuple> expected) { |
422 | Set<Tuple> translatedMatchSet = new HashSet<>(); | ||
420 | var iterator = matchSet.iterator(); | 423 | var iterator = matchSet.iterator(); |
421 | while (iterator.hasNext()) { | 424 | while (iterator.hasNext()) { |
422 | var element = iterator.next(); | 425 | var element = iterator.next(); |
423 | List<Tuple> elementToTranslatedMatchSet = new ArrayList<>(); | 426 | translatedMatchSet.add(element.toTuple()); |
424 | for (Object o : element) { | ||
425 | elementToTranslatedMatchSet.add((Tuple) o); | ||
426 | } | ||
427 | translatedMatchSet.add(elementToTranslatedMatchSet); | ||
428 | } | 427 | } |
429 | |||
430 | assertEquals(expected, translatedMatchSet); | 428 | assertEquals(expected, translatedMatchSet); |
431 | } | 429 | } |
432 | } | 430 | } |
diff --git a/subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/tests/QueryTransactionTest.java b/subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/tests/QueryTransactionTest.java index 613d0074..f57bca2b 100644 --- a/subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/tests/QueryTransactionTest.java +++ b/subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/tests/QueryTransactionTest.java | |||
@@ -1,7 +1,7 @@ | |||
1 | package tools.refinery.store.query.viatra.tests; | 1 | package tools.refinery.store.query.viatra.tests; |
2 | 2 | ||
3 | import org.junit.jupiter.api.Test; | 3 | import org.junit.jupiter.api.Test; |
4 | import tools.refinery.store.model.Tuple; | 4 | import tools.refinery.store.tuple.Tuple; |
5 | import tools.refinery.store.model.representation.Relation; | 5 | import tools.refinery.store.model.representation.Relation; |
6 | import tools.refinery.store.query.QueryableModel; | 6 | import tools.refinery.store.query.QueryableModel; |
7 | import tools.refinery.store.query.QueryableModelStore; | 7 | import tools.refinery.store.query.QueryableModelStore; |
diff --git a/subprojects/store/src/main/java/tools/refinery/store/model/ModelStoreImpl.java b/subprojects/store/src/main/java/tools/refinery/store/model/ModelStoreImpl.java index 97406cbb..b5e1c453 100644 --- a/subprojects/store/src/main/java/tools/refinery/store/model/ModelStoreImpl.java +++ b/subprojects/store/src/main/java/tools/refinery/store/model/ModelStoreImpl.java | |||
@@ -16,6 +16,7 @@ import tools.refinery.store.model.internal.SimilarRelationEquivalenceClass; | |||
16 | import tools.refinery.store.model.representation.AuxilaryData; | 16 | import tools.refinery.store.model.representation.AuxilaryData; |
17 | import tools.refinery.store.model.representation.DataRepresentation; | 17 | import tools.refinery.store.model.representation.DataRepresentation; |
18 | import tools.refinery.store.model.representation.Relation; | 18 | import tools.refinery.store.model.representation.Relation; |
19 | import tools.refinery.store.tuple.Tuple; | ||
19 | 20 | ||
20 | import java.util.Set; | 21 | import java.util.Set; |
21 | 22 | ||
diff --git a/subprojects/store/src/main/java/tools/refinery/store/model/Tuple.java b/subprojects/store/src/main/java/tools/refinery/store/model/Tuple.java deleted file mode 100644 index 0aae3727..00000000 --- a/subprojects/store/src/main/java/tools/refinery/store/model/Tuple.java +++ /dev/null | |||
@@ -1,148 +0,0 @@ | |||
1 | package tools.refinery.store.model; | ||
2 | |||
3 | import java.util.ArrayList; | ||
4 | import java.util.Arrays; | ||
5 | import java.util.List; | ||
6 | |||
7 | public abstract class Tuple { | ||
8 | private static final int CUSTOMTUPLESIZE = 2; | ||
9 | protected static final List<Tuple1> tuple1Cash = new ArrayList<>(1024); | ||
10 | |||
11 | public abstract int getSize(); | ||
12 | public abstract int get(int element); | ||
13 | public abstract int[] toArray(); | ||
14 | |||
15 | @Override | ||
16 | public String toString() { | ||
17 | StringBuilder b = new StringBuilder(); | ||
18 | b.append("["); | ||
19 | for(int i = 0; i<getSize(); i++) { | ||
20 | if(i!=0) { | ||
21 | b.append(","); | ||
22 | } | ||
23 | b.append(get(i)); | ||
24 | } | ||
25 | b.append("]"); | ||
26 | return b.toString(); | ||
27 | } | ||
28 | |||
29 | public static Tuple1 of1(int value) { | ||
30 | if(value < tuple1Cash.size()) { | ||
31 | return tuple1Cash.get(value); | ||
32 | } else { | ||
33 | Tuple1 newlyCreated = null; | ||
34 | while(value >= tuple1Cash.size()) { | ||
35 | newlyCreated = new Tuple1(tuple1Cash.size()); | ||
36 | tuple1Cash.add(newlyCreated); | ||
37 | } | ||
38 | return newlyCreated; | ||
39 | } | ||
40 | } | ||
41 | |||
42 | public static Tuple of(int... values) { | ||
43 | if(values.length == 0) { | ||
44 | return new Tuple0(); | ||
45 | } else if(values.length == 1) { | ||
46 | return of1(values[0]); | ||
47 | } else if(values.length == 2) { | ||
48 | return new Tuple2(values[0],values[1]); | ||
49 | } else return new TupleN(values); | ||
50 | } | ||
51 | |||
52 | protected IllegalArgumentException doesNotContain(int element) { | ||
53 | return new IllegalArgumentException("Tuple does not contain element "+element); | ||
54 | } | ||
55 | |||
56 | public static class Tuple0 extends Tuple{ | ||
57 | protected Tuple0() { } | ||
58 | @Override public int getSize() { return 0; } | ||
59 | @Override public int get(int element) { | ||
60 | throw doesNotContain(element); | ||
61 | } | ||
62 | @Override public int[] toArray() {return new int[]{};} | ||
63 | @Override public int hashCode() { return TupleHashProvider.singleton().getHash(this, 0); } | ||
64 | @Override | ||
65 | public boolean equals(Object obj) { | ||
66 | if (this == obj) | ||
67 | return true; | ||
68 | if (obj == null) | ||
69 | return false; | ||
70 | if (getClass() != obj.getClass()) | ||
71 | return false; | ||
72 | return true; | ||
73 | } | ||
74 | } | ||
75 | public static class Tuple1 extends Tuple{ | ||
76 | final int value0; | ||
77 | protected Tuple1(int value0) { this.value0 = value0; } | ||
78 | @Override public int getSize() { return 1; } | ||
79 | @Override public int get(int element) { | ||
80 | if(element == 0) return value0; | ||
81 | throw doesNotContain(element); | ||
82 | } | ||
83 | @Override public int[] toArray() {return new int[]{ value0 };} | ||
84 | @Override public int hashCode() { return TupleHashProvider.singleton().getHash(this, 0); } | ||
85 | @Override | ||
86 | public boolean equals(Object obj) { | ||
87 | if (this == obj) | ||
88 | return true; | ||
89 | if (obj == null) | ||
90 | return false; | ||
91 | if (getClass() != obj.getClass()) | ||
92 | return false; | ||
93 | Tuple1 other = (Tuple1) obj; | ||
94 | return value0 == other.value0; | ||
95 | } | ||
96 | } | ||
97 | public static class Tuple2 extends Tuple{ | ||
98 | final int value0; | ||
99 | final int value1; | ||
100 | protected Tuple2(int value0, int value1) { this.value0 = value0; this.value1 = value1; } | ||
101 | @Override public int getSize() { return 2; } | ||
102 | @Override public int get(int element) { | ||
103 | if(element == 0) return value0; | ||
104 | else if(element == 1) return value1; | ||
105 | throw doesNotContain(element); | ||
106 | } | ||
107 | @Override public int[] toArray() {return new int[]{ value0,value1 };} | ||
108 | @Override public int hashCode() { return TupleHashProvider.singleton().getHash(this, 0); } | ||
109 | @Override | ||
110 | public boolean equals(Object obj) { | ||
111 | if (this == obj) | ||
112 | return true; | ||
113 | if (obj == null) | ||
114 | return false; | ||
115 | if (getClass() != obj.getClass()) | ||
116 | return false; | ||
117 | Tuple2 other = (Tuple2) obj; | ||
118 | return value0 == other.value0 && value1 == other.value1; | ||
119 | } | ||
120 | } | ||
121 | public static class TupleN extends Tuple{ | ||
122 | final int[] values; | ||
123 | protected TupleN(int[] values) { | ||
124 | if(values.length<CUSTOMTUPLESIZE) | ||
125 | throw new IllegalArgumentException(); | ||
126 | this.values = Arrays.copyOf(values, values.length); | ||
127 | } | ||
128 | @Override public int getSize() { return values.length; } | ||
129 | @Override public int get(int element) { | ||
130 | if(0<=element && element < values.length) { | ||
131 | return values[element]; | ||
132 | } else throw doesNotContain(element); | ||
133 | } | ||
134 | @Override public int[] toArray() { return values; } | ||
135 | @Override public int hashCode() { return TupleHashProvider.singleton().getHash(this, 0); } | ||
136 | @Override | ||
137 | public boolean equals(Object obj) { | ||
138 | if (this == obj) | ||
139 | return true; | ||
140 | if (obj == null) | ||
141 | return false; | ||
142 | if (getClass() != obj.getClass()) | ||
143 | return false; | ||
144 | TupleN other = (TupleN) obj; | ||
145 | return Arrays.equals(values, other.values); | ||
146 | } | ||
147 | } | ||
148 | } | ||
diff --git a/subprojects/store/src/main/java/tools/refinery/store/model/TupleHashProvider.java b/subprojects/store/src/main/java/tools/refinery/store/model/TupleHashProvider.java index 7a01311a..988ce423 100644 --- a/subprojects/store/src/main/java/tools/refinery/store/model/TupleHashProvider.java +++ b/subprojects/store/src/main/java/tools/refinery/store/model/TupleHashProvider.java | |||
@@ -1,6 +1,7 @@ | |||
1 | package tools.refinery.store.model; | 1 | package tools.refinery.store.model; |
2 | 2 | ||
3 | import tools.refinery.store.map.ContinousHashProvider; | 3 | import tools.refinery.store.map.ContinousHashProvider; |
4 | import tools.refinery.store.tuple.Tuple; | ||
4 | 5 | ||
5 | public class TupleHashProvider implements ContinousHashProvider<Tuple> { | 6 | public class TupleHashProvider implements ContinousHashProvider<Tuple> { |
6 | protected static TupleHashProvider instance; | 7 | protected static TupleHashProvider instance; |
@@ -39,7 +40,7 @@ public class TupleHashProvider implements ContinousHashProvider<Tuple> { | |||
39 | 3527, 3529, 3533, 3539, 3541, 3547, 3557, 3559, 3571, 3581, 3583, 3593, 3607, 3613, 3617, 3623, 3631, 3637, | 40 | 3527, 3529, 3533, 3539, 3541, 3547, 3557, 3559, 3571, 3581, 3583, 3593, 3607, 3613, 3617, 3623, 3631, 3637, |
40 | 3643, 3659, 3671, 3673, 3677, 3691, 3697, 3701, 3709, 3719, 3727, 3733, 3739, 3761, 3767, 3769, 3779, 3793, | 41 | 3643, 3659, 3671, 3673, 3677, 3691, 3697, 3701, 3709, 3719, 3727, 3733, 3739, 3761, 3767, 3769, 3779, 3793, |
41 | 3797, 3803, 3821, 3823, 3833, 3847, 3851, 3853, 3863, 3877, 3881, 3889, 3907, 3911 }; | 42 | 3797, 3803, 3821, 3823, 3833, 3847, 3851, 3853, 3863, 3877, 3881, 3889, 3907, 3911 }; |
42 | 43 | ||
43 | protected static final long LARGESTPRIME30BITS = 1073741789; | 44 | protected static final long LARGESTPRIME30BITS = 1073741789; |
44 | 45 | ||
45 | public TupleHashProvider() { | 46 | public TupleHashProvider() { |
diff --git a/subprojects/store/src/main/java/tools/refinery/store/model/TupleHashProviderBitMagic.java b/subprojects/store/src/main/java/tools/refinery/store/model/TupleHashProviderBitMagic.java index 5b053229..33059a1b 100644 --- a/subprojects/store/src/main/java/tools/refinery/store/model/TupleHashProviderBitMagic.java +++ b/subprojects/store/src/main/java/tools/refinery/store/model/TupleHashProviderBitMagic.java | |||
@@ -1,6 +1,7 @@ | |||
1 | package tools.refinery.store.model; | 1 | package tools.refinery.store.model; |
2 | 2 | ||
3 | import tools.refinery.store.map.ContinousHashProvider; | 3 | import tools.refinery.store.map.ContinousHashProvider; |
4 | import tools.refinery.store.tuple.Tuple; | ||
4 | 5 | ||
5 | public class TupleHashProviderBitMagic implements ContinousHashProvider<Tuple> { | 6 | public class TupleHashProviderBitMagic implements ContinousHashProvider<Tuple> { |
6 | 7 | ||
@@ -9,12 +10,12 @@ public class TupleHashProviderBitMagic implements ContinousHashProvider<Tuple> { | |||
9 | if(key.getSize() == 1) { | 10 | if(key.getSize() == 1) { |
10 | return key.get(0); | 11 | return key.get(0); |
11 | } | 12 | } |
12 | 13 | ||
13 | int result = 0; | 14 | int result = 0; |
14 | final int startBitIndex = index*30; | 15 | final int startBitIndex = index*30; |
15 | final int finalBitIndex = startBitIndex+30; | 16 | final int finalBitIndex = startBitIndex+30; |
16 | final int arity = key.getSize(); | 17 | final int arity = key.getSize(); |
17 | 18 | ||
18 | for(int i = startBitIndex; i<=finalBitIndex; i++) { | 19 | for(int i = startBitIndex; i<=finalBitIndex; i++) { |
19 | final int selectedKey = key.get(i%arity); | 20 | final int selectedKey = key.get(i%arity); |
20 | final int selectedPosition = 1<<(i/arity); | 21 | final int selectedPosition = 1<<(i/arity); |
@@ -22,7 +23,7 @@ public class TupleHashProviderBitMagic implements ContinousHashProvider<Tuple> { | |||
22 | result |= 1<<(i%30); | 23 | result |= 1<<(i%30); |
23 | } | 24 | } |
24 | } | 25 | } |
25 | 26 | ||
26 | return result; | 27 | return result; |
27 | } | 28 | } |
28 | } | 29 | } |
diff --git a/subprojects/store/src/main/java/tools/refinery/store/model/internal/SimilarRelationEquivalenceClass.java b/subprojects/store/src/main/java/tools/refinery/store/model/internal/SimilarRelationEquivalenceClass.java index 9d1b1dd0..9939f17e 100644 --- a/subprojects/store/src/main/java/tools/refinery/store/model/internal/SimilarRelationEquivalenceClass.java +++ b/subprojects/store/src/main/java/tools/refinery/store/model/internal/SimilarRelationEquivalenceClass.java | |||
@@ -3,7 +3,7 @@ package tools.refinery.store.model.internal; | |||
3 | import java.util.Objects; | 3 | import java.util.Objects; |
4 | 4 | ||
5 | import tools.refinery.store.map.ContinousHashProvider; | 5 | import tools.refinery.store.map.ContinousHashProvider; |
6 | import tools.refinery.store.model.Tuple; | 6 | import tools.refinery.store.tuple.Tuple; |
7 | import tools.refinery.store.model.representation.Relation; | 7 | import tools.refinery.store.model.representation.Relation; |
8 | 8 | ||
9 | public class SimilarRelationEquivalenceClass { | 9 | public class SimilarRelationEquivalenceClass { |
@@ -29,5 +29,5 @@ public class SimilarRelationEquivalenceClass { | |||
29 | return arity == other.arity && Objects.equals(defaultValue, other.defaultValue) | 29 | return arity == other.arity && Objects.equals(defaultValue, other.defaultValue) |
30 | && Objects.equals(hashProvider, other.hashProvider); | 30 | && Objects.equals(hashProvider, other.hashProvider); |
31 | } | 31 | } |
32 | 32 | ||
33 | } | 33 | } |
diff --git a/subprojects/store/src/main/java/tools/refinery/store/model/representation/Relation.java b/subprojects/store/src/main/java/tools/refinery/store/model/representation/Relation.java index fc2a3185..c0f31d08 100644 --- a/subprojects/store/src/main/java/tools/refinery/store/model/representation/Relation.java +++ b/subprojects/store/src/main/java/tools/refinery/store/model/representation/Relation.java | |||
@@ -1,6 +1,6 @@ | |||
1 | package tools.refinery.store.model.representation; | 1 | package tools.refinery.store.model.representation; |
2 | 2 | ||
3 | import tools.refinery.store.model.Tuple; | 3 | import tools.refinery.store.tuple.Tuple; |
4 | import tools.refinery.store.model.TupleHashProvider; | 4 | import tools.refinery.store.model.TupleHashProvider; |
5 | 5 | ||
6 | public class Relation<D> extends DataRepresentation<Tuple, D> { | 6 | public class Relation<D> extends DataRepresentation<Tuple, D> { |
diff --git a/subprojects/store/src/main/java/tools/refinery/store/query/QueryableModel.java b/subprojects/store/src/main/java/tools/refinery/store/query/QueryableModel.java index 187abbc2..648c3a36 100644 --- a/subprojects/store/src/main/java/tools/refinery/store/query/QueryableModel.java +++ b/subprojects/store/src/main/java/tools/refinery/store/query/QueryableModel.java | |||
@@ -2,12 +2,14 @@ package tools.refinery.store.query; | |||
2 | 2 | ||
3 | import tools.refinery.store.model.Model; | 3 | import tools.refinery.store.model.Model; |
4 | import tools.refinery.store.query.building.DNFPredicate; | 4 | import tools.refinery.store.query.building.DNFPredicate; |
5 | import tools.refinery.store.tuple.Tuple; | ||
6 | import tools.refinery.store.tuple.TupleLike; | ||
5 | 7 | ||
6 | import java.util.Optional; | 8 | import java.util.Optional; |
7 | import java.util.Set; | 9 | import java.util.Set; |
8 | import java.util.stream.Stream; | 10 | import java.util.stream.Stream; |
9 | 11 | ||
10 | public interface QueryableModel extends Model{ | 12 | public interface QueryableModel extends Model { |
11 | Set<DNFPredicate> getPredicates(); | 13 | Set<DNFPredicate> getPredicates(); |
12 | 14 | ||
13 | boolean hasChanges(); | 15 | boolean hasChanges(); |
@@ -16,17 +18,17 @@ public interface QueryableModel extends Model{ | |||
16 | 18 | ||
17 | boolean hasResult(DNFPredicate predicate); | 19 | boolean hasResult(DNFPredicate predicate); |
18 | 20 | ||
19 | boolean hasResult(DNFPredicate predicate, Object[] parameters); | 21 | boolean hasResult(DNFPredicate predicate, Tuple parameters); |
20 | 22 | ||
21 | Optional<Object[]> oneResult(DNFPredicate predicate); | 23 | Optional<TupleLike> oneResult(DNFPredicate predicate); |
22 | 24 | ||
23 | Optional<Object[]> oneResult(DNFPredicate predicate, Object[] parameters); | 25 | Optional<TupleLike> oneResult(DNFPredicate predicate, Tuple parameters); |
24 | 26 | ||
25 | Stream<Object[]> allResults(DNFPredicate predicate); | 27 | Stream<TupleLike> allResults(DNFPredicate predicate); |
26 | 28 | ||
27 | Stream<Object[]> allResults(DNFPredicate predicate, Object[] parameters); | 29 | Stream<TupleLike> allResults(DNFPredicate predicate, Tuple parameters); |
28 | 30 | ||
29 | int countResults(DNFPredicate predicate); | 31 | int countResults(DNFPredicate predicate); |
30 | 32 | ||
31 | int countResults(DNFPredicate predicate, Object[] parameters); | 33 | int countResults(DNFPredicate predicate, Tuple parameters); |
32 | } | 34 | } |
diff --git a/subprojects/store/src/main/java/tools/refinery/store/query/QueryableModelStore.java b/subprojects/store/src/main/java/tools/refinery/store/query/QueryableModelStore.java index 08efe17c..878e1058 100644 --- a/subprojects/store/src/main/java/tools/refinery/store/query/QueryableModelStore.java +++ b/subprojects/store/src/main/java/tools/refinery/store/query/QueryableModelStore.java | |||
@@ -1,6 +1,5 @@ | |||
1 | package tools.refinery.store.query; | 1 | package tools.refinery.store.query; |
2 | 2 | ||
3 | import tools.refinery.store.model.ModelDiffCursor; | ||
4 | import tools.refinery.store.model.ModelStore; | 3 | import tools.refinery.store.model.ModelStore; |
5 | import tools.refinery.store.model.representation.DataRepresentation; | 4 | import tools.refinery.store.model.representation.DataRepresentation; |
6 | import tools.refinery.store.query.building.DNFPredicate; | 5 | import tools.refinery.store.query.building.DNFPredicate; |
@@ -8,16 +7,16 @@ import tools.refinery.store.query.view.RelationView; | |||
8 | 7 | ||
9 | import java.util.Set; | 8 | import java.util.Set; |
10 | 9 | ||
11 | public interface QueryableModelStore extends ModelStore{ | 10 | public interface QueryableModelStore extends ModelStore { |
12 | @SuppressWarnings("squid:S1452") | 11 | @SuppressWarnings("squid:S1452") |
13 | Set<DataRepresentation<?, ?>> getDataRepresentations(); | 12 | Set<DataRepresentation<?, ?>> getDataRepresentations(); |
13 | |||
14 | @SuppressWarnings("squid:S1452") | 14 | @SuppressWarnings("squid:S1452") |
15 | Set<RelationView<?>> getViews(); | 15 | Set<RelationView<?>> getViews(); |
16 | |||
16 | Set<DNFPredicate> getPredicates(); | 17 | Set<DNFPredicate> getPredicates(); |
17 | 18 | ||
18 | QueryableModel createModel(); | 19 | QueryableModel createModel(); |
19 | QueryableModel createModel(long state); | ||
20 | 20 | ||
21 | Set<Long> getStates(); | 21 | QueryableModel createModel(long state); |
22 | ModelDiffCursor getDiffCursor(long from, long to); | ||
23 | } | 22 | } |
diff --git a/subprojects/store/src/main/java/tools/refinery/store/query/view/AbstractFilteredRelationView.java b/subprojects/store/src/main/java/tools/refinery/store/query/view/AbstractFilteredRelationView.java index a21a38ba..79de1c4d 100644 --- a/subprojects/store/src/main/java/tools/refinery/store/query/view/AbstractFilteredRelationView.java +++ b/subprojects/store/src/main/java/tools/refinery/store/query/view/AbstractFilteredRelationView.java | |||
@@ -1,8 +1,8 @@ | |||
1 | package tools.refinery.store.query.view; | 1 | package tools.refinery.store.query.view; |
2 | 2 | ||
3 | import tools.refinery.store.model.Model; | 3 | import tools.refinery.store.model.Model; |
4 | import tools.refinery.store.model.Tuple; | 4 | import tools.refinery.store.tuple.Tuple; |
5 | import tools.refinery.store.model.Tuple.Tuple1; | 5 | import tools.refinery.store.tuple.Tuple1; |
6 | import tools.refinery.store.model.representation.Relation; | 6 | import tools.refinery.store.model.representation.Relation; |
7 | 7 | ||
8 | public abstract class AbstractFilteredRelationView<D> extends RelationView<D> { | 8 | public abstract class AbstractFilteredRelationView<D> extends RelationView<D> { |
@@ -23,7 +23,7 @@ public abstract class AbstractFilteredRelationView<D> extends RelationView<D> { | |||
23 | public boolean get(Model model, Object[] tuple) { | 23 | public boolean get(Model model, Object[] tuple) { |
24 | int[] content = new int[tuple.length]; | 24 | int[] content = new int[tuple.length]; |
25 | for (int i = 0; i < tuple.length; i++) { | 25 | for (int i = 0; i < tuple.length; i++) { |
26 | content[i] = ((Tuple1) tuple[i]).get(0); | 26 | content[i] = ((Tuple1) tuple[i]).value0(); |
27 | } | 27 | } |
28 | Tuple key = Tuple.of(content); | 28 | Tuple key = Tuple.of(content); |
29 | D value = model.get(getRepresentation(), key); | 29 | D value = model.get(getRepresentation(), key); |
diff --git a/subprojects/store/src/main/java/tools/refinery/store/query/view/FilteredRelationView.java b/subprojects/store/src/main/java/tools/refinery/store/query/view/FilteredRelationView.java index bb5d0237..3b639979 100644 --- a/subprojects/store/src/main/java/tools/refinery/store/query/view/FilteredRelationView.java +++ b/subprojects/store/src/main/java/tools/refinery/store/query/view/FilteredRelationView.java | |||
@@ -1,6 +1,6 @@ | |||
1 | package tools.refinery.store.query.view; | 1 | package tools.refinery.store.query.view; |
2 | 2 | ||
3 | import tools.refinery.store.model.Tuple; | 3 | import tools.refinery.store.tuple.Tuple; |
4 | import tools.refinery.store.model.representation.Relation; | 4 | import tools.refinery.store.model.representation.Relation; |
5 | 5 | ||
6 | import java.util.function.BiPredicate; | 6 | import java.util.function.BiPredicate; |
diff --git a/subprojects/store/src/main/java/tools/refinery/store/query/view/FunctionalRelationView.java b/subprojects/store/src/main/java/tools/refinery/store/query/view/FunctionalRelationView.java index 54baa050..ef3954a4 100644 --- a/subprojects/store/src/main/java/tools/refinery/store/query/view/FunctionalRelationView.java +++ b/subprojects/store/src/main/java/tools/refinery/store/query/view/FunctionalRelationView.java | |||
@@ -1,8 +1,8 @@ | |||
1 | package tools.refinery.store.query.view; | 1 | package tools.refinery.store.query.view; |
2 | 2 | ||
3 | import tools.refinery.store.model.Model; | 3 | import tools.refinery.store.model.Model; |
4 | import tools.refinery.store.model.Tuple; | 4 | import tools.refinery.store.tuple.Tuple; |
5 | import tools.refinery.store.model.Tuple.Tuple1; | 5 | import tools.refinery.store.tuple.Tuple1; |
6 | import tools.refinery.store.model.representation.Relation; | 6 | import tools.refinery.store.model.representation.Relation; |
7 | 7 | ||
8 | public class FunctionalRelationView<D> extends RelationView<D> { | 8 | public class FunctionalRelationView<D> extends RelationView<D> { |
@@ -28,7 +28,7 @@ public class FunctionalRelationView<D> extends RelationView<D> { | |||
28 | public boolean get(Model model, Object[] tuple) { | 28 | public boolean get(Model model, Object[] tuple) { |
29 | int[] content = new int[tuple.length - 1]; | 29 | int[] content = new int[tuple.length - 1]; |
30 | for (int i = 0; i < tuple.length - 1; i++) { | 30 | for (int i = 0; i < tuple.length - 1; i++) { |
31 | content[i] = ((Tuple1) tuple[i]).get(0); | 31 | content[i] = ((Tuple1) tuple[i]).value0(); |
32 | } | 32 | } |
33 | Tuple key = Tuple.of(content); | 33 | Tuple key = Tuple.of(content); |
34 | @SuppressWarnings("unchecked") | 34 | @SuppressWarnings("unchecked") |
diff --git a/subprojects/store/src/main/java/tools/refinery/store/query/view/KeyOnlyRelationView.java b/subprojects/store/src/main/java/tools/refinery/store/query/view/KeyOnlyRelationView.java index b9a9ed9f..c88af5a4 100644 --- a/subprojects/store/src/main/java/tools/refinery/store/query/view/KeyOnlyRelationView.java +++ b/subprojects/store/src/main/java/tools/refinery/store/query/view/KeyOnlyRelationView.java | |||
@@ -1,6 +1,6 @@ | |||
1 | package tools.refinery.store.query.view; | 1 | package tools.refinery.store.query.view; |
2 | 2 | ||
3 | import tools.refinery.store.model.Tuple; | 3 | import tools.refinery.store.tuple.Tuple; |
4 | import tools.refinery.store.model.representation.Relation; | 4 | import tools.refinery.store.model.representation.Relation; |
5 | 5 | ||
6 | public class KeyOnlyRelationView extends AbstractFilteredRelationView<Boolean> { | 6 | public class KeyOnlyRelationView extends AbstractFilteredRelationView<Boolean> { |
diff --git a/subprojects/store/src/main/java/tools/refinery/store/query/view/RelationView.java b/subprojects/store/src/main/java/tools/refinery/store/query/view/RelationView.java index b8a54046..ceaf7d55 100644 --- a/subprojects/store/src/main/java/tools/refinery/store/query/view/RelationView.java +++ b/subprojects/store/src/main/java/tools/refinery/store/query/view/RelationView.java | |||
@@ -2,7 +2,7 @@ package tools.refinery.store.query.view; | |||
2 | 2 | ||
3 | import tools.refinery.store.map.CursorAsIterator; | 3 | import tools.refinery.store.map.CursorAsIterator; |
4 | import tools.refinery.store.model.Model; | 4 | import tools.refinery.store.model.Model; |
5 | import tools.refinery.store.model.Tuple; | 5 | import tools.refinery.store.tuple.Tuple; |
6 | import tools.refinery.store.model.representation.Relation; | 6 | import tools.refinery.store.model.representation.Relation; |
7 | 7 | ||
8 | import java.util.Objects; | 8 | import java.util.Objects; |
diff --git a/subprojects/store/src/main/java/tools/refinery/store/tuple/Tuple.java b/subprojects/store/src/main/java/tools/refinery/store/tuple/Tuple.java new file mode 100644 index 00000000..bf844c6d --- /dev/null +++ b/subprojects/store/src/main/java/tools/refinery/store/tuple/Tuple.java | |||
@@ -0,0 +1,29 @@ | |||
1 | package tools.refinery.store.tuple; | ||
2 | |||
3 | public sealed interface Tuple extends TupleLike permits Tuple0, Tuple1, Tuple2, TupleN { | ||
4 | @Override | ||
5 | default Tuple toTuple() { | ||
6 | return this; | ||
7 | } | ||
8 | |||
9 | static Tuple of() { | ||
10 | return Tuple0.INSTANCE; | ||
11 | } | ||
12 | |||
13 | static Tuple of(int value) { | ||
14 | return Tuple1.Cache.INSTANCE.getOrCreate(value); | ||
15 | } | ||
16 | |||
17 | static Tuple of(int value1, int value2) { | ||
18 | return new Tuple2(value1, value2); | ||
19 | } | ||
20 | |||
21 | static Tuple of(int... values) { | ||
22 | return switch (values.length) { | ||
23 | case 0 -> of(); | ||
24 | case 1 -> of(values[0]); | ||
25 | case 2 -> of(values[0], values[1]); | ||
26 | default -> new TupleN(values); | ||
27 | }; | ||
28 | } | ||
29 | } | ||
diff --git a/subprojects/store/src/main/java/tools/refinery/store/tuple/Tuple0.java b/subprojects/store/src/main/java/tools/refinery/store/tuple/Tuple0.java new file mode 100644 index 00000000..8eea5c3a --- /dev/null +++ b/subprojects/store/src/main/java/tools/refinery/store/tuple/Tuple0.java | |||
@@ -0,0 +1,25 @@ | |||
1 | package tools.refinery.store.tuple; | ||
2 | |||
3 | public record Tuple0() implements Tuple { | ||
4 | public static Tuple0 INSTANCE = new Tuple0(); | ||
5 | |||
6 | @Override | ||
7 | public int getSize() { | ||
8 | return 0; | ||
9 | } | ||
10 | |||
11 | @Override | ||
12 | public int get(int element) { | ||
13 | throw new IndexOutOfBoundsException(element); | ||
14 | } | ||
15 | |||
16 | @Override | ||
17 | public int[] toArray() { | ||
18 | return new int[]{}; | ||
19 | } | ||
20 | |||
21 | @Override | ||
22 | public String toString() { | ||
23 | return "[]"; | ||
24 | } | ||
25 | } | ||
diff --git a/subprojects/store/src/main/java/tools/refinery/store/tuple/Tuple1.java b/subprojects/store/src/main/java/tools/refinery/store/tuple/Tuple1.java new file mode 100644 index 00000000..95907ee1 --- /dev/null +++ b/subprojects/store/src/main/java/tools/refinery/store/tuple/Tuple1.java | |||
@@ -0,0 +1,54 @@ | |||
1 | package tools.refinery.store.tuple; | ||
2 | |||
3 | import java.util.ArrayList; | ||
4 | |||
5 | public record Tuple1(int value0) implements Tuple { | ||
6 | @Override | ||
7 | public int getSize() { | ||
8 | return 1; | ||
9 | } | ||
10 | |||
11 | @Override | ||
12 | public int get(int element) { | ||
13 | if (element == 0) { | ||
14 | return value0; | ||
15 | } | ||
16 | throw new IndexOutOfBoundsException(element); | ||
17 | } | ||
18 | |||
19 | @Override | ||
20 | public int[] toArray() { | ||
21 | return new int[]{value0}; | ||
22 | } | ||
23 | |||
24 | @Override | ||
25 | public String toString() { | ||
26 | return "[" + value0 + "]"; | ||
27 | } | ||
28 | |||
29 | public static class Cache { | ||
30 | public static final Cache INSTANCE = new Cache(); | ||
31 | |||
32 | private final ArrayList<Tuple1> tuple1Cache = new ArrayList<>(1024); | ||
33 | |||
34 | private Cache() { | ||
35 | } | ||
36 | |||
37 | public Tuple1 getOrCreate(int value) { | ||
38 | if (value < 0) { | ||
39 | // Mask tuple for QueryableModelStore, doesn't refer to a model node. | ||
40 | return new Tuple1(value); | ||
41 | } | ||
42 | if (value < tuple1Cache.size()) { | ||
43 | return tuple1Cache.get(value); | ||
44 | } | ||
45 | Tuple1 newlyCreated = null; | ||
46 | tuple1Cache.ensureCapacity(value); | ||
47 | while (value >= tuple1Cache.size()) { | ||
48 | newlyCreated = new Tuple1(tuple1Cache.size()); | ||
49 | tuple1Cache.add(newlyCreated); | ||
50 | } | ||
51 | return newlyCreated; | ||
52 | } | ||
53 | } | ||
54 | } | ||
diff --git a/subprojects/store/src/main/java/tools/refinery/store/tuple/Tuple2.java b/subprojects/store/src/main/java/tools/refinery/store/tuple/Tuple2.java new file mode 100644 index 00000000..0836a32d --- /dev/null +++ b/subprojects/store/src/main/java/tools/refinery/store/tuple/Tuple2.java | |||
@@ -0,0 +1,27 @@ | |||
1 | package tools.refinery.store.tuple; | ||
2 | |||
3 | public record Tuple2(int value0, int value1) implements Tuple { | ||
4 | @Override | ||
5 | public int getSize() { | ||
6 | return 2; | ||
7 | } | ||
8 | |||
9 | @Override | ||
10 | public int get(int element) { | ||
11 | return switch (element) { | ||
12 | case 0 -> value0; | ||
13 | case 1 -> value1; | ||
14 | default -> throw new ArrayIndexOutOfBoundsException(element); | ||
15 | }; | ||
16 | } | ||
17 | |||
18 | @Override | ||
19 | public int[] toArray() { | ||
20 | return new int[]{value0, value1}; | ||
21 | } | ||
22 | |||
23 | @Override | ||
24 | public String toString() { | ||
25 | return "[" + value0 + ", " + value1 + "]"; | ||
26 | } | ||
27 | } | ||
diff --git a/subprojects/store/src/main/java/tools/refinery/store/tuple/TupleLike.java b/subprojects/store/src/main/java/tools/refinery/store/tuple/TupleLike.java new file mode 100644 index 00000000..470ca298 --- /dev/null +++ b/subprojects/store/src/main/java/tools/refinery/store/tuple/TupleLike.java | |||
@@ -0,0 +1,25 @@ | |||
1 | package tools.refinery.store.tuple; | ||
2 | |||
3 | public interface TupleLike { | ||
4 | int getSize(); | ||
5 | |||
6 | int get(int element); | ||
7 | |||
8 | default int[] toArray() { | ||
9 | int size = getSize(); | ||
10 | var array = new int[size]; | ||
11 | for (int i = 0; i < size; i++) { | ||
12 | array[i] = get(i); | ||
13 | } | ||
14 | return array; | ||
15 | } | ||
16 | |||
17 | default Tuple toTuple() { | ||
18 | return switch (getSize()) { | ||
19 | case 0 -> Tuple.of(); | ||
20 | case 1 -> Tuple.of(get(0)); | ||
21 | case 2 -> Tuple.of(get(0), get(1)); | ||
22 | default -> Tuple.of(toArray()); | ||
23 | }; | ||
24 | } | ||
25 | } | ||
diff --git a/subprojects/store/src/main/java/tools/refinery/store/tuple/TupleN.java b/subprojects/store/src/main/java/tools/refinery/store/tuple/TupleN.java new file mode 100644 index 00000000..15fd063b --- /dev/null +++ b/subprojects/store/src/main/java/tools/refinery/store/tuple/TupleN.java | |||
@@ -0,0 +1,52 @@ | |||
1 | package tools.refinery.store.tuple; | ||
2 | |||
3 | import java.util.Arrays; | ||
4 | import java.util.stream.Collectors; | ||
5 | |||
6 | public record TupleN(int[] values) implements Tuple { | ||
7 | static final int CUSTOM_TUPLE_SIZE = 2; | ||
8 | |||
9 | public TupleN(int[] values) { | ||
10 | if (values.length < CUSTOM_TUPLE_SIZE) | ||
11 | throw new IllegalArgumentException(); | ||
12 | this.values = Arrays.copyOf(values, values.length); | ||
13 | } | ||
14 | |||
15 | @Override | ||
16 | public int getSize() { | ||
17 | return values.length; | ||
18 | } | ||
19 | |||
20 | @Override | ||
21 | public int get(int element) { | ||
22 | return values[element]; | ||
23 | } | ||
24 | |||
25 | @Override | ||
26 | public int[] toArray() { | ||
27 | return values; | ||
28 | } | ||
29 | |||
30 | @Override | ||
31 | public String toString() { | ||
32 | var valuesString = Arrays.stream(values).mapToObj(Integer::toString).collect(Collectors.joining(", ")); | ||
33 | return "[" + valuesString + "]"; | ||
34 | } | ||
35 | |||
36 | @Override | ||
37 | public int hashCode() { | ||
38 | return Arrays.hashCode(values); | ||
39 | } | ||
40 | |||
41 | @Override | ||
42 | public boolean equals(Object obj) { | ||
43 | if (this == obj) | ||
44 | return true; | ||
45 | if (obj == null) | ||
46 | return false; | ||
47 | if (getClass() != obj.getClass()) | ||
48 | return false; | ||
49 | TupleN other = (TupleN) obj; | ||
50 | return Arrays.equals(values, other.values); | ||
51 | } | ||
52 | } | ||
diff --git a/subprojects/store/src/test/java/tools/refinery/store/map/tests/MapUnitTests.java b/subprojects/store/src/test/java/tools/refinery/store/map/tests/MapUnitTests.java index f0d5d927..081112cc 100644 --- a/subprojects/store/src/test/java/tools/refinery/store/map/tests/MapUnitTests.java +++ b/subprojects/store/src/test/java/tools/refinery/store/map/tests/MapUnitTests.java | |||
@@ -6,7 +6,7 @@ import org.junit.jupiter.api.Test; | |||
6 | 6 | ||
7 | import tools.refinery.store.map.VersionedMapStore; | 7 | import tools.refinery.store.map.VersionedMapStore; |
8 | import tools.refinery.store.map.VersionedMapStoreImpl; | 8 | import tools.refinery.store.map.VersionedMapStoreImpl; |
9 | import tools.refinery.store.model.Tuple; | 9 | import tools.refinery.store.tuple.Tuple; |
10 | import tools.refinery.store.model.TupleHashProvider; | 10 | import tools.refinery.store.model.TupleHashProvider; |
11 | 11 | ||
12 | class MapUnitTests { | 12 | class MapUnitTests { |
diff --git a/subprojects/store/src/test/java/tools/refinery/store/model/hashTests/HashEfficiencyTest.java b/subprojects/store/src/test/java/tools/refinery/store/model/hashTests/HashEfficiencyTest.java index 7d070380..ceec40f5 100644 --- a/subprojects/store/src/test/java/tools/refinery/store/model/hashTests/HashEfficiencyTest.java +++ b/subprojects/store/src/test/java/tools/refinery/store/model/hashTests/HashEfficiencyTest.java | |||
@@ -10,7 +10,7 @@ import java.util.Random; | |||
10 | import org.junit.jupiter.api.Test; | 10 | import org.junit.jupiter.api.Test; |
11 | 11 | ||
12 | import tools.refinery.store.map.ContinousHashProvider; | 12 | import tools.refinery.store.map.ContinousHashProvider; |
13 | import tools.refinery.store.model.Tuple; | 13 | import tools.refinery.store.tuple.Tuple; |
14 | import tools.refinery.store.model.TupleHashProvider; | 14 | import tools.refinery.store.model.TupleHashProvider; |
15 | import tools.refinery.store.model.TupleHashProviderBitMagic; | 15 | import tools.refinery.store.model.TupleHashProviderBitMagic; |
16 | 16 | ||
@@ -39,7 +39,7 @@ class HashEfficiencyTest { | |||
39 | return result; | 39 | return result; |
40 | } else throw new IllegalArgumentException(); | 40 | } else throw new IllegalArgumentException(); |
41 | } | 41 | } |
42 | 42 | ||
43 | private static int amountToRange(int arity, int n) { | 43 | private static int amountToRange(int arity, int n) { |
44 | int range = 1; | 44 | int range = 1; |
45 | while(Math.pow(range,arity)<n+0.1) { | 45 | while(Math.pow(range,arity)<n+0.1) { |
@@ -47,7 +47,7 @@ class HashEfficiencyTest { | |||
47 | } | 47 | } |
48 | return 1024; | 48 | return 1024; |
49 | } | 49 | } |
50 | 50 | ||
51 | public static List<Tuple> nPermutations(int arity, int n) { | 51 | public static List<Tuple> nPermutations(int arity, int n) { |
52 | int range = amountToRange(arity, n); | 52 | int range = amountToRange(arity, n); |
53 | List<Tuple> permutations = permutations(range, arity); | 53 | List<Tuple> permutations = permutations(range, arity); |
@@ -67,7 +67,7 @@ class HashEfficiencyTest { | |||
67 | } | 67 | } |
68 | return permutations; | 68 | return permutations; |
69 | } | 69 | } |
70 | 70 | ||
71 | @Test | 71 | @Test |
72 | void permutationTest() { | 72 | void permutationTest() { |
73 | List<Tuple> p = permutations(10, 2); | 73 | List<Tuple> p = permutations(10, 2); |
@@ -92,7 +92,7 @@ class HashEfficiencyTest { | |||
92 | } | 92 | } |
93 | private static double calculateHashClashes(List<Tuple> tuples, ContinousHashProvider<Tuple> chp) { | 93 | private static double calculateHashClashes(List<Tuple> tuples, ContinousHashProvider<Tuple> chp) { |
94 | int sumClashes = 0; | 94 | int sumClashes = 0; |
95 | 95 | ||
96 | for(int i = 0; i<tuples.size(); i++) { | 96 | for(int i = 0; i<tuples.size(); i++) { |
97 | int height = 0; | 97 | int height = 0; |
98 | for(int j=0; j<tuples.size(); j++) { | 98 | for(int j=0; j<tuples.size(); j++) { |
@@ -131,22 +131,22 @@ class HashEfficiencyTest { | |||
131 | hashes.add(new TupleHashProvider()); | 131 | hashes.add(new TupleHashProvider()); |
132 | hashNames.add("BitMagic"); | 132 | hashNames.add("BitMagic"); |
133 | hashes.add(new TupleHashProviderBitMagic()); | 133 | hashes.add(new TupleHashProviderBitMagic()); |
134 | 134 | ||
135 | int[] arities = new int[] {2,3,4,5}; | 135 | int[] arities = new int[] {2,3,4,5}; |
136 | int[] sizes = new int[] {32*32,32*32*8}; | 136 | int[] sizes = new int[] {32*32,32*32*8}; |
137 | 137 | ||
138 | System.out.println("Size,Arity,DataSource,Hash,Chashes,Optimal,Badness"); | 138 | System.out.println("Size,Arity,DataSource,Hash,Chashes,Optimal,Badness"); |
139 | for(int size : sizes) { | 139 | for(int size : sizes) { |
140 | double optimalClashes = caclulateOptimalHashClash(size); | 140 | double optimalClashes = caclulateOptimalHashClash(size); |
141 | for(int arity : arities) { | 141 | for(int arity : arities) { |
142 | List<String> dataSourceNames = new LinkedList<>(); | 142 | List<String> dataSourceNames = new LinkedList<>(); |
143 | List<List<Tuple>> dataSources = new LinkedList<>(); | 143 | List<List<Tuple>> dataSources = new LinkedList<>(); |
144 | 144 | ||
145 | // dataSourceNames.add("Permutation"); | 145 | // dataSourceNames.add("Permutation"); |
146 | // dataSources.add(nPermutations(arity, size)); | 146 | // dataSources.add(nPermutations(arity, size)); |
147 | dataSourceNames.add("Random"); | 147 | dataSourceNames.add("Random"); |
148 | dataSources.add(nRandoms(arity, size, 0)); | 148 | dataSources.add(nRandoms(arity, size, 0)); |
149 | 149 | ||
150 | for(int dataSourceIndex = 0; dataSourceIndex<dataSourceNames.size(); dataSourceIndex++) { | 150 | for(int dataSourceIndex = 0; dataSourceIndex<dataSourceNames.size(); dataSourceIndex++) { |
151 | for(int hashIndex = 0; hashIndex<hashNames.size(); hashIndex++) { | 151 | for(int hashIndex = 0; hashIndex<hashNames.size(); hashIndex++) { |
152 | double clashes = calculateHashClashes(dataSources.get(dataSourceIndex),hashes.get(hashIndex)); | 152 | double clashes = calculateHashClashes(dataSources.get(dataSourceIndex),hashes.get(hashIndex)); |
diff --git a/subprojects/store/src/test/java/tools/refinery/store/model/tests/ModelTest.java b/subprojects/store/src/test/java/tools/refinery/store/model/tests/ModelTest.java index 9d90b1e1..61dd7c74 100644 --- a/subprojects/store/src/test/java/tools/refinery/store/model/tests/ModelTest.java +++ b/subprojects/store/src/test/java/tools/refinery/store/model/tests/ModelTest.java | |||
@@ -12,7 +12,7 @@ import org.junit.jupiter.api.Test; | |||
12 | import tools.refinery.store.model.Model; | 12 | import tools.refinery.store.model.Model; |
13 | import tools.refinery.store.model.ModelStore; | 13 | import tools.refinery.store.model.ModelStore; |
14 | import tools.refinery.store.model.ModelStoreImpl; | 14 | import tools.refinery.store.model.ModelStoreImpl; |
15 | import tools.refinery.store.model.Tuple; | 15 | import tools.refinery.store.tuple.Tuple; |
16 | import tools.refinery.store.model.representation.Relation; | 16 | import tools.refinery.store.model.representation.Relation; |
17 | 17 | ||
18 | class ModelTest { | 18 | class ModelTest { |