aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/viatra-runtime-matchers/src/main/java/tools/refinery/viatra/runtime/matchers/scopes/tables/IIndexTable.java
diff options
context:
space:
mode:
Diffstat (limited to 'subprojects/viatra-runtime-matchers/src/main/java/tools/refinery/viatra/runtime/matchers/scopes/tables/IIndexTable.java')
-rw-r--r--subprojects/viatra-runtime-matchers/src/main/java/tools/refinery/viatra/runtime/matchers/scopes/tables/IIndexTable.java212
1 files changed, 212 insertions, 0 deletions
diff --git a/subprojects/viatra-runtime-matchers/src/main/java/tools/refinery/viatra/runtime/matchers/scopes/tables/IIndexTable.java b/subprojects/viatra-runtime-matchers/src/main/java/tools/refinery/viatra/runtime/matchers/scopes/tables/IIndexTable.java
new file mode 100644
index 00000000..be375393
--- /dev/null
+++ b/subprojects/viatra-runtime-matchers/src/main/java/tools/refinery/viatra/runtime/matchers/scopes/tables/IIndexTable.java
@@ -0,0 +1,212 @@
1/*******************************************************************************
2 * Copyright (c) 2010-2018, Gabor Bergmann, IncQuery Labs 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 *******************************************************************************/
9package tools.refinery.viatra.runtime.matchers.scopes.tables;
10
11import java.util.Iterator;
12import java.util.Optional;
13import java.util.stream.Stream;
14
15import tools.refinery.viatra.runtime.matchers.context.IInputKey;
16import tools.refinery.viatra.runtime.matchers.context.IQueryMetaContext;
17import tools.refinery.viatra.runtime.matchers.context.IQueryRuntimeContext;
18import tools.refinery.viatra.runtime.matchers.context.IQueryRuntimeContextListener;
19import tools.refinery.viatra.runtime.matchers.tuple.ITuple;
20import tools.refinery.viatra.runtime.matchers.tuple.Tuple;
21import tools.refinery.viatra.runtime.matchers.tuple.TupleMask;
22import tools.refinery.viatra.runtime.matchers.util.Accuracy;
23
24/**
25 * Read-only interface that provides the {@link IInputKey}-specific slice of an instance store to realize a
26 * {@link IQueryRuntimeContext}. Implemented by a customizable data store that is responsible for:
27 * <ul>
28 * <li>storing the instance tuples of the {@link IInputKey},</li>
29 * <li>providing efficient lookup via storage-specific indexing,</li>
30 * <li>delivering notifications. (TODO not designed yet)</li>
31 * </ul>
32 *
33 * <p>
34 * Can be specialized for unary / binary / etc., opposite edges or node subtypes, specific types, distributed storage,
35 * etc.
36 * <p>
37 * Writeable API is specific to the customized implementations (e.g. unary).
38 *
39 * <p>
40 * <b>Precondition:</b> the associated input key is enumerable, see {@link IQueryMetaContext#isEnumerable(IInputKey)}.
41 * <p>
42 * <strong>EXPERIMENTAL</strong>. This class or interface has been added as
43 * part of a work in progress. There is no guarantee that this API will
44 * work or that it will remain the same.
45 *
46 * @since 2.0
47 * @author Gabor Bergmann
48 * @noimplement This interface is not intended to be implemented directly. Extend {@link AbstractIndexTable} instead.
49 */
50public interface IIndexTable {
51
52 // TODO add superinterface that represents a statistics-only counter?
53
54 /**
55 * @return the input key indexed by this table
56 */
57 public IInputKey getInputKey();
58
59 /**
60 * Returns the tuples, optionally seeded with the given tuple.
61 *
62 * <p> Consider using the more idiomatic {@link #streamTuples(TupleMask, ITuple)} instead.
63 *
64 * @param seedMask
65 * a mask that extracts those parameters of the input key (from the entire parameter list) that should be
66 * bound to a fixed value; must not be null. <strong>Note</strong>: any given index must occur at most
67 * once in seedMask.
68 * @param seed
69 * the tuple of fixed values restricting the row set to be considered, in the same order as given in
70 * parameterSeedMask, so that for each considered row tuple,
71 * projectedParameterSeed.equals(parameterSeedMask.transform(row)) should hold. Must not be null.
72 * @return the tuples in the table for the given key and seed
73 */
74 @SuppressWarnings("unchecked")
75 public default Iterable<Tuple> enumerateTuples(TupleMask seedMask, ITuple seed) {
76 return () -> (Iterator<Tuple>) (streamTuples(seedMask, seed).iterator());
77 }
78
79 /**
80 * Returns the tuples, optionally seeded with the given tuple.
81 *
82 * @param seedMask
83 * a mask that extracts those parameters of the input key (from the entire parameter list) that should be
84 * bound to a fixed value; must not be null. <strong>Note</strong>: any given index must occur at most
85 * once in seedMask.
86 * @param seed
87 * the tuple of fixed values restricting the row set to be considered, in the same order as given in
88 * parameterSeedMask, so that for each considered row tuple,
89 * projectedParameterSeed.equals(parameterSeedMask.transform(row)) should hold. Must not be null.
90 * @return the tuples in the table for the given key and seed
91 * @since 2.1
92 */
93 public Stream<? extends Tuple> streamTuples(TupleMask seedMask, ITuple seed);
94
95 /**
96 * Simpler form of {@link #enumerateTuples(TupleMask, ITuple)} in the case where all values of the tuples are bound
97 * by the seed except for one.
98 *
99 * <p>
100 * Selects the tuples in the table, optionally seeded with the given tuple, and then returns the single value from
101 * each tuple which is not bound by the seed mask.
102 *
103 * <p> Consider using the more idiomatic {@link #streamValues(TupleMask, ITuple)} instead.
104 *
105 * @param seedMask
106 * a mask that extracts those parameters of the input key (from the entire parameter list) that should be
107 * bound to a fixed value; must not be null. <strong>Note</strong>: any given index must occur at most
108 * once in seedMask, and seedMask must include all parameters in any arbitrary order except one.
109 * @param seed
110 * the tuple of fixed values restricting the row set to be considered, in the same order as given in
111 * parameterSeedMask, so that for each considered row tuple,
112 * projectedParameterSeed.equals(parameterSeedMask.transform(row)) should hold. Must not be null.
113 * @return the objects in the table for the given key and seed
114 *
115 */
116 @SuppressWarnings("unchecked")
117 public default Iterable<? extends Object> enumerateValues(TupleMask seedMask, ITuple seed) {
118 return () -> (Iterator<Object>) (streamValues(seedMask, seed).iterator());
119 }
120
121 /**
122 * Simpler form of {@link #enumerateTuples(TupleMask, ITuple)} in the case where all values of the tuples are bound
123 * by the seed except for one.
124 *
125 * <p>
126 * Selects the tuples in the table, optionally seeded with the given tuple, and then returns the single value from
127 * each tuple which is not bound by the seed mask.
128 *
129 * @param seedMask
130 * a mask that extracts those parameters of the input key (from the entire parameter list) that should be
131 * bound to a fixed value; must not be null. <strong>Note</strong>: any given index must occur at most
132 * once in seedMask, and seedMask must include all parameters in any arbitrary order except one.
133 * @param seed
134 * the tuple of fixed values restricting the row set to be considered, in the same order as given in
135 * parameterSeedMask, so that for each considered row tuple,
136 * projectedParameterSeed.equals(parameterSeedMask.transform(row)) should hold. Must not be null.
137 * @return the objects in the table for the given key and seed
138 *
139 * @since 2.1
140 */
141 public Stream<? extends Object> streamValues(TupleMask seedMask, ITuple seed);
142
143 /**
144 * Simpler form of {@link #enumerateTuples(TupleMask, ITuple)} in the case where all values of the tuples are bound
145 * by the seed.
146 *
147 * <p>
148 * Returns whether the given tuple is in the table identified by the input key.
149 *
150 * @param seed
151 * a row tuple of fixed values whose presence in the table is queried
152 * @return true iff there is a row tuple contained in the table that corresponds to the given seed
153 */
154 public boolean containsTuple(ITuple seed);
155
156 /**
157 * Returns the number of tuples, optionally seeded with the given tuple.
158 *
159 * <p>
160 * Selects the tuples in the table, optionally seeded with the given tuple, and then returns their number.
161 *
162 * @param seedMask
163 * a mask that extracts those parameters of the input key (from the entire parameter list) that should be
164 * bound to a fixed value; must not be null. <strong>Note</strong>: any given index must occur at most
165 * once in seedMask.
166 * @param seed
167 * the tuple of fixed values restricting the row set to be considered, in the same order as given in
168 * parameterSeedMask, so that for each considered row tuple,
169 * projectedParameterSeed.equals(parameterSeedMask.transform(row)) should hold. Must not be null.
170 * @return the number of tuples in the table for the given key and seed
171 *
172 */
173 public int countTuples(TupleMask seedMask, ITuple seed);
174
175 /**
176 * Gives an estimate of the number of different groups the tuples of the table are projected into by the given mask
177 * (e.g. for an identity mask, this means the full relation size). The estimate must meet the required accuracy.
178 *
179 * <p> Derived tables may return {@link Optional#empty()} if it would be costly to provide an answer up to the required precision.
180 * Direct storage tables are expected to always be able to give an exact count.
181 *
182 * <p> PRE: {@link TupleMask#isNonrepeating()} must hold for the group mask.
183 *
184 * @since 2.1
185 */
186 public Optional<Long> estimateProjectionSize(TupleMask groupMask, Accuracy requiredAccuracy);
187
188 /**
189 * Subscribes for updates in the table, optionally seeded with the given tuple.
190 * <p> This should be called after initializing a result cache by an enumeration method.
191 *
192 * @param seed can be null or a tuple with matching arity;
193 * if non-null, notifications will delivered only about those updates of the table
194 * that match the seed at positions where the seed is non-null.
195 * @param listener will be notified of future changes
196 *
197 * @since 2.1
198 */
199 public void addUpdateListener(Tuple seed, IQueryRuntimeContextListener listener);
200
201 /**
202 * Unsubscribes from updates in the table, optionally seeded with the given tuple.
203 *
204 * @param seed can be null or a tuple with matching arity;
205 * see {@link #addUpdateListener(Tuple, IQueryRuntimeContextListener)} for definition.
206 * @param listener will no longer be notified of future changes
207 *
208 * @since 2.1
209 */
210 public void removeUpdateListener(Tuple seed, IQueryRuntimeContextListener listener);
211
212}