diff options
Diffstat (limited to 'store/src/main/java/org/eclipse/viatra/solver/data/model')
14 files changed, 0 insertions, 734 deletions
diff --git a/store/src/main/java/org/eclipse/viatra/solver/data/model/Model.java b/store/src/main/java/org/eclipse/viatra/solver/data/model/Model.java deleted file mode 100644 index 2b21e3e7..00000000 --- a/store/src/main/java/org/eclipse/viatra/solver/data/model/Model.java +++ /dev/null | |||
@@ -1,20 +0,0 @@ | |||
1 | package org.eclipse.viatra.solver.data.model; | ||
2 | |||
3 | import java.util.Set; | ||
4 | |||
5 | import org.eclipse.viatra.solver.data.map.Cursor; | ||
6 | import org.eclipse.viatra.solver.data.map.Versioned; | ||
7 | import org.eclipse.viatra.solver.data.model.representation.DataRepresentation; | ||
8 | |||
9 | public interface Model extends Versioned{ | ||
10 | @SuppressWarnings("squid:S1452") | ||
11 | Set<DataRepresentation<?, ?>> getDataRepresentations(); | ||
12 | |||
13 | <K,V> V get(DataRepresentation<K,V> representation, K key); | ||
14 | <K,V> Cursor<K,V> getAll(DataRepresentation<K,V> representation); | ||
15 | <K,V> V put(DataRepresentation<K,V> representation, K key, V value); | ||
16 | <K,V> void putAll(DataRepresentation<K,V> representation, Cursor<K,V> cursor); | ||
17 | <K,V> long getSize(DataRepresentation<K,V> representation); | ||
18 | |||
19 | ModelDiffCursor getDiffCursor(long to); | ||
20 | } | ||
diff --git a/store/src/main/java/org/eclipse/viatra/solver/data/model/ModelCursor.java b/store/src/main/java/org/eclipse/viatra/solver/data/model/ModelCursor.java deleted file mode 100644 index 3157c9f0..00000000 --- a/store/src/main/java/org/eclipse/viatra/solver/data/model/ModelCursor.java +++ /dev/null | |||
@@ -1,25 +0,0 @@ | |||
1 | package org.eclipse.viatra.solver.data.model; | ||
2 | |||
3 | import java.util.Map; | ||
4 | |||
5 | import org.eclipse.viatra.solver.data.map.Cursor; | ||
6 | import org.eclipse.viatra.solver.data.model.representation.DataRepresentation; | ||
7 | |||
8 | public class ModelCursor { | ||
9 | final Map<DataRepresentation<?, ?>,Cursor<?,?>> cursors; | ||
10 | |||
11 | public ModelCursor(Map<DataRepresentation<?, ?>, Cursor<?, ?>> cursors) { | ||
12 | super(); | ||
13 | this.cursors = cursors; | ||
14 | } | ||
15 | |||
16 | @SuppressWarnings("unchecked") | ||
17 | public <K,V> Cursor<K,V> getCursor(DataRepresentation<K, V> representation) { | ||
18 | Cursor<?, ?> cursor = cursors.get(representation); | ||
19 | if(cursor != null) { | ||
20 | return (Cursor<K, V>) cursor; | ||
21 | } else { | ||
22 | throw new IllegalArgumentException("ModelCursor does not contain cursor for representation "+representation); | ||
23 | } | ||
24 | } | ||
25 | } | ||
diff --git a/store/src/main/java/org/eclipse/viatra/solver/data/model/ModelDiffCursor.java b/store/src/main/java/org/eclipse/viatra/solver/data/model/ModelDiffCursor.java deleted file mode 100644 index d3551e47..00000000 --- a/store/src/main/java/org/eclipse/viatra/solver/data/model/ModelDiffCursor.java +++ /dev/null | |||
@@ -1,26 +0,0 @@ | |||
1 | package org.eclipse.viatra.solver.data.model; | ||
2 | |||
3 | import java.util.Map; | ||
4 | |||
5 | import org.eclipse.viatra.solver.data.map.Cursor; | ||
6 | import org.eclipse.viatra.solver.data.map.DiffCursor; | ||
7 | import org.eclipse.viatra.solver.data.model.representation.DataRepresentation; | ||
8 | |||
9 | public class ModelDiffCursor { | ||
10 | final Map<DataRepresentation<?, ?>,DiffCursor<?,?>> diffcursors; | ||
11 | |||
12 | public ModelDiffCursor(Map<DataRepresentation<?, ?>, DiffCursor<?, ?>> diffcursors) { | ||
13 | super(); | ||
14 | this.diffcursors = diffcursors; | ||
15 | } | ||
16 | |||
17 | @SuppressWarnings("unchecked") | ||
18 | public <K,V> DiffCursor<K,V> getCursor(DataRepresentation<K, V> representation) { | ||
19 | Cursor<?, ?> cursor = diffcursors.get(representation); | ||
20 | if(cursor != null) { | ||
21 | return (DiffCursor<K, V>) cursor; | ||
22 | } else { | ||
23 | throw new IllegalArgumentException("ModelCursor does not contain cursor for representation "+representation); | ||
24 | } | ||
25 | } | ||
26 | } | ||
diff --git a/store/src/main/java/org/eclipse/viatra/solver/data/model/ModelStore.java b/store/src/main/java/org/eclipse/viatra/solver/data/model/ModelStore.java deleted file mode 100644 index 35ac72b5..00000000 --- a/store/src/main/java/org/eclipse/viatra/solver/data/model/ModelStore.java +++ /dev/null | |||
@@ -1,16 +0,0 @@ | |||
1 | package org.eclipse.viatra.solver.data.model; | ||
2 | |||
3 | import java.util.Set; | ||
4 | |||
5 | import org.eclipse.viatra.solver.data.model.representation.DataRepresentation; | ||
6 | |||
7 | public interface ModelStore { | ||
8 | @SuppressWarnings("squid:S1452") | ||
9 | Set<DataRepresentation<?, ?>> getDataRepresentations(); | ||
10 | |||
11 | Model createModel(); | ||
12 | Model createModel(long state); | ||
13 | |||
14 | Set<Long> getStates(); | ||
15 | ModelDiffCursor getDiffCursor(long from, long to); | ||
16 | } \ No newline at end of file | ||
diff --git a/store/src/main/java/org/eclipse/viatra/solver/data/model/ModelStoreImpl.java b/store/src/main/java/org/eclipse/viatra/solver/data/model/ModelStoreImpl.java deleted file mode 100644 index a97fb27a..00000000 --- a/store/src/main/java/org/eclipse/viatra/solver/data/model/ModelStoreImpl.java +++ /dev/null | |||
@@ -1,121 +0,0 @@ | |||
1 | package org.eclipse.viatra.solver.data.model; | ||
2 | |||
3 | import java.util.HashMap; | ||
4 | import java.util.LinkedList; | ||
5 | import java.util.List; | ||
6 | import java.util.Map; | ||
7 | import java.util.Map.Entry; | ||
8 | import java.util.Set; | ||
9 | |||
10 | import org.eclipse.viatra.solver.data.map.ContinousHashProvider; | ||
11 | import org.eclipse.viatra.solver.data.map.DiffCursor; | ||
12 | import org.eclipse.viatra.solver.data.map.VersionedMap; | ||
13 | import org.eclipse.viatra.solver.data.map.VersionedMapStore; | ||
14 | import org.eclipse.viatra.solver.data.map.VersionedMapStoreImpl; | ||
15 | import org.eclipse.viatra.solver.data.model.internal.ModelImpl; | ||
16 | import org.eclipse.viatra.solver.data.model.internal.SimilarRelationEquivalenceClass; | ||
17 | import org.eclipse.viatra.solver.data.model.representation.AuxilaryData; | ||
18 | import org.eclipse.viatra.solver.data.model.representation.DataRepresentation; | ||
19 | import org.eclipse.viatra.solver.data.model.representation.Relation; | ||
20 | |||
21 | public class ModelStoreImpl implements ModelStore { | ||
22 | |||
23 | private final Map<DataRepresentation<?, ?>, VersionedMapStore<?, ?>> stores; | ||
24 | |||
25 | public ModelStoreImpl(Set<DataRepresentation<?, ?>> dataRepresentations) { | ||
26 | stores = initStores(dataRepresentations); | ||
27 | } | ||
28 | |||
29 | private Map<DataRepresentation<?, ?>, VersionedMapStore<?, ?>> initStores( | ||
30 | Set<DataRepresentation<?, ?>> dataRepresentations) { | ||
31 | Map<DataRepresentation<?, ?>, VersionedMapStore<?, ?>> result = new HashMap<>(); | ||
32 | |||
33 | Map<SimilarRelationEquivalenceClass, List<Relation<?>>> symbolRepresentationsPerHashPerArity = new HashMap<>(); | ||
34 | |||
35 | for (DataRepresentation<?, ?> dataRepresentation : dataRepresentations) { | ||
36 | if (dataRepresentation instanceof Relation<?> symbolRepresentation) { | ||
37 | addOrCreate(symbolRepresentationsPerHashPerArity, | ||
38 | new SimilarRelationEquivalenceClass(symbolRepresentation), symbolRepresentation); | ||
39 | } else if (dataRepresentation instanceof AuxilaryData<?, ?>) { | ||
40 | VersionedMapStoreImpl<?, ?> store = new VersionedMapStoreImpl<>(dataRepresentation.getHashProvider(), | ||
41 | dataRepresentation.getDefaultValue()); | ||
42 | result.put(dataRepresentation, store); | ||
43 | } else { | ||
44 | throw new UnsupportedOperationException( | ||
45 | "Model store does not have strategy to use " + dataRepresentation.getClass() + "!"); | ||
46 | } | ||
47 | } | ||
48 | for (List<Relation<?>> symbolGroup : symbolRepresentationsPerHashPerArity.values()) { | ||
49 | initRepresentationGroup(result, symbolGroup); | ||
50 | } | ||
51 | |||
52 | return result; | ||
53 | } | ||
54 | |||
55 | private void initRepresentationGroup(Map<DataRepresentation<?, ?>, VersionedMapStore<?, ?>> result, | ||
56 | List<Relation<?>> symbolGroup) { | ||
57 | final ContinousHashProvider<Tuple> hashProvider = symbolGroup.get(0).getHashProvider(); | ||
58 | final Object defaultValue = symbolGroup.get(0).getDefaultValue(); | ||
59 | |||
60 | List<VersionedMapStore<Tuple, Object>> maps = VersionedMapStoreImpl | ||
61 | .createSharedVersionedMapStores(symbolGroup.size(), hashProvider, defaultValue); | ||
62 | |||
63 | for (int i = 0; i < symbolGroup.size(); i++) { | ||
64 | result.put(symbolGroup.get(i), maps.get(i)); | ||
65 | } | ||
66 | } | ||
67 | |||
68 | private static <K, V> void addOrCreate(Map<K, List<V>> map, K key, V value) { | ||
69 | List<V> list; | ||
70 | if (map.containsKey(key)) { | ||
71 | list = map.get(key); | ||
72 | } else { | ||
73 | list = new LinkedList<>(); | ||
74 | map.put(key, list); | ||
75 | } | ||
76 | list.add(value); | ||
77 | } | ||
78 | |||
79 | @Override | ||
80 | public Set<DataRepresentation<?, ?>> getDataRepresentations() { | ||
81 | return this.stores.keySet(); | ||
82 | } | ||
83 | |||
84 | @Override | ||
85 | public ModelImpl createModel() { | ||
86 | Map<DataRepresentation<?, ?>, VersionedMap<?, ?>> maps = new HashMap<>(); | ||
87 | for (Entry<DataRepresentation<?, ?>, VersionedMapStore<?, ?>> entry : this.stores.entrySet()) { | ||
88 | maps.put(entry.getKey(), entry.getValue().createMap()); | ||
89 | } | ||
90 | return new ModelImpl(this, maps); | ||
91 | } | ||
92 | |||
93 | @Override | ||
94 | public synchronized ModelImpl createModel(long state) { | ||
95 | Map<DataRepresentation<?, ?>, VersionedMap<?, ?>> maps = new HashMap<>(); | ||
96 | for (Entry<DataRepresentation<?, ?>, VersionedMapStore<?, ?>> entry : this.stores.entrySet()) { | ||
97 | maps.put(entry.getKey(), entry.getValue().createMap(state)); | ||
98 | } | ||
99 | return new ModelImpl(this, maps); | ||
100 | } | ||
101 | |||
102 | @Override | ||
103 | public synchronized Set<Long> getStates() { | ||
104 | var iterator = stores.values().iterator(); | ||
105 | if (iterator.hasNext()) { | ||
106 | return Set.copyOf(iterator.next().getStates()); | ||
107 | } | ||
108 | return Set.of(0l); | ||
109 | } | ||
110 | |||
111 | @Override | ||
112 | public synchronized ModelDiffCursor getDiffCursor(long from, long to) { | ||
113 | Map<DataRepresentation<?, ?>, DiffCursor<?, ?>> diffcursors = new HashMap<>(); | ||
114 | for (Entry<DataRepresentation<?, ?>, VersionedMapStore<?, ?>> entry : stores.entrySet()) { | ||
115 | DataRepresentation<?, ?> representation = entry.getKey(); | ||
116 | DiffCursor<?, ?> diffCursor = entry.getValue().getDiffCursor(from, to); | ||
117 | diffcursors.put(representation, diffCursor); | ||
118 | } | ||
119 | return new ModelDiffCursor(diffcursors); | ||
120 | } | ||
121 | } | ||
diff --git a/store/src/main/java/org/eclipse/viatra/solver/data/model/Tuple.java b/store/src/main/java/org/eclipse/viatra/solver/data/model/Tuple.java deleted file mode 100644 index ca6548a4..00000000 --- a/store/src/main/java/org/eclipse/viatra/solver/data/model/Tuple.java +++ /dev/null | |||
@@ -1,148 +0,0 @@ | |||
1 | package org.eclipse.viatra.solver.data.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/store/src/main/java/org/eclipse/viatra/solver/data/model/TupleHashProvider.java b/store/src/main/java/org/eclipse/viatra/solver/data/model/TupleHashProvider.java deleted file mode 100644 index 6c37aa37..00000000 --- a/store/src/main/java/org/eclipse/viatra/solver/data/model/TupleHashProvider.java +++ /dev/null | |||
@@ -1,65 +0,0 @@ | |||
1 | package org.eclipse.viatra.solver.data.model; | ||
2 | |||
3 | import org.eclipse.viatra.solver.data.map.ContinousHashProvider; | ||
4 | |||
5 | public class TupleHashProvider implements ContinousHashProvider<Tuple> { | ||
6 | protected static TupleHashProvider instance; | ||
7 | |||
8 | public static TupleHashProvider singleton() { | ||
9 | if (instance == null) { | ||
10 | instance = new TupleHashProvider(); | ||
11 | } | ||
12 | return instance; | ||
13 | } | ||
14 | |||
15 | protected static final int[] primes = new int[] { 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, | ||
16 | 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, | ||
17 | 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, | ||
18 | 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, | ||
19 | 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, | ||
20 | 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, | ||
21 | 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, | ||
22 | 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997, 1009, 1013, 1019, 1021, | ||
23 | 1031, 1033, 1039, 1049, 1051, 1061, 1063, 1069, 1087, 1091, 1093, 1097, 1103, 1109, 1117, 1123, 1129, 1151, | ||
24 | 1153, 1163, 1171, 1181, 1187, 1193, 1201, 1213, 1217, 1223, 1229, 1231, 1237, 1249, 1259, 1277, 1279, 1283, | ||
25 | 1289, 1291, 1297, 1301, 1303, 1307, 1319, 1321, 1327, 1361, 1367, 1373, 1381, 1399, 1409, 1423, 1427, 1429, | ||
26 | 1433, 1439, 1447, 1451, 1453, 1459, 1471, 1481, 1483, 1487, 1489, 1493, 1499, 1511, 1523, 1531, 1543, 1549, | ||
27 | 1553, 1559, 1567, 1571, 1579, 1583, 1597, 1601, 1607, 1609, 1613, 1619, 1621, 1627, 1637, 1657, 1663, 1667, | ||
28 | 1669, 1693, 1697, 1699, 1709, 1721, 1723, 1733, 1741, 1747, 1753, 1759, 1777, 1783, 1787, 1789, 1801, 1811, | ||
29 | 1823, 1831, 1847, 1861, 1867, 1871, 1873, 1877, 1879, 1889, 1901, 1907, 1913, 1931, 1933, 1949, 1951, 1973, | ||
30 | 1979, 1987, 1993, 1997, 1999, 2003, 2011, 2017, 2027, 2029, 2039, 2053, 2063, 2069, 2081, 2083, 2087, 2089, | ||
31 | 2099, 2111, 2113, 2129, 2131, 2137, 2141, 2143, 2153, 2161, 2179, 2203, 2207, 2213, 2221, 2237, 2239, 2243, | ||
32 | 2251, 2267, 2269, 2273, 2281, 2287, 2293, 2297, 2309, 2311, 2333, 2339, 2341, 2347, 2351, 2357, 2371, 2377, | ||
33 | 2381, 2383, 2389, 2393, 2399, 2411, 2417, 2423, 2437, 2441, 2447, 2459, 2467, 2473, 2477, 2503, 2521, 2531, | ||
34 | 2539, 2543, 2549, 2551, 2557, 2579, 2591, 2593, 2609, 2617, 2621, 2633, 2647, 2657, 2659, 2663, 2671, 2677, | ||
35 | 2683, 2687, 2689, 2693, 2699, 2707, 2711, 2713, 2719, 2729, 2731, 2741, 2749, 2753, 2767, 2777, 2789, 2791, | ||
36 | 2797, 2801, 2803, 2819, 3089, 3109, 3119, 3121, 3137, 3163, 3167, 3169, 3181, 3187, 3191, 3203, 3209, 3217, | ||
37 | 3221, 3229, 3251, 3253, 3257, 3259, 3271, 3299, 3301, 3307, 3313, 3319, 3323, 3329, 3331, 3343, 3347, 3359, | ||
38 | 3361, 3371, 3373, 3389, 3391, 3407, 3413, 3433, 3449, 3457, 3461, 3463, 3467, 3469, 3491, 3499, 3511, 3517, | ||
39 | 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 | 3797, 3803, 3821, 3823, 3833, 3847, 3851, 3853, 3863, 3877, 3881, 3889, 3907, 3911 }; | ||
42 | |||
43 | protected static final long LARGESTPRIME30BITS = 1073741789; | ||
44 | |||
45 | public TupleHashProvider() { | ||
46 | if (primes.length < MAX_PRACTICAL_DEPTH) { | ||
47 | throw new UnsupportedOperationException( | ||
48 | "Not enough prime numbers to support the practical depth of continuous hash!"); | ||
49 | } | ||
50 | } | ||
51 | |||
52 | @Override | ||
53 | public int getHash(Tuple key, int index) { | ||
54 | if (index >= primes.length) { | ||
55 | throw new IllegalArgumentException("Not enough prime numbers to support index"); | ||
56 | } | ||
57 | long accumulator = 0; | ||
58 | final int prime = primes[index]; | ||
59 | for (int i = 0; i < key.getSize(); i++) { | ||
60 | accumulator = (prime * accumulator + key.get(i)) % LARGESTPRIME30BITS; | ||
61 | } | ||
62 | |||
63 | return (int) accumulator; | ||
64 | } | ||
65 | } | ||
diff --git a/store/src/main/java/org/eclipse/viatra/solver/data/model/TupleHashProviderBitMagic.java b/store/src/main/java/org/eclipse/viatra/solver/data/model/TupleHashProviderBitMagic.java deleted file mode 100644 index 2a514d66..00000000 --- a/store/src/main/java/org/eclipse/viatra/solver/data/model/TupleHashProviderBitMagic.java +++ /dev/null | |||
@@ -1,28 +0,0 @@ | |||
1 | package org.eclipse.viatra.solver.data.model; | ||
2 | |||
3 | import org.eclipse.viatra.solver.data.map.ContinousHashProvider; | ||
4 | |||
5 | public class TupleHashProviderBitMagic implements ContinousHashProvider<Tuple> { | ||
6 | |||
7 | @Override | ||
8 | public int getHash(Tuple key, int index) { | ||
9 | if(key.getSize() == 1) { | ||
10 | return key.get(0); | ||
11 | } | ||
12 | |||
13 | int result = 0; | ||
14 | final int startBitIndex = index*30; | ||
15 | final int finalBitIndex = startBitIndex+30; | ||
16 | final int arity = key.getSize(); | ||
17 | |||
18 | for(int i = startBitIndex; i<=finalBitIndex; i++) { | ||
19 | final int selectedKey = key.get(i%arity); | ||
20 | final int selectedPosition = 1<<(i/arity); | ||
21 | if((selectedKey&selectedPosition) != 0) { | ||
22 | result |= 1<<(i%30); | ||
23 | } | ||
24 | } | ||
25 | |||
26 | return result; | ||
27 | } | ||
28 | } | ||
diff --git a/store/src/main/java/org/eclipse/viatra/solver/data/model/internal/ModelImpl.java b/store/src/main/java/org/eclipse/viatra/solver/data/model/internal/ModelImpl.java deleted file mode 100644 index 6d7f4e97..00000000 --- a/store/src/main/java/org/eclipse/viatra/solver/data/model/internal/ModelImpl.java +++ /dev/null | |||
@@ -1,124 +0,0 @@ | |||
1 | package org.eclipse.viatra.solver.data.model.internal; | ||
2 | |||
3 | import java.util.HashMap; | ||
4 | import java.util.Map; | ||
5 | import java.util.Set; | ||
6 | |||
7 | import org.eclipse.viatra.solver.data.map.ContinousHashProvider; | ||
8 | import org.eclipse.viatra.solver.data.map.Cursor; | ||
9 | import org.eclipse.viatra.solver.data.map.DiffCursor; | ||
10 | import org.eclipse.viatra.solver.data.map.VersionedMap; | ||
11 | import org.eclipse.viatra.solver.data.map.internal.MapDiffCursor; | ||
12 | import org.eclipse.viatra.solver.data.model.Model; | ||
13 | import org.eclipse.viatra.solver.data.model.ModelDiffCursor; | ||
14 | import org.eclipse.viatra.solver.data.model.ModelStore; | ||
15 | import org.eclipse.viatra.solver.data.model.representation.DataRepresentation; | ||
16 | |||
17 | public class ModelImpl implements Model { | ||
18 | private final ModelStore store; | ||
19 | private final Map<DataRepresentation<?, ?>, VersionedMap<?, ?>> maps; | ||
20 | |||
21 | public ModelImpl(ModelStore store, Map<DataRepresentation<?, ?>, VersionedMap<?, ?>> maps) { | ||
22 | this.store = store; | ||
23 | this.maps = maps; | ||
24 | } | ||
25 | |||
26 | @Override | ||
27 | public Set<DataRepresentation<?, ?>> getDataRepresentations() { | ||
28 | return maps.keySet(); | ||
29 | } | ||
30 | |||
31 | @SuppressWarnings("unchecked") | ||
32 | private <K, V> VersionedMap<K, V> getMap(DataRepresentation<K, V> representation) { | ||
33 | if (maps.containsKey(representation)) { | ||
34 | return (VersionedMap<K, V>) maps.get(representation); | ||
35 | } else { | ||
36 | throw new IllegalArgumentException("Model does have representation " + representation); | ||
37 | } | ||
38 | } | ||
39 | |||
40 | private <K, V> VersionedMap<K, V> getMapValidateKey(DataRepresentation<K, V> representation, K key) { | ||
41 | if (representation.isValidKey(key)) { | ||
42 | return getMap(representation); | ||
43 | } else { | ||
44 | throw new IllegalArgumentException( | ||
45 | "Key is not valid for representation! (representation=" + representation + ", key=" + key + ");"); | ||
46 | } | ||
47 | } | ||
48 | |||
49 | @Override | ||
50 | public <K, V> V get(DataRepresentation<K, V> representation, K key) { | ||
51 | return getMapValidateKey(representation, key).get(key); | ||
52 | } | ||
53 | |||
54 | @Override | ||
55 | public <K, V> Cursor<K, V> getAll(DataRepresentation<K, V> representation) { | ||
56 | return getMap(representation).getAll(); | ||
57 | } | ||
58 | |||
59 | @Override | ||
60 | public <K, V> V put(DataRepresentation<K, V> representation, K key, V value) { | ||
61 | return getMapValidateKey(representation, key).put(key, value); | ||
62 | } | ||
63 | |||
64 | @Override | ||
65 | public <K, V> void putAll(DataRepresentation<K, V> representation, Cursor<K, V> cursor) { | ||
66 | getMap(representation).putAll(cursor); | ||
67 | } | ||
68 | |||
69 | @Override | ||
70 | public <K, V> long getSize(DataRepresentation<K, V> representation) { | ||
71 | return getMap(representation).getSize(); | ||
72 | } | ||
73 | |||
74 | @Override | ||
75 | public ModelDiffCursor getDiffCursor(long to) { | ||
76 | Model toModel = store.createModel(to); | ||
77 | Map<DataRepresentation<?, ?>, DiffCursor<?, ?>> diffCursors = new HashMap<>(); | ||
78 | for (DataRepresentation<?, ?> representation : this.maps.keySet()) { | ||
79 | MapDiffCursor<?, ?> diffCursor = constructDiffCursor(toModel, representation); | ||
80 | diffCursors.put(representation, diffCursor); | ||
81 | } | ||
82 | return new ModelDiffCursor(diffCursors); | ||
83 | } | ||
84 | |||
85 | private <K, V> MapDiffCursor<K, V> constructDiffCursor(Model toModel, DataRepresentation<K, V> representation) { | ||
86 | @SuppressWarnings("unchecked") | ||
87 | Cursor<K, V> fromCursor = (Cursor<K, V>) this.maps.get(representation).getAll(); | ||
88 | Cursor<K, V> toCursor = toModel.getAll(representation); | ||
89 | |||
90 | ContinousHashProvider<K> hashProvider = representation.getHashProvider(); | ||
91 | V defaultValue = representation.getDefaultValue(); | ||
92 | return new MapDiffCursor<>(hashProvider, defaultValue, fromCursor, toCursor); | ||
93 | } | ||
94 | |||
95 | @Override | ||
96 | public long commit() { | ||
97 | long version = 0; | ||
98 | boolean versionSet = false; | ||
99 | for (VersionedMap<?, ?> map : maps.values()) { | ||
100 | long newVersion = map.commit(); | ||
101 | if (versionSet) { | ||
102 | if (version != newVersion) { | ||
103 | throw new IllegalStateException( | ||
104 | "Maps in model have different versions! (" + version + " and" + newVersion + ")"); | ||
105 | } | ||
106 | } else { | ||
107 | version = newVersion; | ||
108 | versionSet = true; | ||
109 | } | ||
110 | } | ||
111 | return version; | ||
112 | } | ||
113 | |||
114 | @Override | ||
115 | public void restore(long state) { | ||
116 | if(store.getStates().contains(state)) { | ||
117 | for (VersionedMap<?, ?> map : maps.values()) { | ||
118 | map.restore(state); | ||
119 | } | ||
120 | } else { | ||
121 | throw new IllegalArgumentException("Map does not contain state "+state+"!"); | ||
122 | } | ||
123 | } | ||
124 | } | ||
diff --git a/store/src/main/java/org/eclipse/viatra/solver/data/model/internal/SimilarRelationEquivalenceClass.java b/store/src/main/java/org/eclipse/viatra/solver/data/model/internal/SimilarRelationEquivalenceClass.java deleted file mode 100644 index 7054e4db..00000000 --- a/store/src/main/java/org/eclipse/viatra/solver/data/model/internal/SimilarRelationEquivalenceClass.java +++ /dev/null | |||
@@ -1,33 +0,0 @@ | |||
1 | package org.eclipse.viatra.solver.data.model.internal; | ||
2 | |||
3 | import java.util.Objects; | ||
4 | |||
5 | import org.eclipse.viatra.solver.data.map.ContinousHashProvider; | ||
6 | import org.eclipse.viatra.solver.data.model.Tuple; | ||
7 | import org.eclipse.viatra.solver.data.model.representation.Relation; | ||
8 | |||
9 | public class SimilarRelationEquivalenceClass { | ||
10 | final ContinousHashProvider<Tuple> hashProvider; | ||
11 | final Object defaultValue; | ||
12 | final int arity; | ||
13 | public SimilarRelationEquivalenceClass(Relation<?> representation) { | ||
14 | this.hashProvider = representation.getHashProvider(); | ||
15 | this.defaultValue = representation.getDefaultValue(); | ||
16 | this.arity = representation.getArity(); | ||
17 | } | ||
18 | @Override | ||
19 | public int hashCode() { | ||
20 | return Objects.hash(arity, defaultValue, hashProvider); | ||
21 | } | ||
22 | @Override | ||
23 | public boolean equals(Object obj) { | ||
24 | if (this == obj) | ||
25 | return true; | ||
26 | if (!(obj instanceof SimilarRelationEquivalenceClass)) | ||
27 | return false; | ||
28 | SimilarRelationEquivalenceClass other = (SimilarRelationEquivalenceClass) obj; | ||
29 | return arity == other.arity && Objects.equals(defaultValue, other.defaultValue) | ||
30 | && Objects.equals(hashProvider, other.hashProvider); | ||
31 | } | ||
32 | |||
33 | } | ||
diff --git a/store/src/main/java/org/eclipse/viatra/solver/data/model/representation/AuxilaryData.java b/store/src/main/java/org/eclipse/viatra/solver/data/model/representation/AuxilaryData.java deleted file mode 100644 index 7fc79348..00000000 --- a/store/src/main/java/org/eclipse/viatra/solver/data/model/representation/AuxilaryData.java +++ /dev/null | |||
@@ -1,22 +0,0 @@ | |||
1 | package org.eclipse.viatra.solver.data.model.representation; | ||
2 | |||
3 | import org.eclipse.viatra.solver.data.map.ContinousHashProvider; | ||
4 | |||
5 | public class AuxilaryData<K,V> extends DataRepresentation<K, V> { | ||
6 | private final String name; | ||
7 | |||
8 | public AuxilaryData(String name, ContinousHashProvider<K> hashProvider, V defaultValue) { | ||
9 | super(hashProvider, defaultValue); | ||
10 | this.name = name; | ||
11 | } | ||
12 | |||
13 | @Override | ||
14 | public String getName() { | ||
15 | return name; | ||
16 | } | ||
17 | |||
18 | @Override | ||
19 | public boolean isValidKey(K key) { | ||
20 | return true; | ||
21 | } | ||
22 | } | ||
diff --git a/store/src/main/java/org/eclipse/viatra/solver/data/model/representation/DataRepresentation.java b/store/src/main/java/org/eclipse/viatra/solver/data/model/representation/DataRepresentation.java deleted file mode 100644 index fd48eb94..00000000 --- a/store/src/main/java/org/eclipse/viatra/solver/data/model/representation/DataRepresentation.java +++ /dev/null | |||
@@ -1,24 +0,0 @@ | |||
1 | package org.eclipse.viatra.solver.data.model.representation; | ||
2 | |||
3 | import org.eclipse.viatra.solver.data.map.ContinousHashProvider; | ||
4 | |||
5 | public abstract class DataRepresentation<K, V> { | ||
6 | protected final ContinousHashProvider<K> hashProvider; | ||
7 | protected final V defaultValue; | ||
8 | |||
9 | protected DataRepresentation(ContinousHashProvider<K> hashProvider, V defaultValue) { | ||
10 | this.hashProvider = hashProvider; | ||
11 | this.defaultValue = defaultValue; | ||
12 | } | ||
13 | |||
14 | public abstract String getName(); | ||
15 | |||
16 | public ContinousHashProvider<K> getHashProvider() { | ||
17 | return hashProvider; | ||
18 | } | ||
19 | public abstract boolean isValidKey(K key); | ||
20 | |||
21 | public V getDefaultValue() { | ||
22 | return defaultValue; | ||
23 | } | ||
24 | } | ||
diff --git a/store/src/main/java/org/eclipse/viatra/solver/data/model/representation/Relation.java b/store/src/main/java/org/eclipse/viatra/solver/data/model/representation/Relation.java deleted file mode 100644 index eafb5c56..00000000 --- a/store/src/main/java/org/eclipse/viatra/solver/data/model/representation/Relation.java +++ /dev/null | |||
@@ -1,31 +0,0 @@ | |||
1 | package org.eclipse.viatra.solver.data.model.representation; | ||
2 | |||
3 | import org.eclipse.viatra.solver.data.model.Tuple; | ||
4 | import org.eclipse.viatra.solver.data.model.TupleHashProvider; | ||
5 | |||
6 | public class Relation<D> extends DataRepresentation<Tuple, D> { | ||
7 | private final String name; | ||
8 | private final int arity; | ||
9 | |||
10 | public Relation(String name, int arity, D defaultValue) { | ||
11 | super(TupleHashProvider.singleton(), defaultValue); | ||
12 | this.name = name; | ||
13 | this.arity = arity; | ||
14 | } | ||
15 | |||
16 | @Override | ||
17 | public String getName() { | ||
18 | return name; | ||
19 | } | ||
20 | |||
21 | public int getArity() { | ||
22 | return arity; | ||
23 | } | ||
24 | |||
25 | @Override | ||
26 | public boolean isValidKey(Tuple key) { | ||
27 | if(key == null) { | ||
28 | return false; | ||
29 | } else return key.getSize() == getArity(); | ||
30 | } | ||
31 | } | ||
diff --git a/store/src/main/java/org/eclipse/viatra/solver/data/model/representation/TruthValue.java b/store/src/main/java/org/eclipse/viatra/solver/data/model/representation/TruthValue.java deleted file mode 100644 index 049c7eac..00000000 --- a/store/src/main/java/org/eclipse/viatra/solver/data/model/representation/TruthValue.java +++ /dev/null | |||
@@ -1,51 +0,0 @@ | |||
1 | package org.eclipse.viatra.solver.data.model.representation; | ||
2 | |||
3 | public enum TruthValue { | ||
4 | TRUE("true"), | ||
5 | |||
6 | FALSE("false"), | ||
7 | |||
8 | UNKNOWN("unknown"), | ||
9 | |||
10 | ERROR("error"); | ||
11 | |||
12 | private final String name; | ||
13 | |||
14 | private TruthValue(String name) { | ||
15 | this.name = name; | ||
16 | } | ||
17 | |||
18 | public String getName() { | ||
19 | return name; | ||
20 | } | ||
21 | |||
22 | public static TruthValue toTruthValue(boolean value) { | ||
23 | return value ? TRUE : FALSE; | ||
24 | } | ||
25 | |||
26 | public boolean isConsistent() { | ||
27 | return this != ERROR; | ||
28 | } | ||
29 | |||
30 | public boolean isComplete() { | ||
31 | return this != UNKNOWN; | ||
32 | } | ||
33 | |||
34 | public boolean must() { | ||
35 | return this == TRUE || this == ERROR; | ||
36 | } | ||
37 | |||
38 | public boolean may() { | ||
39 | return this == TRUE || this == UNKNOWN; | ||
40 | } | ||
41 | |||
42 | public TruthValue not() { | ||
43 | if (this == TRUE) { | ||
44 | return FALSE; | ||
45 | } else if (this == FALSE) { | ||
46 | return TRUE; | ||
47 | } else { | ||
48 | return this; | ||
49 | } | ||
50 | } | ||
51 | } | ||