diff options
Diffstat (limited to 'subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/memories/NullaryMaskedTupleMemory.java')
-rw-r--r-- | subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/memories/NullaryMaskedTupleMemory.java | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/memories/NullaryMaskedTupleMemory.java b/subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/memories/NullaryMaskedTupleMemory.java new file mode 100644 index 00000000..7fa9e053 --- /dev/null +++ b/subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/memories/NullaryMaskedTupleMemory.java | |||
@@ -0,0 +1,85 @@ | |||
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 | *******************************************************************************/ | ||
9 | package tools.refinery.viatra.runtime.matchers.memories; | ||
10 | |||
11 | import java.util.Collection; | ||
12 | import java.util.Collections; | ||
13 | import java.util.Set; | ||
14 | |||
15 | import tools.refinery.viatra.runtime.matchers.tuple.ITuple; | ||
16 | import tools.refinery.viatra.runtime.matchers.tuple.Tuple; | ||
17 | import tools.refinery.viatra.runtime.matchers.tuple.TupleMask; | ||
18 | import tools.refinery.viatra.runtime.matchers.tuple.Tuples; | ||
19 | import tools.refinery.viatra.runtime.matchers.util.CollectionsFactory.MemoryType; | ||
20 | |||
21 | /** | ||
22 | * Specialized for nullary mask; tuples are stored as a simple set/multiset memory. | ||
23 | * | ||
24 | * @author Gabor Bergmann | ||
25 | * @since 2.0 | ||
26 | */ | ||
27 | public final class NullaryMaskedTupleMemory<Timestamp extends Comparable<Timestamp>> extends AbstractTrivialMaskedMemory<Timestamp> { | ||
28 | |||
29 | protected static final Set<Tuple> UNIT_RELATION = | ||
30 | Collections.singleton(Tuples.staticArityFlatTupleOf()); | ||
31 | protected static final Set<Tuple> EMPTY_RELATION = | ||
32 | Collections.emptySet(); | ||
33 | /** | ||
34 | * @param mask | ||
35 | * The mask used to index the matchings | ||
36 | * @param owner the object "owning" this memory | ||
37 | * @param bucketType the kind of tuple collection maintained for each indexer bucket | ||
38 | * @since 2.0 | ||
39 | */ | ||
40 | public NullaryMaskedTupleMemory(TupleMask mask, MemoryType bucketType, Object owner) { | ||
41 | super(mask, bucketType, owner); | ||
42 | if (0 != mask.getSize()) throw new IllegalArgumentException(mask.toString()); | ||
43 | } | ||
44 | |||
45 | @Override | ||
46 | public int getKeysetSize() { | ||
47 | return tuples.isEmpty() ? 0 : 1; | ||
48 | } | ||
49 | |||
50 | @Override | ||
51 | public Iterable<Tuple> getSignatures() { | ||
52 | return tuples.isEmpty() ? EMPTY_RELATION : UNIT_RELATION; | ||
53 | } | ||
54 | |||
55 | @Override | ||
56 | public Collection<Tuple> get(ITuple signature) { | ||
57 | if (0 == signature.getSize()) | ||
58 | return tuples.distinctValues(); | ||
59 | else return null; | ||
60 | } | ||
61 | |||
62 | @Override | ||
63 | public boolean remove(Tuple tuple, Tuple signature) { | ||
64 | tuples.removeOne(tuple); | ||
65 | return tuples.isEmpty(); | ||
66 | } | ||
67 | |||
68 | @Override | ||
69 | public boolean remove(Tuple tuple) { | ||
70 | return remove(tuple, null); | ||
71 | } | ||
72 | |||
73 | @Override | ||
74 | public boolean add(Tuple tuple, Tuple signature) { | ||
75 | boolean wasEmpty = tuples.isEmpty(); | ||
76 | tuples.addOne(tuple); | ||
77 | return wasEmpty; | ||
78 | } | ||
79 | |||
80 | @Override | ||
81 | public boolean add(Tuple tuple) { | ||
82 | return add(tuple, null); | ||
83 | } | ||
84 | |||
85 | } | ||