diff options
author | 2023-07-24 16:51:47 +0200 | |
---|---|---|
committer | 2023-07-24 16:51:47 +0200 | |
commit | 26592fc70a026b850616fc4bc9be5a46ab1179a9 (patch) | |
tree | 0e1f22a451122169f5efd2bc683c7787c666ddd6 /subprojects | |
parent | Enabled QueryTransactionTest (diff) | |
download | refinery-26592fc70a026b850616fc4bc9be5a46ab1179a9.tar.gz refinery-26592fc70a026b850616fc4bc9be5a46ab1179a9.tar.zst refinery-26592fc70a026b850616fc4bc9be5a46ab1179a9.zip |
Refactoring packages related to VersionedMapDeltaImpl + VersionedMapStoreStateImpl, update builder.
- details of the maps goes to internal packages
- ModelStoreBuilderImpl uses VersionedMapStoreFactoryBuilder
Diffstat (limited to 'subprojects')
35 files changed, 189 insertions, 239 deletions
diff --git a/subprojects/store/src/jmh/java/tools/refinery/store/map/benchmarks/ImmutablePutExecutionPlan.java b/subprojects/store/src/jmh/java/tools/refinery/store/map/benchmarks/ImmutablePutExecutionPlan.java index 7e89cd06..4708e6d3 100644 --- a/subprojects/store/src/jmh/java/tools/refinery/store/map/benchmarks/ImmutablePutExecutionPlan.java +++ b/subprojects/store/src/jmh/java/tools/refinery/store/map/benchmarks/ImmutablePutExecutionPlan.java | |||
@@ -5,12 +5,13 @@ | |||
5 | */ | 5 | */ |
6 | package tools.refinery.store.map.benchmarks; | 6 | package tools.refinery.store.map.benchmarks; |
7 | 7 | ||
8 | import java.util.Objects; | ||
8 | import java.util.Random; | 9 | import java.util.Random; |
9 | 10 | ||
10 | import tools.refinery.store.map.ContinousHashProvider; | 11 | import tools.refinery.store.map.ContinuousHashProvider; |
11 | import tools.refinery.store.map.VersionedMapStore; | 12 | import tools.refinery.store.map.VersionedMapStore; |
12 | import tools.refinery.store.map.VersionedMapStoreImpl; | 13 | import tools.refinery.store.map.internal.state.VersionedMapStoreStateImpl; |
13 | import tools.refinery.store.map.internal.VersionedMapImpl; | 14 | import tools.refinery.store.map.internal.state.VersionedMapStateImpl; |
14 | import tools.refinery.store.map.tests.utils.MapTestEnvironment; | 15 | import tools.refinery.store.map.tests.utils.MapTestEnvironment; |
15 | 16 | ||
16 | import org.openjdk.jmh.annotations.Level; | 17 | import org.openjdk.jmh.annotations.Level; |
@@ -35,7 +36,7 @@ public class ImmutablePutExecutionPlan { | |||
35 | 36 | ||
36 | private String[] values; | 37 | private String[] values; |
37 | 38 | ||
38 | private ContinousHashProvider<Integer> hashProvider = MapTestEnvironment.prepareHashProvider(false); | 39 | private ContinuousHashProvider<Integer> hashProvider = MapTestEnvironment.prepareHashProvider(false); |
39 | 40 | ||
40 | @Setup(Level.Trial) | 41 | @Setup(Level.Trial) |
41 | public void setUpTrial() { | 42 | public void setUpTrial() { |
@@ -43,9 +44,9 @@ public class ImmutablePutExecutionPlan { | |||
43 | values = MapTestEnvironment.prepareValues(nValues, true); | 44 | values = MapTestEnvironment.prepareValues(nValues, true); |
44 | } | 45 | } |
45 | 46 | ||
46 | public VersionedMapImpl<Integer, String> createSut() { | 47 | public VersionedMapStateImpl<Integer, String> createSut() { |
47 | VersionedMapStore<Integer, String> store = new VersionedMapStoreImpl<Integer, String>(hashProvider, values[0]); | 48 | VersionedMapStore<Integer, String> store = new VersionedMapStoreStateImpl<>(hashProvider, values[0]); |
48 | return (VersionedMapImpl<Integer, String>) store.createMap(); | 49 | return (VersionedMapStateImpl<Integer, String>) store.createMap(); |
49 | } | 50 | } |
50 | 51 | ||
51 | public Integer nextKey() { | 52 | public Integer nextKey() { |
@@ -53,7 +54,7 @@ public class ImmutablePutExecutionPlan { | |||
53 | } | 54 | } |
54 | 55 | ||
55 | public boolean isDefault(String value) { | 56 | public boolean isDefault(String value) { |
56 | return value == values[0]; | 57 | return Objects.equals(value,values[0]); |
57 | } | 58 | } |
58 | 59 | ||
59 | public String nextValue() { | 60 | public String nextValue() { |
diff --git a/subprojects/store/src/main/java/tools/refinery/store/map/ContinousHashProvider.java b/subprojects/store/src/main/java/tools/refinery/store/map/ContinuousHashProvider.java index 8e451230..abc044d0 100644 --- a/subprojects/store/src/main/java/tools/refinery/store/map/ContinousHashProvider.java +++ b/subprojects/store/src/main/java/tools/refinery/store/map/ContinuousHashProvider.java | |||
@@ -5,17 +5,17 @@ | |||
5 | */ | 5 | */ |
6 | package tools.refinery.store.map; | 6 | package tools.refinery.store.map; |
7 | 7 | ||
8 | import tools.refinery.store.map.internal.Node; | 8 | import tools.refinery.store.map.internal.state.Node; |
9 | 9 | ||
10 | /** | 10 | /** |
11 | * A class representing an equivalence relation for a type {@code K} with a | 11 | * A class representing an equivalence relation for a type {@code K} with a |
12 | * continuous hash function. | 12 | * continuous hash function. |
13 | * | 13 | * |
14 | * @author Oszkar Semerath | 14 | * @author Oszkar Semerath |
15 | * | 15 | * |
16 | * @param <K> Target java type. | 16 | * @param <K> Target java type. |
17 | */ | 17 | */ |
18 | public interface ContinousHashProvider<K> { | 18 | public interface ContinuousHashProvider<K> { |
19 | public static final int EFFECTIVE_BITS = Node.EFFECTIVE_BITS; | 19 | public static final int EFFECTIVE_BITS = Node.EFFECTIVE_BITS; |
20 | public static final int EFFECTIVE_BIT_MASK = (1 << (EFFECTIVE_BITS)) - 1; | 20 | public static final int EFFECTIVE_BIT_MASK = (1 << (EFFECTIVE_BITS)) - 1; |
21 | 21 | ||
@@ -38,9 +38,9 @@ public interface ContinousHashProvider<K> { | |||
38 | * {@link #EFFECTIVE_BITS} | 38 | * {@link #EFFECTIVE_BITS} |
39 | * </ul> | 39 | * </ul> |
40 | * Check {@link #equals} for further details. | 40 | * Check {@link #equals} for further details. |
41 | * | 41 | * |
42 | * @param key The target data object. | 42 | * @param key The target data object. |
43 | * @param index The depth of the the hash code. Needs to be non-negative. | 43 | * @param index The depth of the hash code. Needs to be non-negative. |
44 | * @return A hash code. | 44 | * @return A hash code. |
45 | */ | 45 | */ |
46 | public int getHash(K key, int index); | 46 | public int getHash(K key, int index); |
@@ -53,7 +53,7 @@ public interface ContinousHashProvider<K> { | |||
53 | if (key1.equals(key2)) { | 53 | if (key1.equals(key2)) { |
54 | return 0; | 54 | return 0; |
55 | } else { | 55 | } else { |
56 | for (int i = 0; i < ContinousHashProvider.MAX_PRACTICAL_DEPTH; i++) { | 56 | for (int i = 0; i < ContinuousHashProvider.MAX_PRACTICAL_DEPTH; i++) { |
57 | int hash1 = getEffectiveHash(key1, i); | 57 | int hash1 = getEffectiveHash(key1, i); |
58 | int hash2 = getEffectiveHash(key2, i); | 58 | int hash2 = getEffectiveHash(key2, i); |
59 | for(int j = 0; j<Integer.SIZE/Node.BRANCHING_FACTOR_BITS; j++) { | 59 | for(int j = 0; j<Integer.SIZE/Node.BRANCHING_FACTOR_BITS; j++) { |
@@ -68,7 +68,7 @@ public interface ContinousHashProvider<K> { | |||
68 | } | 68 | } |
69 | throw new IllegalArgumentException("Two different keys (" + key1 + " and " + key2 | 69 | throw new IllegalArgumentException("Two different keys (" + key1 + " and " + key2 |
70 | + ") have the same hashcode over the practical depth limitation (" | 70 | + ") have the same hashcode over the practical depth limitation (" |
71 | + ContinousHashProvider.MAX_PRACTICAL_DEPTH + ")!"); | 71 | + ContinuousHashProvider.MAX_PRACTICAL_DEPTH + ")!"); |
72 | } | 72 | } |
73 | } | 73 | } |
74 | } | 74 | } |
diff --git a/subprojects/store/src/main/java/tools/refinery/store/map/internal/IteratorAsCursor.java b/subprojects/store/src/main/java/tools/refinery/store/map/IteratorAsCursor.java index d1ab8bb1..29b03edf 100644 --- a/subprojects/store/src/main/java/tools/refinery/store/map/internal/IteratorAsCursor.java +++ b/subprojects/store/src/main/java/tools/refinery/store/map/IteratorAsCursor.java | |||
@@ -1,16 +1,14 @@ | |||
1 | /* | 1 | /* |
2 | * SPDX-FileCopyrightText: 2021-2023 The Refinery Authors <https://refinery.tools/> | 2 | * SPDX-FileCopyrightText: 2023 The Refinery Authors <https://refinery.tools/> |
3 | * | 3 | * |
4 | * SPDX-License-Identifier: EPL-2.0 | 4 | * SPDX-License-Identifier: EPL-2.0 |
5 | */ | 5 | */ |
6 | package tools.refinery.store.map.internal; | 6 | package tools.refinery.store.map; |
7 | 7 | ||
8 | import java.util.*; | 8 | import java.util.Iterator; |
9 | import java.util.Map; | ||
9 | import java.util.Map.Entry; | 10 | import java.util.Map.Entry; |
10 | 11 | import java.util.Set; | |
11 | import tools.refinery.store.map.AnyVersionedMap; | ||
12 | import tools.refinery.store.map.Cursor; | ||
13 | import tools.refinery.store.map.VersionedMap; | ||
14 | 12 | ||
15 | public class IteratorAsCursor<K, V> implements Cursor<K, V> { | 13 | public class IteratorAsCursor<K, V> implements Cursor<K, V> { |
16 | final Iterator<Entry<K, V>> iterator; | 14 | final Iterator<Entry<K, V>> iterator; |
diff --git a/subprojects/store/src/main/java/tools/refinery/store/map/VersionedMapStoreFactoryBuilder.java b/subprojects/store/src/main/java/tools/refinery/store/map/VersionedMapStoreFactoryBuilder.java index 6329a2f6..6b4fc2a0 100644 --- a/subprojects/store/src/main/java/tools/refinery/store/map/VersionedMapStoreFactoryBuilder.java +++ b/subprojects/store/src/main/java/tools/refinery/store/map/VersionedMapStoreFactoryBuilder.java | |||
@@ -22,7 +22,7 @@ public interface VersionedMapStoreFactoryBuilder<K,V> { | |||
22 | VersionedMapStoreFactoryBuilder<K,V> strategy(StoreStrategy strategy); | 22 | VersionedMapStoreFactoryBuilder<K,V> strategy(StoreStrategy strategy); |
23 | VersionedMapStoreFactoryBuilder<K,V> stateBasedImmutableWhenCommitting(boolean transformToImmutable); | 23 | VersionedMapStoreFactoryBuilder<K,V> stateBasedImmutableWhenCommitting(boolean transformToImmutable); |
24 | VersionedMapStoreFactoryBuilder<K,V> stateBasedSharingStrategy(SharingStrategy sharingStrategy); | 24 | VersionedMapStoreFactoryBuilder<K,V> stateBasedSharingStrategy(SharingStrategy sharingStrategy); |
25 | VersionedMapStoreFactoryBuilder<K,V> stateBasedHashProvider(ContinousHashProvider<K> hashProvider); | 25 | VersionedMapStoreFactoryBuilder<K,V> stateBasedHashProvider(ContinuousHashProvider<K> hashProvider); |
26 | VersionedMapStoreFactoryBuilder<K,V> deltaTransactionStrategy(DeltaTransactionStrategy deltaStrategy); | 26 | VersionedMapStoreFactoryBuilder<K,V> deltaTransactionStrategy(DeltaTransactionStrategy deltaStrategy); |
27 | 27 | ||
28 | VersionedMapStoreFactory<K,V> build(); | 28 | VersionedMapStoreFactory<K,V> build(); |
diff --git a/subprojects/store/src/main/java/tools/refinery/store/map/internal/HashClash.java b/subprojects/store/src/main/java/tools/refinery/store/map/internal/HashClash.java deleted file mode 100644 index a357fbce..00000000 --- a/subprojects/store/src/main/java/tools/refinery/store/map/internal/HashClash.java +++ /dev/null | |||
@@ -1,23 +0,0 @@ | |||
1 | /* | ||
2 | * SPDX-FileCopyrightText: 2021-2023 The Refinery Authors <https://refinery.tools/> | ||
3 | * | ||
4 | * SPDX-License-Identifier: EPL-2.0 | ||
5 | */ | ||
6 | package tools.refinery.store.map.internal; | ||
7 | |||
8 | enum HashClash { | ||
9 | /** | ||
10 | * Not stuck. | ||
11 | */ | ||
12 | NONE, | ||
13 | |||
14 | /** | ||
15 | * Clashed, next we should return the key of cursor 1. | ||
16 | */ | ||
17 | STUCK_CURSOR_1, | ||
18 | |||
19 | /** | ||
20 | * Clashed, next we should return the key of cursor 2. | ||
21 | */ | ||
22 | STUCK_CURSOR_2 | ||
23 | } | ||
diff --git a/subprojects/store/src/main/java/tools/refinery/store/map/internal/VersionedMapStoreFactoryBuilderImpl.java b/subprojects/store/src/main/java/tools/refinery/store/map/internal/VersionedMapStoreFactoryBuilderImpl.java index cf117d95..47470236 100644 --- a/subprojects/store/src/main/java/tools/refinery/store/map/internal/VersionedMapStoreFactoryBuilderImpl.java +++ b/subprojects/store/src/main/java/tools/refinery/store/map/internal/VersionedMapStoreFactoryBuilderImpl.java | |||
@@ -5,9 +5,11 @@ | |||
5 | */ | 5 | */ |
6 | package tools.refinery.store.map.internal; | 6 | package tools.refinery.store.map.internal; |
7 | 7 | ||
8 | import tools.refinery.store.map.ContinousHashProvider; | 8 | import tools.refinery.store.map.ContinuousHashProvider; |
9 | import tools.refinery.store.map.VersionedMapStoreFactory; | 9 | import tools.refinery.store.map.VersionedMapStoreFactory; |
10 | import tools.refinery.store.map.VersionedMapStoreFactoryBuilder; | 10 | import tools.refinery.store.map.VersionedMapStoreFactoryBuilder; |
11 | import tools.refinery.store.map.internal.delta.DeltaBasedVersionedMapStoreFactory; | ||
12 | import tools.refinery.store.map.internal.state.StateBasedVersionedMapStoreFactory; | ||
11 | 13 | ||
12 | public class VersionedMapStoreFactoryBuilderImpl<K, V> implements VersionedMapStoreFactoryBuilder<K, V> { | 14 | public class VersionedMapStoreFactoryBuilderImpl<K, V> implements VersionedMapStoreFactoryBuilder<K, V> { |
13 | 15 | ||
@@ -16,14 +18,14 @@ public class VersionedMapStoreFactoryBuilderImpl<K, V> implements VersionedMapSt | |||
16 | private StoreStrategy strategy = null; | 18 | private StoreStrategy strategy = null; |
17 | private Boolean transformToImmutable = null; | 19 | private Boolean transformToImmutable = null; |
18 | private SharingStrategy sharingStrategy = null; | 20 | private SharingStrategy sharingStrategy = null; |
19 | private ContinousHashProvider<K> continousHashProvider = null; | 21 | private ContinuousHashProvider<K> continuousHashProvider = null; |
20 | private DeltaTransactionStrategy deltaTransactionStrategy = null; | 22 | private DeltaTransactionStrategy deltaTransactionStrategy = null; |
21 | 23 | ||
22 | private StoreStrategy checkStrategy() { | 24 | private StoreStrategy checkStrategy() { |
23 | StoreStrategy currentStrategy = strategy; | 25 | StoreStrategy currentStrategy = strategy; |
24 | currentStrategy = mergeStrategies(currentStrategy, transformToImmutable, StoreStrategy.STATE); | 26 | currentStrategy = mergeStrategies(currentStrategy, transformToImmutable, StoreStrategy.STATE); |
25 | currentStrategy = mergeStrategies(currentStrategy, sharingStrategy, StoreStrategy.STATE); | 27 | currentStrategy = mergeStrategies(currentStrategy, sharingStrategy, StoreStrategy.STATE); |
26 | currentStrategy = mergeStrategies(currentStrategy, continousHashProvider, StoreStrategy.STATE); | 28 | currentStrategy = mergeStrategies(currentStrategy, continuousHashProvider, StoreStrategy.STATE); |
27 | currentStrategy = mergeStrategies(currentStrategy, deltaTransactionStrategy, StoreStrategy.DELTA); | 29 | currentStrategy = mergeStrategies(currentStrategy, deltaTransactionStrategy, StoreStrategy.DELTA); |
28 | return currentStrategy; | 30 | return currentStrategy; |
29 | } | 31 | } |
@@ -77,8 +79,8 @@ public class VersionedMapStoreFactoryBuilderImpl<K, V> implements VersionedMapSt | |||
77 | } | 79 | } |
78 | 80 | ||
79 | @Override | 81 | @Override |
80 | public VersionedMapStoreFactoryBuilder<K, V> stateBasedHashProvider(ContinousHashProvider<K> hashProvider) { | 82 | public VersionedMapStoreFactoryBuilder<K, V> stateBasedHashProvider(ContinuousHashProvider<K> hashProvider) { |
81 | this.continousHashProvider = hashProvider; | 83 | this.continuousHashProvider = hashProvider; |
82 | checkStrategy(); | 84 | checkStrategy(); |
83 | return this; | 85 | return this; |
84 | } | 86 | } |
@@ -110,13 +112,13 @@ public class VersionedMapStoreFactoryBuilderImpl<K, V> implements VersionedMapSt | |||
110 | } | 112 | } |
111 | return switch (strategyToUse) { | 113 | return switch (strategyToUse) { |
112 | case STATE -> { | 114 | case STATE -> { |
113 | if(continousHashProvider == null) { | 115 | if(continuousHashProvider == null) { |
114 | throw new IllegalArgumentException("Continuous hash provider is missing!"); | 116 | throw new IllegalArgumentException("Continuous hash provider is missing!"); |
115 | } | 117 | } |
116 | yield new StateBasedVersionedMapStoreFactory<>(defaultValue, | 118 | yield new StateBasedVersionedMapStoreFactory<>(defaultValue, |
117 | getOrDefault(transformToImmutable,true), | 119 | getOrDefault(transformToImmutable,true), |
118 | getOrDefault(sharingStrategy, SharingStrategy.SHARED_NODE_CACHE_IN_GROUP), | 120 | getOrDefault(sharingStrategy, SharingStrategy.SHARED_NODE_CACHE_IN_GROUP), |
119 | continousHashProvider); | 121 | continuousHashProvider); |
120 | } | 122 | } |
121 | case DELTA -> new DeltaBasedVersionedMapStoreFactory<>(defaultValue, | 123 | case DELTA -> new DeltaBasedVersionedMapStoreFactory<>(defaultValue, |
122 | getOrDefault(deltaTransactionStrategy, DeltaTransactionStrategy.LIST)); | 124 | getOrDefault(deltaTransactionStrategy, DeltaTransactionStrategy.LIST)); |
@@ -130,7 +132,7 @@ public class VersionedMapStoreFactoryBuilderImpl<K, V> implements VersionedMapSt | |||
130 | ", strategy=" + strategy + | 132 | ", strategy=" + strategy + |
131 | ", stateBasedImmutableWhenCommitting=" + transformToImmutable + | 133 | ", stateBasedImmutableWhenCommitting=" + transformToImmutable + |
132 | ", stateBasedNodeSharingStrategy=" + sharingStrategy + | 134 | ", stateBasedNodeSharingStrategy=" + sharingStrategy + |
133 | ", hashProvider=" + continousHashProvider + | 135 | ", hashProvider=" + continuousHashProvider + |
134 | ", deltaStorageStrategy=" + deltaTransactionStrategy + | 136 | ", deltaStorageStrategy=" + deltaTransactionStrategy + |
135 | '}'; | 137 | '}'; |
136 | } | 138 | } |
diff --git a/subprojects/store/src/main/java/tools/refinery/store/map/internal/DeltaBasedVersionedMapStoreFactory.java b/subprojects/store/src/main/java/tools/refinery/store/map/internal/delta/DeltaBasedVersionedMapStoreFactory.java index fe490f46..cedcdc0b 100644 --- a/subprojects/store/src/main/java/tools/refinery/store/map/internal/DeltaBasedVersionedMapStoreFactory.java +++ b/subprojects/store/src/main/java/tools/refinery/store/map/internal/delta/DeltaBasedVersionedMapStoreFactory.java | |||
@@ -1,12 +1,11 @@ | |||
1 | /* | 1 | /* |
2 | * SPDX-FileCopyrightText: 2021-2023 The Refinery Authors <https://refinery.tools/> | 2 | * SPDX-FileCopyrightText: 2023 The Refinery Authors <https://refinery.tools/> |
3 | * | 3 | * |
4 | * SPDX-License-Identifier: EPL-2.0 | 4 | * SPDX-License-Identifier: EPL-2.0 |
5 | */ | 5 | */ |
6 | package tools.refinery.store.map.internal; | 6 | package tools.refinery.store.map.internal.delta; |
7 | 7 | ||
8 | import tools.refinery.store.map.VersionedMapStore; | 8 | import tools.refinery.store.map.VersionedMapStore; |
9 | import tools.refinery.store.map.VersionedMapStoreDeltaImpl; | ||
10 | import tools.refinery.store.map.VersionedMapStoreFactory; | 9 | import tools.refinery.store.map.VersionedMapStoreFactory; |
11 | import tools.refinery.store.map.VersionedMapStoreFactoryBuilder; | 10 | import tools.refinery.store.map.VersionedMapStoreFactoryBuilder; |
12 | 11 | ||
diff --git a/subprojects/store/src/main/java/tools/refinery/store/map/internal/DeltaDiffCursor.java b/subprojects/store/src/main/java/tools/refinery/store/map/internal/delta/DeltaDiffCursor.java index cc9003e3..ce10b246 100644 --- a/subprojects/store/src/main/java/tools/refinery/store/map/internal/DeltaDiffCursor.java +++ b/subprojects/store/src/main/java/tools/refinery/store/map/internal/delta/DeltaDiffCursor.java | |||
@@ -1,9 +1,9 @@ | |||
1 | /* | 1 | /* |
2 | * SPDX-FileCopyrightText: 2021-2023 The Refinery Authors <https://refinery.tools/> | 2 | * SPDX-FileCopyrightText: 2023 The Refinery Authors <https://refinery.tools/> |
3 | * | 3 | * |
4 | * SPDX-License-Identifier: EPL-2.0 | 4 | * SPDX-License-Identifier: EPL-2.0 |
5 | */ | 5 | */ |
6 | package tools.refinery.store.map.internal; | 6 | package tools.refinery.store.map.internal.delta; |
7 | 7 | ||
8 | import tools.refinery.store.map.AnyVersionedMap; | 8 | import tools.refinery.store.map.AnyVersionedMap; |
9 | import tools.refinery.store.map.DiffCursor; | 9 | import tools.refinery.store.map.DiffCursor; |
diff --git a/subprojects/store/src/main/java/tools/refinery/store/map/internal/MapDelta.java b/subprojects/store/src/main/java/tools/refinery/store/map/internal/delta/MapDelta.java index 2674236c..0c0cc906 100644 --- a/subprojects/store/src/main/java/tools/refinery/store/map/internal/MapDelta.java +++ b/subprojects/store/src/main/java/tools/refinery/store/map/internal/delta/MapDelta.java | |||
@@ -1,9 +1,9 @@ | |||
1 | /* | 1 | /* |
2 | * SPDX-FileCopyrightText: 2021-2023 The Refinery Authors <https://refinery.tools/> | 2 | * SPDX-FileCopyrightText: 2023 The Refinery Authors <https://refinery.tools/> |
3 | * | 3 | * |
4 | * SPDX-License-Identifier: EPL-2.0 | 4 | * SPDX-License-Identifier: EPL-2.0 |
5 | */ | 5 | */ |
6 | package tools.refinery.store.map.internal; | 6 | package tools.refinery.store.map.internal.delta; |
7 | 7 | ||
8 | public record MapDelta<K, V>(K key, V oldValue, V newValue) { | 8 | public record MapDelta<K, V>(K key, V oldValue, V newValue) { |
9 | public K getKey() { | 9 | public K getKey() { |
diff --git a/subprojects/store/src/main/java/tools/refinery/store/map/internal/MapTransaction.java b/subprojects/store/src/main/java/tools/refinery/store/map/internal/delta/MapTransaction.java index d63522cd..7f9ccd7f 100644 --- a/subprojects/store/src/main/java/tools/refinery/store/map/internal/MapTransaction.java +++ b/subprojects/store/src/main/java/tools/refinery/store/map/internal/delta/MapTransaction.java | |||
@@ -1,9 +1,9 @@ | |||
1 | /* | 1 | /* |
2 | * SPDX-FileCopyrightText: 2021-2023 The Refinery Authors <https://refinery.tools/> | 2 | * SPDX-FileCopyrightText: 2023 The Refinery Authors <https://refinery.tools/> |
3 | * | 3 | * |
4 | * SPDX-License-Identifier: EPL-2.0 | 4 | * SPDX-License-Identifier: EPL-2.0 |
5 | */ | 5 | */ |
6 | package tools.refinery.store.map.internal; | 6 | package tools.refinery.store.map.internal.delta; |
7 | 7 | ||
8 | import java.util.Arrays; | 8 | import java.util.Arrays; |
9 | import java.util.Objects; | 9 | import java.util.Objects; |
diff --git a/subprojects/store/src/main/java/tools/refinery/store/map/internal/UncommittedDeltaArrayStore.java b/subprojects/store/src/main/java/tools/refinery/store/map/internal/delta/UncommittedDeltaArrayStore.java index ba59cfef..1f6a9000 100644 --- a/subprojects/store/src/main/java/tools/refinery/store/map/internal/UncommittedDeltaArrayStore.java +++ b/subprojects/store/src/main/java/tools/refinery/store/map/internal/delta/UncommittedDeltaArrayStore.java | |||
@@ -1,9 +1,9 @@ | |||
1 | /* | 1 | /* |
2 | * SPDX-FileCopyrightText: 2021-2023 The Refinery Authors <https://refinery.tools/> | 2 | * SPDX-FileCopyrightText: 2023 The Refinery Authors <https://refinery.tools/> |
3 | * | 3 | * |
4 | * SPDX-License-Identifier: EPL-2.0 | 4 | * SPDX-License-Identifier: EPL-2.0 |
5 | */ | 5 | */ |
6 | package tools.refinery.store.map.internal; | 6 | package tools.refinery.store.map.internal.delta; |
7 | 7 | ||
8 | import java.util.ArrayList; | 8 | import java.util.ArrayList; |
9 | import java.util.List; | 9 | import java.util.List; |
diff --git a/subprojects/store/src/main/java/tools/refinery/store/map/internal/UncommittedDeltaMapStore.java b/subprojects/store/src/main/java/tools/refinery/store/map/internal/delta/UncommittedDeltaMapStore.java index 61a34351..644884a6 100644 --- a/subprojects/store/src/main/java/tools/refinery/store/map/internal/UncommittedDeltaMapStore.java +++ b/subprojects/store/src/main/java/tools/refinery/store/map/internal/delta/UncommittedDeltaMapStore.java | |||
@@ -1,9 +1,9 @@ | |||
1 | /* | 1 | /* |
2 | * SPDX-FileCopyrightText: 2021-2023 The Refinery Authors <https://refinery.tools/> | 2 | * SPDX-FileCopyrightText: 2023 The Refinery Authors <https://refinery.tools/> |
3 | * | 3 | * |
4 | * SPDX-License-Identifier: EPL-2.0 | 4 | * SPDX-License-Identifier: EPL-2.0 |
5 | */ | 5 | */ |
6 | package tools.refinery.store.map.internal; | 6 | package tools.refinery.store.map.internal.delta; |
7 | 7 | ||
8 | import java.util.*; | 8 | import java.util.*; |
9 | import java.util.Map.Entry; | 9 | import java.util.Map.Entry; |
diff --git a/subprojects/store/src/main/java/tools/refinery/store/map/internal/UncommittedDeltaStore.java b/subprojects/store/src/main/java/tools/refinery/store/map/internal/delta/UncommittedDeltaStore.java index 438b5561..ecd33c5f 100644 --- a/subprojects/store/src/main/java/tools/refinery/store/map/internal/UncommittedDeltaStore.java +++ b/subprojects/store/src/main/java/tools/refinery/store/map/internal/delta/UncommittedDeltaStore.java | |||
@@ -1,9 +1,9 @@ | |||
1 | /* | 1 | /* |
2 | * SPDX-FileCopyrightText: 2021-2023 The Refinery Authors <https://refinery.tools/> | 2 | * SPDX-FileCopyrightText: 2023 The Refinery Authors <https://refinery.tools/> |
3 | * | 3 | * |
4 | * SPDX-License-Identifier: EPL-2.0 | 4 | * SPDX-License-Identifier: EPL-2.0 |
5 | */ | 5 | */ |
6 | package tools.refinery.store.map.internal; | 6 | package tools.refinery.store.map.internal.delta; |
7 | 7 | ||
8 | public interface UncommittedDeltaStore<K, V> { | 8 | public interface UncommittedDeltaStore<K, V> { |
9 | void processChange(K key, V oldValue, V newValue); | 9 | void processChange(K key, V oldValue, V newValue); |
diff --git a/subprojects/store/src/main/java/tools/refinery/store/map/internal/VersionedMapDeltaImpl.java b/subprojects/store/src/main/java/tools/refinery/store/map/internal/delta/VersionedMapDeltaImpl.java index ae47feda..5bb864ac 100644 --- a/subprojects/store/src/main/java/tools/refinery/store/map/internal/VersionedMapDeltaImpl.java +++ b/subprojects/store/src/main/java/tools/refinery/store/map/internal/delta/VersionedMapDeltaImpl.java | |||
@@ -1,13 +1,14 @@ | |||
1 | /* | 1 | /* |
2 | * SPDX-FileCopyrightText: 2021-2023 The Refinery Authors <https://refinery.tools/> | 2 | * SPDX-FileCopyrightText: 2023 The Refinery Authors <https://refinery.tools/> |
3 | * | 3 | * |
4 | * SPDX-License-Identifier: EPL-2.0 | 4 | * SPDX-License-Identifier: EPL-2.0 |
5 | */ | 5 | */ |
6 | package tools.refinery.store.map.internal; | 6 | package tools.refinery.store.map.internal.delta; |
7 | 7 | ||
8 | import java.util.*; | 8 | import java.util.*; |
9 | 9 | ||
10 | import tools.refinery.store.map.*; | 10 | import tools.refinery.store.map.*; |
11 | import tools.refinery.store.map.IteratorAsCursor; | ||
11 | 12 | ||
12 | public class VersionedMapDeltaImpl<K, V> implements VersionedMap<K, V> { | 13 | public class VersionedMapDeltaImpl<K, V> implements VersionedMap<K, V> { |
13 | protected final VersionedMapStoreDeltaImpl<K, V> store; | 14 | protected final VersionedMapStoreDeltaImpl<K, V> store; |
diff --git a/subprojects/store/src/main/java/tools/refinery/store/map/VersionedMapStoreDeltaImpl.java b/subprojects/store/src/main/java/tools/refinery/store/map/internal/delta/VersionedMapStoreDeltaImpl.java index 0c61bd09..7f56ea77 100644 --- a/subprojects/store/src/main/java/tools/refinery/store/map/VersionedMapStoreDeltaImpl.java +++ b/subprojects/store/src/main/java/tools/refinery/store/map/internal/delta/VersionedMapStoreDeltaImpl.java | |||
@@ -1,13 +1,15 @@ | |||
1 | /* | 1 | /* |
2 | * SPDX-FileCopyrightText: 2021-2023 The Refinery Authors <https://refinery.tools/> | 2 | * SPDX-FileCopyrightText: 2023 The Refinery Authors <https://refinery.tools/> |
3 | * | 3 | * |
4 | * SPDX-License-Identifier: EPL-2.0 | 4 | * SPDX-License-Identifier: EPL-2.0 |
5 | */ | 5 | */ |
6 | package tools.refinery.store.map; | 6 | package tools.refinery.store.map.internal.delta; |
7 | 7 | ||
8 | import java.util.*; | 8 | import tools.refinery.store.map.DiffCursor; |
9 | import tools.refinery.store.map.VersionedMap; | ||
10 | import tools.refinery.store.map.VersionedMapStore; | ||
9 | 11 | ||
10 | import tools.refinery.store.map.internal.*; | 12 | import java.util.*; |
11 | 13 | ||
12 | public class VersionedMapStoreDeltaImpl<K, V> implements VersionedMapStore<K, V> { | 14 | public class VersionedMapStoreDeltaImpl<K, V> implements VersionedMapStore<K, V> { |
13 | // Configuration | 15 | // Configuration |
diff --git a/subprojects/store/src/main/java/tools/refinery/store/map/internal/ImmutableNode.java b/subprojects/store/src/main/java/tools/refinery/store/map/internal/state/ImmutableNode.java index d052318f..722f9ed7 100644 --- a/subprojects/store/src/main/java/tools/refinery/store/map/internal/ImmutableNode.java +++ b/subprojects/store/src/main/java/tools/refinery/store/map/internal/state/ImmutableNode.java | |||
@@ -1,14 +1,14 @@ | |||
1 | /* | 1 | /* |
2 | * SPDX-FileCopyrightText: 2021-2023 The Refinery Authors <https://refinery.tools/> | 2 | * SPDX-FileCopyrightText: 2023 The Refinery Authors <https://refinery.tools/> |
3 | * | 3 | * |
4 | * SPDX-License-Identifier: EPL-2.0 | 4 | * SPDX-License-Identifier: EPL-2.0 |
5 | */ | 5 | */ |
6 | package tools.refinery.store.map.internal; | 6 | package tools.refinery.store.map.internal.state; |
7 | 7 | ||
8 | import java.util.Arrays; | 8 | import java.util.Arrays; |
9 | import java.util.Map; | 9 | import java.util.Map; |
10 | 10 | ||
11 | import tools.refinery.store.map.ContinousHashProvider; | 11 | import tools.refinery.store.map.ContinuousHashProvider; |
12 | 12 | ||
13 | public class ImmutableNode<K, V> extends Node<K, V> { | 13 | public class ImmutableNode<K, V> extends Node<K, V> { |
14 | /** | 14 | /** |
@@ -104,7 +104,7 @@ public class ImmutableNode<K, V> extends Node<K, V> { | |||
104 | } | 104 | } |
105 | 105 | ||
106 | @Override | 106 | @Override |
107 | public V getValue(K key, ContinousHashProvider<? super K> hashProvider, V defaultValue, int hash, int depth) { | 107 | public V getValue(K key, ContinuousHashProvider<? super K> hashProvider, V defaultValue, int hash, int depth) { |
108 | int selectedHashFragment = hashFragment(hash, shiftDepth(depth)); | 108 | int selectedHashFragment = hashFragment(hash, shiftDepth(depth)); |
109 | int bitposition = 1 << selectedHashFragment; | 109 | int bitposition = 1 << selectedHashFragment; |
110 | // If the key is stored as a data | 110 | // If the key is stored as a data |
@@ -133,7 +133,7 @@ public class ImmutableNode<K, V> extends Node<K, V> { | |||
133 | } | 133 | } |
134 | 134 | ||
135 | @Override | 135 | @Override |
136 | public Node<K, V> putValue(K key, V value, OldValueBox<V> oldValue, ContinousHashProvider<? super K> hashProvider, V defaultValue, int hash, int depth) { | 136 | public Node<K, V> putValue(K key, V value, OldValueBox<V> oldValue, ContinuousHashProvider<? super K> hashProvider, V defaultValue, int hash, int depth) { |
137 | int selectedHashFragment = hashFragment(hash, shiftDepth(depth)); | 137 | int selectedHashFragment = hashFragment(hash, shiftDepth(depth)); |
138 | int bitPosition = 1 << selectedHashFragment; | 138 | int bitPosition = 1 << selectedHashFragment; |
139 | if ((dataMap & bitPosition) != 0) { | 139 | if ((dataMap & bitPosition) != 0) { |
@@ -145,7 +145,7 @@ public class ImmutableNode<K, V> extends Node<K, V> { | |||
145 | MutableNode<K, V> mutable = this.toMutable(); | 145 | MutableNode<K, V> mutable = this.toMutable(); |
146 | return mutable.removeEntry(selectedHashFragment, oldValue); | 146 | return mutable.removeEntry(selectedHashFragment, oldValue); |
147 | } else if (value == content[keyIndex + 1]) { | 147 | } else if (value == content[keyIndex + 1]) { |
148 | // dont change | 148 | // don't change |
149 | oldValue.setOldValue(value); | 149 | oldValue.setOldValue(value); |
150 | return this; | 150 | return this; |
151 | } else { | 151 | } else { |
@@ -155,7 +155,7 @@ public class ImmutableNode<K, V> extends Node<K, V> { | |||
155 | } | 155 | } |
156 | } else { | 156 | } else { |
157 | if (value == defaultValue) { | 157 | if (value == defaultValue) { |
158 | // dont change | 158 | // don't change |
159 | oldValue.setOldValue(defaultValue); | 159 | oldValue.setOldValue(defaultValue); |
160 | return this; | 160 | return this; |
161 | } else { | 161 | } else { |
@@ -339,7 +339,7 @@ public class ImmutableNode<K, V> extends Node<K, V> { | |||
339 | } | 339 | } |
340 | 340 | ||
341 | @Override | 341 | @Override |
342 | public void checkIntegrity(ContinousHashProvider<? super K> hashProvider, V defaultValue, int depth) { | 342 | public void checkIntegrity(ContinuousHashProvider<? super K> hashProvider, V defaultValue, int depth) { |
343 | if (depth > 0) { | 343 | if (depth > 0) { |
344 | boolean orphaned = Integer.bitCount(dataMap) == 1 && nodeMap == 0; | 344 | boolean orphaned = Integer.bitCount(dataMap) == 1 && nodeMap == 0; |
345 | if (orphaned) { | 345 | if (orphaned) { |
diff --git a/subprojects/store/src/main/java/tools/refinery/store/map/internal/InOrderMapCursor.java b/subprojects/store/src/main/java/tools/refinery/store/map/internal/state/InOrderMapCursor.java index cb3f366f..7cc91004 100644 --- a/subprojects/store/src/main/java/tools/refinery/store/map/internal/InOrderMapCursor.java +++ b/subprojects/store/src/main/java/tools/refinery/store/map/internal/state/InOrderMapCursor.java | |||
@@ -1,9 +1,9 @@ | |||
1 | /* | 1 | /* |
2 | * SPDX-FileCopyrightText: 2021-2023 The Refinery Authors <https://refinery.tools/> | 2 | * SPDX-FileCopyrightText: 2023 The Refinery Authors <https://refinery.tools/> |
3 | * | 3 | * |
4 | * SPDX-License-Identifier: EPL-2.0 | 4 | * SPDX-License-Identifier: EPL-2.0 |
5 | */ | 5 | */ |
6 | package tools.refinery.store.map.internal; | 6 | package tools.refinery.store.map.internal.state; |
7 | 7 | ||
8 | import tools.refinery.store.map.AnyVersionedMap; | 8 | import tools.refinery.store.map.AnyVersionedMap; |
9 | import tools.refinery.store.map.ContentHashCode; | 9 | import tools.refinery.store.map.ContentHashCode; |
@@ -29,7 +29,7 @@ public class InOrderMapCursor<K, V> implements Cursor<K, V> { | |||
29 | final VersionedMap<K, V> map; | 29 | final VersionedMap<K, V> map; |
30 | final int creationHash; | 30 | final int creationHash; |
31 | 31 | ||
32 | public InOrderMapCursor(VersionedMapImpl<K, V> map) { | 32 | public InOrderMapCursor(VersionedMapStateImpl<K, V> map) { |
33 | // Initializing tree stack | 33 | // Initializing tree stack |
34 | super(); | 34 | super(); |
35 | this.nodeStack = new ArrayDeque<>(); | 35 | this.nodeStack = new ArrayDeque<>(); |
diff --git a/subprojects/store/src/main/java/tools/refinery/store/map/internal/MapCursor.java b/subprojects/store/src/main/java/tools/refinery/store/map/internal/state/MapCursor.java index d42519b2..0db50d04 100644 --- a/subprojects/store/src/main/java/tools/refinery/store/map/internal/MapCursor.java +++ b/subprojects/store/src/main/java/tools/refinery/store/map/internal/state/MapCursor.java | |||
@@ -1,9 +1,9 @@ | |||
1 | /* | 1 | /* |
2 | * SPDX-FileCopyrightText: 2021-2023 The Refinery Authors <https://refinery.tools/> | 2 | * SPDX-FileCopyrightText: 2023 The Refinery Authors <https://refinery.tools/> |
3 | * | 3 | * |
4 | * SPDX-License-Identifier: EPL-2.0 | 4 | * SPDX-License-Identifier: EPL-2.0 |
5 | */ | 5 | */ |
6 | package tools.refinery.store.map.internal; | 6 | package tools.refinery.store.map.internal.state; |
7 | 7 | ||
8 | import tools.refinery.store.map.AnyVersionedMap; | 8 | import tools.refinery.store.map.AnyVersionedMap; |
9 | import tools.refinery.store.map.ContentHashCode; | 9 | import tools.refinery.store.map.ContentHashCode; |
diff --git a/subprojects/store/src/main/java/tools/refinery/store/map/internal/MapDiffCursor.java b/subprojects/store/src/main/java/tools/refinery/store/map/internal/state/MapDiffCursor.java index fb1d5d2b..083bf8cf 100644 --- a/subprojects/store/src/main/java/tools/refinery/store/map/internal/MapDiffCursor.java +++ b/subprojects/store/src/main/java/tools/refinery/store/map/internal/state/MapDiffCursor.java | |||
@@ -1,9 +1,9 @@ | |||
1 | /* | 1 | /* |
2 | * SPDX-FileCopyrightText: 2021-2023 The Refinery Authors <https://refinery.tools/> | 2 | * SPDX-FileCopyrightText: 2023 The Refinery Authors <https://refinery.tools/> |
3 | * | 3 | * |
4 | * SPDX-License-Identifier: EPL-2.0 | 4 | * SPDX-License-Identifier: EPL-2.0 |
5 | */ | 5 | */ |
6 | package tools.refinery.store.map.internal; | 6 | package tools.refinery.store.map.internal.state; |
7 | 7 | ||
8 | import tools.refinery.store.map.AnyVersionedMap; | 8 | import tools.refinery.store.map.AnyVersionedMap; |
9 | import tools.refinery.store.map.Cursor; | 9 | import tools.refinery.store.map.Cursor; |
diff --git a/subprojects/store/src/main/java/tools/refinery/store/map/internal/MutableNode.java b/subprojects/store/src/main/java/tools/refinery/store/map/internal/state/MutableNode.java index bb85deb9..408ed62c 100644 --- a/subprojects/store/src/main/java/tools/refinery/store/map/internal/MutableNode.java +++ b/subprojects/store/src/main/java/tools/refinery/store/map/internal/state/MutableNode.java | |||
@@ -1,11 +1,11 @@ | |||
1 | /* | 1 | /* |
2 | * SPDX-FileCopyrightText: 2021-2023 The Refinery Authors <https://refinery.tools/> | 2 | * SPDX-FileCopyrightText: 2023 The Refinery Authors <https://refinery.tools/> |
3 | * | 3 | * |
4 | * SPDX-License-Identifier: EPL-2.0 | 4 | * SPDX-License-Identifier: EPL-2.0 |
5 | */ | 5 | */ |
6 | package tools.refinery.store.map.internal; | 6 | package tools.refinery.store.map.internal.state; |
7 | 7 | ||
8 | import tools.refinery.store.map.ContinousHashProvider; | 8 | import tools.refinery.store.map.ContinuousHashProvider; |
9 | 9 | ||
10 | import java.util.Arrays; | 10 | import java.util.Arrays; |
11 | import java.util.Map; | 11 | import java.util.Map; |
@@ -20,7 +20,7 @@ public class MutableNode<K, V> extends Node<K, V> { | |||
20 | invalidateHash(); | 20 | invalidateHash(); |
21 | } | 21 | } |
22 | 22 | ||
23 | public static <K, V> MutableNode<K, V> initialize(K key, V value, ContinousHashProvider<? super K> hashProvider, V defaultValue) { | 23 | public static <K, V> MutableNode<K, V> initialize(K key, V value, ContinuousHashProvider<? super K> hashProvider, V defaultValue) { |
24 | if (value == defaultValue) { | 24 | if (value == defaultValue) { |
25 | return null; | 25 | return null; |
26 | } else { | 26 | } else { |
@@ -58,7 +58,7 @@ public class MutableNode<K, V> extends Node<K, V> { | |||
58 | } | 58 | } |
59 | 59 | ||
60 | @Override | 60 | @Override |
61 | public V getValue(K key, ContinousHashProvider<? super K> hashProvider, V defaultValue, int hash, int depth) { | 61 | public V getValue(K key, ContinuousHashProvider<? super K> hashProvider, V defaultValue, int hash, int depth) { |
62 | int selectedHashFragment = hashFragment(hash, shiftDepth(depth)); | 62 | int selectedHashFragment = hashFragment(hash, shiftDepth(depth)); |
63 | @SuppressWarnings("unchecked") K keyCandidate = (K) this.content[2 * selectedHashFragment]; | 63 | @SuppressWarnings("unchecked") K keyCandidate = (K) this.content[2 * selectedHashFragment]; |
64 | if (keyCandidate != null) { | 64 | if (keyCandidate != null) { |
@@ -81,7 +81,7 @@ public class MutableNode<K, V> extends Node<K, V> { | |||
81 | } | 81 | } |
82 | 82 | ||
83 | @Override | 83 | @Override |
84 | public Node<K, V> putValue(K key, V value, OldValueBox<V> oldValueBox, ContinousHashProvider<? super K> hashProvider, V defaultValue, int hash, int depth) { | 84 | public Node<K, V> putValue(K key, V value, OldValueBox<V> oldValueBox, ContinuousHashProvider<? super K> hashProvider, V defaultValue, int hash, int depth) { |
85 | int selectedHashFragment = hashFragment(hash, shiftDepth(depth)); | 85 | int selectedHashFragment = hashFragment(hash, shiftDepth(depth)); |
86 | @SuppressWarnings("unchecked") K keyCandidate = (K) content[2 * selectedHashFragment]; | 86 | @SuppressWarnings("unchecked") K keyCandidate = (K) content[2 * selectedHashFragment]; |
87 | if (keyCandidate != null) { | 87 | if (keyCandidate != null) { |
@@ -217,7 +217,7 @@ public class MutableNode<K, V> extends Node<K, V> { | |||
217 | } | 217 | } |
218 | 218 | ||
219 | @SuppressWarnings("unchecked") | 219 | @SuppressWarnings("unchecked") |
220 | private Node<K, V> moveDownAndSplit(ContinousHashProvider<? super K> hashProvider, K newKey, V newValue, K previousKey, int hashOfNewKey, int depth, int selectedHashFragmentOfCurrentDepth) { | 220 | private Node<K, V> moveDownAndSplit(ContinuousHashProvider<? super K> hashProvider, K newKey, V newValue, K previousKey, int hashOfNewKey, int depth, int selectedHashFragmentOfCurrentDepth) { |
221 | V previousValue = (V) content[2 * selectedHashFragmentOfCurrentDepth + 1]; | 221 | V previousValue = (V) content[2 * selectedHashFragmentOfCurrentDepth + 1]; |
222 | 222 | ||
223 | MutableNode<K, V> newSubNode = newNodeWithTwoEntries(hashProvider, previousKey, previousValue, hashProvider.getHash(previousKey, hashDepth(depth)), newKey, newValue, hashOfNewKey, incrementDepth(depth)); | 223 | MutableNode<K, V> newSubNode = newNodeWithTwoEntries(hashProvider, previousKey, previousValue, hashProvider.getHash(previousKey, hashDepth(depth)), newKey, newValue, hashOfNewKey, incrementDepth(depth)); |
@@ -230,7 +230,7 @@ public class MutableNode<K, V> extends Node<K, V> { | |||
230 | 230 | ||
231 | // Pass everything as parameters for performance. | 231 | // Pass everything as parameters for performance. |
232 | @SuppressWarnings("squid:S107") | 232 | @SuppressWarnings("squid:S107") |
233 | private MutableNode<K, V> newNodeWithTwoEntries(ContinousHashProvider<? super K> hashProvider, K key1, V value1, int oldHash1, K key2, V value2, int oldHash2, int newDepth) { | 233 | private MutableNode<K, V> newNodeWithTwoEntries(ContinuousHashProvider<? super K> hashProvider, K key1, V value1, int oldHash1, K key2, V value2, int oldHash2, int newDepth) { |
234 | int newHash1 = newHash(hashProvider, key1, oldHash1, newDepth); | 234 | int newHash1 = newHash(hashProvider, key1, oldHash1, newDepth); |
235 | int newHash2 = newHash(hashProvider, key2, oldHash2, newDepth); | 235 | int newHash2 = newHash(hashProvider, key2, oldHash2, newDepth); |
236 | int newFragment1 = hashFragment(newHash1, shiftDepth(newDepth)); | 236 | int newFragment1 = hashFragment(newHash1, shiftDepth(newDepth)); |
@@ -418,7 +418,7 @@ public class MutableNode<K, V> extends Node<K, V> { | |||
418 | } | 418 | } |
419 | 419 | ||
420 | @Override | 420 | @Override |
421 | public void checkIntegrity(ContinousHashProvider<? super K> hashProvider, V defaultValue, int depth) { | 421 | public void checkIntegrity(ContinuousHashProvider<? super K> hashProvider, V defaultValue, int depth) { |
422 | // check for orphan nodes | 422 | // check for orphan nodes |
423 | if (depth > 0) { | 423 | if (depth > 0) { |
424 | int orphaned = isOrphaned(); | 424 | int orphaned = isOrphaned(); |
diff --git a/subprojects/store/src/main/java/tools/refinery/store/map/internal/Node.java b/subprojects/store/src/main/java/tools/refinery/store/map/internal/state/Node.java index 4b44f760..0ecf2712 100644 --- a/subprojects/store/src/main/java/tools/refinery/store/map/internal/Node.java +++ b/subprojects/store/src/main/java/tools/refinery/store/map/internal/state/Node.java | |||
@@ -1,13 +1,13 @@ | |||
1 | /* | 1 | /* |
2 | * SPDX-FileCopyrightText: 2021-2023 The Refinery Authors <https://refinery.tools/> | 2 | * SPDX-FileCopyrightText: 2023 The Refinery Authors <https://refinery.tools/> |
3 | * | 3 | * |
4 | * SPDX-License-Identifier: EPL-2.0 | 4 | * SPDX-License-Identifier: EPL-2.0 |
5 | */ | 5 | */ |
6 | package tools.refinery.store.map.internal; | 6 | package tools.refinery.store.map.internal.state; |
7 | 7 | ||
8 | import java.util.Map; | 8 | import java.util.Map; |
9 | 9 | ||
10 | import tools.refinery.store.map.ContinousHashProvider; | 10 | import tools.refinery.store.map.ContinuousHashProvider; |
11 | 11 | ||
12 | public abstract class Node<K, V> { | 12 | public abstract class Node<K, V> { |
13 | public static final int BRANCHING_FACTOR_BITS = 5; | 13 | public static final int BRANCHING_FACTOR_BITS = 5; |
@@ -77,14 +77,14 @@ public abstract class Node<K, V> { | |||
77 | * @param depth The depth. | 77 | * @param depth The depth. |
78 | * @return The new hash code. | 78 | * @return The new hash code. |
79 | */ | 79 | */ |
80 | protected int newHash(final ContinousHashProvider<? super K> hashProvider, K key, int hash, int depth) { | 80 | protected int newHash(final ContinuousHashProvider<? super K> hashProvider, K key, int hash, int depth) { |
81 | final int shiftDepth = shiftDepth(depth); | 81 | final int shiftDepth = shiftDepth(depth); |
82 | if (shiftDepth == 0) { | 82 | if (shiftDepth == 0) { |
83 | final int hashDepth = hashDepth(depth); | 83 | final int hashDepth = hashDepth(depth); |
84 | if (hashDepth >= ContinousHashProvider.MAX_PRACTICAL_DEPTH) { | 84 | if (hashDepth >= ContinuousHashProvider.MAX_PRACTICAL_DEPTH) { |
85 | throw new IllegalArgumentException( | 85 | throw new IllegalArgumentException( |
86 | "Key " + key + " have the clashing hashcode over the practical depth limitation (" | 86 | "Key " + key + " have the clashing hashcode over the practical depth limitation (" |
87 | + ContinousHashProvider.MAX_PRACTICAL_DEPTH + ")!"); | 87 | + ContinuousHashProvider.MAX_PRACTICAL_DEPTH + ")!"); |
88 | } | 88 | } |
89 | return hashProvider.getHash(key, hashDepth); | 89 | return hashProvider.getHash(key, hashDepth); |
90 | } else { | 90 | } else { |
@@ -92,11 +92,11 @@ public abstract class Node<K, V> { | |||
92 | } | 92 | } |
93 | } | 93 | } |
94 | 94 | ||
95 | public abstract V getValue(K key, ContinousHashProvider<? super K> hashProvider, V defaultValue, int hash, | 95 | public abstract V getValue(K key, ContinuousHashProvider<? super K> hashProvider, V defaultValue, int hash, |
96 | int depth); | 96 | int depth); |
97 | 97 | ||
98 | public abstract Node<K, V> putValue(K key, V value, OldValueBox<V> old, | 98 | public abstract Node<K, V> putValue(K key, V value, OldValueBox<V> old, |
99 | ContinousHashProvider<? super K> hashProvider, V defaultValue, int hash, int depth); | 99 | ContinuousHashProvider<? super K> hashProvider, V defaultValue, int hash, int depth); |
100 | 100 | ||
101 | public abstract long getSize(); | 101 | public abstract long getSize(); |
102 | 102 | ||
@@ -126,6 +126,6 @@ public abstract class Node<K, V> { | |||
126 | return stringBuilder.toString(); | 126 | return stringBuilder.toString(); |
127 | } | 127 | } |
128 | 128 | ||
129 | public void checkIntegrity(ContinousHashProvider<? super K> hashProvider, V defaultValue, int depth) { | 129 | public void checkIntegrity(ContinuousHashProvider<? super K> hashProvider, V defaultValue, int depth) { |
130 | } | 130 | } |
131 | } | 131 | } |
diff --git a/subprojects/store/src/main/java/tools/refinery/store/map/internal/OldValueBox.java b/subprojects/store/src/main/java/tools/refinery/store/map/internal/state/OldValueBox.java index 354af51d..1b0a4b0c 100644 --- a/subprojects/store/src/main/java/tools/refinery/store/map/internal/OldValueBox.java +++ b/subprojects/store/src/main/java/tools/refinery/store/map/internal/state/OldValueBox.java | |||
@@ -1,9 +1,9 @@ | |||
1 | /* | 1 | /* |
2 | * SPDX-FileCopyrightText: 2021-2023 The Refinery Authors <https://refinery.tools/> | 2 | * SPDX-FileCopyrightText: 2023 The Refinery Authors <https://refinery.tools/> |
3 | * | 3 | * |
4 | * SPDX-License-Identifier: EPL-2.0 | 4 | * SPDX-License-Identifier: EPL-2.0 |
5 | */ | 5 | */ |
6 | package tools.refinery.store.map.internal; | 6 | package tools.refinery.store.map.internal.state; |
7 | 7 | ||
8 | public class OldValueBox<V>{ | 8 | public class OldValueBox<V>{ |
9 | V oldValue; | 9 | V oldValue; |
@@ -20,5 +20,5 @@ public class OldValueBox<V>{ | |||
20 | this.oldValue = ouldValue; | 20 | this.oldValue = ouldValue; |
21 | isSet = true; | 21 | isSet = true; |
22 | } | 22 | } |
23 | 23 | ||
24 | } | 24 | } |
diff --git a/subprojects/store/src/main/java/tools/refinery/store/map/internal/StateBasedVersionedMapStoreFactory.java b/subprojects/store/src/main/java/tools/refinery/store/map/internal/state/StateBasedVersionedMapStoreFactory.java index 1c3ab27b..9409ace0 100644 --- a/subprojects/store/src/main/java/tools/refinery/store/map/internal/StateBasedVersionedMapStoreFactory.java +++ b/subprojects/store/src/main/java/tools/refinery/store/map/internal/state/StateBasedVersionedMapStoreFactory.java | |||
@@ -1,9 +1,9 @@ | |||
1 | /* | 1 | /* |
2 | * SPDX-FileCopyrightText: 2021-2023 The Refinery Authors <https://refinery.tools/> | 2 | * SPDX-FileCopyrightText: 2023 The Refinery Authors <https://refinery.tools/> |
3 | * | 3 | * |
4 | * SPDX-License-Identifier: EPL-2.0 | 4 | * SPDX-License-Identifier: EPL-2.0 |
5 | */ | 5 | */ |
6 | package tools.refinery.store.map.internal; | 6 | package tools.refinery.store.map.internal.state; |
7 | 7 | ||
8 | import tools.refinery.store.map.*; | 8 | import tools.refinery.store.map.*; |
9 | 9 | ||
@@ -11,14 +11,14 @@ import java.util.List; | |||
11 | 11 | ||
12 | public class StateBasedVersionedMapStoreFactory<K, V> implements VersionedMapStoreFactory<K, V> { | 12 | public class StateBasedVersionedMapStoreFactory<K, V> implements VersionedMapStoreFactory<K, V> { |
13 | private final V defaultValue; | 13 | private final V defaultValue; |
14 | private final ContinousHashProvider<K> continousHashProvider; | 14 | private final ContinuousHashProvider<K> continuousHashProvider; |
15 | private final VersionedMapStoreConfiguration config; | 15 | private final VersionedMapStoreStateConfiguration config; |
16 | 16 | ||
17 | public StateBasedVersionedMapStoreFactory(V defaultValue, Boolean transformToImmutable, VersionedMapStoreFactoryBuilder.SharingStrategy sharingStrategy, ContinousHashProvider<K> continousHashProvider) { | 17 | public StateBasedVersionedMapStoreFactory(V defaultValue, Boolean transformToImmutable, VersionedMapStoreFactoryBuilder.SharingStrategy sharingStrategy, ContinuousHashProvider<K> continuousHashProvider) { |
18 | this.defaultValue = defaultValue; | 18 | this.defaultValue = defaultValue; |
19 | this.continousHashProvider = continousHashProvider; | 19 | this.continuousHashProvider = continuousHashProvider; |
20 | 20 | ||
21 | this.config = new VersionedMapStoreConfiguration( | 21 | this.config = new VersionedMapStoreStateConfiguration( |
22 | transformToImmutable, | 22 | transformToImmutable, |
23 | sharingStrategy == VersionedMapStoreFactoryBuilder.SharingStrategy.SHARED_NODE_CACHE || sharingStrategy == VersionedMapStoreFactoryBuilder.SharingStrategy.SHARED_NODE_CACHE_IN_GROUP, | 23 | sharingStrategy == VersionedMapStoreFactoryBuilder.SharingStrategy.SHARED_NODE_CACHE || sharingStrategy == VersionedMapStoreFactoryBuilder.SharingStrategy.SHARED_NODE_CACHE_IN_GROUP, |
24 | sharingStrategy == VersionedMapStoreFactoryBuilder.SharingStrategy.SHARED_NODE_CACHE_IN_GROUP); | 24 | sharingStrategy == VersionedMapStoreFactoryBuilder.SharingStrategy.SHARED_NODE_CACHE_IN_GROUP); |
@@ -26,13 +26,13 @@ public class StateBasedVersionedMapStoreFactory<K, V> implements VersionedMapSto | |||
26 | 26 | ||
27 | @Override | 27 | @Override |
28 | public VersionedMapStore<K, V> createOne() { | 28 | public VersionedMapStore<K, V> createOne() { |
29 | return new VersionedMapStoreImpl<>(continousHashProvider, defaultValue, config); | 29 | return new VersionedMapStoreStateImpl<>(continuousHashProvider, defaultValue, config); |
30 | 30 | ||
31 | } | 31 | } |
32 | 32 | ||
33 | @Override | 33 | @Override |
34 | public List<VersionedMapStore<K, V>> createGroup(int amount) { | 34 | public List<VersionedMapStore<K, V>> createGroup(int amount) { |
35 | return VersionedMapStoreImpl.createSharedVersionedMapStores(amount, continousHashProvider, defaultValue, | 35 | return VersionedMapStoreStateImpl.createSharedVersionedMapStores(amount, continuousHashProvider, defaultValue, |
36 | config); | 36 | config); |
37 | } | 37 | } |
38 | } | 38 | } |
diff --git a/subprojects/store/src/main/java/tools/refinery/store/map/internal/VersionedMapImpl.java b/subprojects/store/src/main/java/tools/refinery/store/map/internal/state/VersionedMapStateImpl.java index c107f7e0..817fc70b 100644 --- a/subprojects/store/src/main/java/tools/refinery/store/map/internal/VersionedMapImpl.java +++ b/subprojects/store/src/main/java/tools/refinery/store/map/internal/state/VersionedMapStateImpl.java | |||
@@ -1,9 +1,9 @@ | |||
1 | /* | 1 | /* |
2 | * SPDX-FileCopyrightText: 2021-2023 The Refinery Authors <https://refinery.tools/> | 2 | * SPDX-FileCopyrightText: 2023 The Refinery Authors <https://refinery.tools/> |
3 | * | 3 | * |
4 | * SPDX-License-Identifier: EPL-2.0 | 4 | * SPDX-License-Identifier: EPL-2.0 |
5 | */ | 5 | */ |
6 | package tools.refinery.store.map.internal; | 6 | package tools.refinery.store.map.internal.state; |
7 | 7 | ||
8 | import tools.refinery.store.map.*; | 8 | import tools.refinery.store.map.*; |
9 | 9 | ||
@@ -19,18 +19,18 @@ import java.util.Objects; | |||
19 | * @param <V> | 19 | * @param <V> |
20 | * @author Oszkar Semerath | 20 | * @author Oszkar Semerath |
21 | */ | 21 | */ |
22 | public class VersionedMapImpl<K, V> implements VersionedMap<K, V> { | 22 | public class VersionedMapStateImpl<K, V> implements VersionedMap<K, V> { |
23 | protected final VersionedMapStoreImpl<K, V> store; | 23 | protected final VersionedMapStoreStateImpl<K, V> store; |
24 | 24 | ||
25 | protected final ContinousHashProvider<K> hashProvider; | 25 | protected final ContinuousHashProvider<K> hashProvider; |
26 | protected final V defaultValue; | 26 | protected final V defaultValue; |
27 | protected Node<K, V> root; | 27 | protected Node<K, V> root; |
28 | 28 | ||
29 | private final OldValueBox<V> oldValueBox = new OldValueBox<>(); | 29 | private final OldValueBox<V> oldValueBox = new OldValueBox<>(); |
30 | 30 | ||
31 | public VersionedMapImpl( | 31 | public VersionedMapStateImpl( |
32 | VersionedMapStoreImpl<K, V> store, | 32 | VersionedMapStoreStateImpl<K, V> store, |
33 | ContinousHashProvider<K> hashProvider, | 33 | ContinuousHashProvider<K> hashProvider, |
34 | V defaultValue) { | 34 | V defaultValue) { |
35 | this.store = store; | 35 | this.store = store; |
36 | this.hashProvider = hashProvider; | 36 | this.hashProvider = hashProvider; |
@@ -38,9 +38,9 @@ public class VersionedMapImpl<K, V> implements VersionedMap<K, V> { | |||
38 | this.root = null; | 38 | this.root = null; |
39 | } | 39 | } |
40 | 40 | ||
41 | public VersionedMapImpl( | 41 | public VersionedMapStateImpl( |
42 | VersionedMapStoreImpl<K, V> store, | 42 | VersionedMapStoreStateImpl<K, V> store, |
43 | ContinousHashProvider<K> hashProvider, | 43 | ContinuousHashProvider<K> hashProvider, |
44 | V defaultValue, Node<K, V> data) { | 44 | V defaultValue, Node<K, V> data) { |
45 | this.store = store; | 45 | this.store = store; |
46 | this.hashProvider = hashProvider; | 46 | this.hashProvider = hashProvider; |
@@ -53,7 +53,7 @@ public class VersionedMapImpl<K, V> implements VersionedMap<K, V> { | |||
53 | return defaultValue; | 53 | return defaultValue; |
54 | } | 54 | } |
55 | 55 | ||
56 | public ContinousHashProvider<K> getHashProvider() { | 56 | public ContinuousHashProvider<K> getHashProvider() { |
57 | return hashProvider; | 57 | return hashProvider; |
58 | } | 58 | } |
59 | 59 | ||
@@ -117,7 +117,7 @@ public class VersionedMapImpl<K, V> implements VersionedMap<K, V> { | |||
117 | @Override | 117 | @Override |
118 | public DiffCursor<K, V> getDiffCursor(long toVersion) { | 118 | public DiffCursor<K, V> getDiffCursor(long toVersion) { |
119 | InOrderMapCursor<K, V> fromCursor = new InOrderMapCursor<>(this); | 119 | InOrderMapCursor<K, V> fromCursor = new InOrderMapCursor<>(this); |
120 | VersionedMapImpl<K, V> toMap = (VersionedMapImpl<K, V>) this.store.createMap(toVersion); | 120 | VersionedMapStateImpl<K, V> toMap = (VersionedMapStateImpl<K, V>) this.store.createMap(toVersion); |
121 | InOrderMapCursor<K, V> toCursor = new InOrderMapCursor<>(toMap); | 121 | InOrderMapCursor<K, V> toCursor = new InOrderMapCursor<>(toMap); |
122 | return new MapDiffCursor<>(this.defaultValue, fromCursor, toCursor); | 122 | return new MapDiffCursor<>(this.defaultValue, fromCursor, toCursor); |
123 | } | 123 | } |
@@ -166,6 +166,6 @@ public class VersionedMapImpl<K, V> implements VersionedMap<K, V> { | |||
166 | 166 | ||
167 | @Override | 167 | @Override |
168 | public boolean contentEquals(AnyVersionedMap other) { | 168 | public boolean contentEquals(AnyVersionedMap other) { |
169 | return other instanceof VersionedMapImpl<?, ?> otherImpl && Objects.equals(root, otherImpl.root); | 169 | return other instanceof VersionedMapStateImpl<?, ?> otherImpl && Objects.equals(root, otherImpl.root); |
170 | } | 170 | } |
171 | } | 171 | } |
diff --git a/subprojects/store/src/main/java/tools/refinery/store/map/VersionedMapStoreConfiguration.java b/subprojects/store/src/main/java/tools/refinery/store/map/internal/state/VersionedMapStoreStateConfiguration.java index b00cd961..45f30cc7 100644 --- a/subprojects/store/src/main/java/tools/refinery/store/map/VersionedMapStoreConfiguration.java +++ b/subprojects/store/src/main/java/tools/refinery/store/map/internal/state/VersionedMapStoreStateConfiguration.java | |||
@@ -1,17 +1,20 @@ | |||
1 | /* | 1 | /* |
2 | * SPDX-FileCopyrightText: 2021-2023 The Refinery Authors <https://refinery.tools/> | 2 | * SPDX-FileCopyrightText: 2023 The Refinery Authors <https://refinery.tools/> |
3 | * | 3 | * |
4 | * SPDX-License-Identifier: EPL-2.0 | 4 | * SPDX-License-Identifier: EPL-2.0 |
5 | */ | 5 | */ |
6 | package tools.refinery.store.map; | 6 | package tools.refinery.store.map.internal.state; |
7 | 7 | ||
8 | public class VersionedMapStoreConfiguration { | 8 | import tools.refinery.store.map.ContinuousHashProvider; |
9 | import tools.refinery.store.map.VersionedMapStore; | ||
9 | 10 | ||
10 | public VersionedMapStoreConfiguration() { | 11 | public class VersionedMapStoreStateConfiguration { |
12 | |||
13 | public VersionedMapStoreStateConfiguration() { | ||
11 | 14 | ||
12 | } | 15 | } |
13 | public VersionedMapStoreConfiguration(boolean immutableWhenCommitting, boolean sharedNodeCacheInStore, | 16 | public VersionedMapStoreStateConfiguration(boolean immutableWhenCommitting, boolean sharedNodeCacheInStore, |
14 | boolean sharedNodeCacheInStoreGroups) { | 17 | boolean sharedNodeCacheInStoreGroups) { |
15 | super(); | 18 | super(); |
16 | this.immutableWhenCommitting = immutableWhenCommitting; | 19 | this.immutableWhenCommitting = immutableWhenCommitting; |
17 | this.sharedNodeCacheInStore = sharedNodeCacheInStore; | 20 | this.sharedNodeCacheInStore = sharedNodeCacheInStore; |
@@ -42,8 +45,8 @@ public class VersionedMapStoreConfiguration { | |||
42 | 45 | ||
43 | /** | 46 | /** |
44 | * If true, all sub-nodes are cached within a group of | 47 | * If true, all sub-nodes are cached within a group of |
45 | * {@link VersionedMapStoreImpl#createSharedVersionedMapStores(int, ContinousHashProvider, Object, VersionedMapStoreConfiguration)}. | 48 | * {@link VersionedMapStoreStateImpl#createSharedVersionedMapStores(int, ContinuousHashProvider, Object, VersionedMapStoreStateConfiguration)}. |
46 | * If {@link VersionedMapStoreConfiguration#sharedNodeCacheInStore} is | 49 | * If {@link VersionedMapStoreStateConfiguration#sharedNodeCacheInStore} is |
47 | * <code>false</code>, then it has currently no impact. | 50 | * <code>false</code>, then it has currently no impact. |
48 | */ | 51 | */ |
49 | private boolean sharedNodeCacheInStoreGroups = true; | 52 | private boolean sharedNodeCacheInStoreGroups = true; |
diff --git a/subprojects/store/src/main/java/tools/refinery/store/map/VersionedMapStoreImpl.java b/subprojects/store/src/main/java/tools/refinery/store/map/internal/state/VersionedMapStoreStateImpl.java index a934d59e..0651772a 100644 --- a/subprojects/store/src/main/java/tools/refinery/store/map/VersionedMapStoreImpl.java +++ b/subprojects/store/src/main/java/tools/refinery/store/map/internal/state/VersionedMapStoreStateImpl.java | |||
@@ -1,20 +1,20 @@ | |||
1 | /* | 1 | /* |
2 | * SPDX-FileCopyrightText: 2021-2023 The Refinery Authors <https://refinery.tools/> | 2 | * SPDX-FileCopyrightText: 2023 The Refinery Authors <https://refinery.tools/> |
3 | * | 3 | * |
4 | * SPDX-License-Identifier: EPL-2.0 | 4 | * SPDX-License-Identifier: EPL-2.0 |
5 | */ | 5 | */ |
6 | package tools.refinery.store.map; | 6 | package tools.refinery.store.map.internal.state; |
7 | 7 | ||
8 | import tools.refinery.store.map.internal.*; | 8 | import tools.refinery.store.map.*; |
9 | 9 | ||
10 | import java.util.*; | 10 | import java.util.*; |
11 | 11 | ||
12 | public class VersionedMapStoreImpl<K, V> implements VersionedMapStore<K, V> { | 12 | public class VersionedMapStoreStateImpl<K, V> implements VersionedMapStore<K, V> { |
13 | // Configuration | 13 | // Configuration |
14 | private final boolean immutableWhenCommitting; | 14 | private final boolean immutableWhenCommitting; |
15 | 15 | ||
16 | // Static data | 16 | // Static data |
17 | protected final ContinousHashProvider<K> hashProvider; | 17 | protected final ContinuousHashProvider<K> hashProvider; |
18 | protected final V defaultValue; | 18 | protected final V defaultValue; |
19 | 19 | ||
20 | // Dynamic data | 20 | // Dynamic data |
@@ -22,8 +22,8 @@ public class VersionedMapStoreImpl<K, V> implements VersionedMapStore<K, V> { | |||
22 | protected final Map<Node<K, V>, ImmutableNode<K, V>> nodeCache; | 22 | protected final Map<Node<K, V>, ImmutableNode<K, V>> nodeCache; |
23 | protected long nextID = 0; | 23 | protected long nextID = 0; |
24 | 24 | ||
25 | public VersionedMapStoreImpl(ContinousHashProvider<K> hashProvider, V defaultValue, | 25 | public VersionedMapStoreStateImpl(ContinuousHashProvider<K> hashProvider, V defaultValue, |
26 | VersionedMapStoreConfiguration config) { | 26 | VersionedMapStoreStateConfiguration config) { |
27 | this.immutableWhenCommitting = config.isImmutableWhenCommitting(); | 27 | this.immutableWhenCommitting = config.isImmutableWhenCommitting(); |
28 | this.hashProvider = hashProvider; | 28 | this.hashProvider = hashProvider; |
29 | this.defaultValue = defaultValue; | 29 | this.defaultValue = defaultValue; |
@@ -34,21 +34,21 @@ public class VersionedMapStoreImpl<K, V> implements VersionedMapStore<K, V> { | |||
34 | } | 34 | } |
35 | } | 35 | } |
36 | 36 | ||
37 | private VersionedMapStoreImpl(ContinousHashProvider<K> hashProvider, V defaultValue, | 37 | private VersionedMapStoreStateImpl(ContinuousHashProvider<K> hashProvider, V defaultValue, |
38 | Map<Node<K, V>, ImmutableNode<K, V>> nodeCache, VersionedMapStoreConfiguration config) { | 38 | Map<Node<K, V>, ImmutableNode<K, V>> nodeCache, VersionedMapStoreStateConfiguration config) { |
39 | this.immutableWhenCommitting = config.isImmutableWhenCommitting(); | 39 | this.immutableWhenCommitting = config.isImmutableWhenCommitting(); |
40 | this.hashProvider = hashProvider; | 40 | this.hashProvider = hashProvider; |
41 | this.defaultValue = defaultValue; | 41 | this.defaultValue = defaultValue; |
42 | this.nodeCache = nodeCache; | 42 | this.nodeCache = nodeCache; |
43 | } | 43 | } |
44 | 44 | ||
45 | public VersionedMapStoreImpl(ContinousHashProvider<K> hashProvider, V defaultValue) { | 45 | public VersionedMapStoreStateImpl(ContinuousHashProvider<K> hashProvider, V defaultValue) { |
46 | this(hashProvider, defaultValue, new VersionedMapStoreConfiguration()); | 46 | this(hashProvider, defaultValue, new VersionedMapStoreStateConfiguration()); |
47 | } | 47 | } |
48 | 48 | ||
49 | public static <K, V> List<VersionedMapStore<K, V>> createSharedVersionedMapStores(int amount, | 49 | public static <K, V> List<VersionedMapStore<K, V>> createSharedVersionedMapStores(int amount, |
50 | ContinousHashProvider<K> hashProvider, V defaultValue, | 50 | ContinuousHashProvider<K> hashProvider, V defaultValue, |
51 | VersionedMapStoreConfiguration config) { | 51 | VersionedMapStoreStateConfiguration config) { |
52 | List<VersionedMapStore<K, V>> result = new ArrayList<>(amount); | 52 | List<VersionedMapStore<K, V>> result = new ArrayList<>(amount); |
53 | if (config.isSharedNodeCacheInStoreGroups()) { | 53 | if (config.isSharedNodeCacheInStoreGroups()) { |
54 | Map<Node<K, V>, ImmutableNode<K, V>> nodeCache; | 54 | Map<Node<K, V>, ImmutableNode<K, V>> nodeCache; |
@@ -58,19 +58,19 @@ public class VersionedMapStoreImpl<K, V> implements VersionedMapStore<K, V> { | |||
58 | nodeCache = null; | 58 | nodeCache = null; |
59 | } | 59 | } |
60 | for (int i = 0; i < amount; i++) { | 60 | for (int i = 0; i < amount; i++) { |
61 | result.add(new VersionedMapStoreImpl<>(hashProvider, defaultValue, nodeCache, config)); | 61 | result.add(new VersionedMapStoreStateImpl<>(hashProvider, defaultValue, nodeCache, config)); |
62 | } | 62 | } |
63 | } else { | 63 | } else { |
64 | for (int i = 0; i < amount; i++) { | 64 | for (int i = 0; i < amount; i++) { |
65 | result.add(new VersionedMapStoreImpl<>(hashProvider, defaultValue, config)); | 65 | result.add(new VersionedMapStoreStateImpl<>(hashProvider, defaultValue, config)); |
66 | } | 66 | } |
67 | } | 67 | } |
68 | return result; | 68 | return result; |
69 | } | 69 | } |
70 | 70 | ||
71 | public static <K, V> List<VersionedMapStore<K, V>> createSharedVersionedMapStores(int amount, | 71 | public static <K, V> List<VersionedMapStore<K, V>> createSharedVersionedMapStores(int amount, |
72 | ContinousHashProvider<K> hashProvider, V defaultValue) { | 72 | ContinuousHashProvider<K> hashProvider, V defaultValue) { |
73 | return createSharedVersionedMapStores(amount, hashProvider, defaultValue, new VersionedMapStoreConfiguration()); | 73 | return createSharedVersionedMapStores(amount, hashProvider, defaultValue, new VersionedMapStoreStateConfiguration()); |
74 | } | 74 | } |
75 | 75 | ||
76 | @Override | 76 | @Override |
@@ -80,13 +80,13 @@ public class VersionedMapStoreImpl<K, V> implements VersionedMapStore<K, V> { | |||
80 | 80 | ||
81 | @Override | 81 | @Override |
82 | public VersionedMap<K, V> createMap() { | 82 | public VersionedMap<K, V> createMap() { |
83 | return new VersionedMapImpl<>(this, hashProvider, defaultValue); | 83 | return new VersionedMapStateImpl<>(this, hashProvider, defaultValue); |
84 | } | 84 | } |
85 | 85 | ||
86 | @Override | 86 | @Override |
87 | public VersionedMap<K, V> createMap(long state) { | 87 | public VersionedMap<K, V> createMap(long state) { |
88 | ImmutableNode<K, V> data = revert(state); | 88 | ImmutableNode<K, V> data = revert(state); |
89 | return new VersionedMapImpl<>(this, hashProvider, defaultValue, data); | 89 | return new VersionedMapStateImpl<>(this, hashProvider, defaultValue, data); |
90 | } | 90 | } |
91 | 91 | ||
92 | public synchronized ImmutableNode<K, V> revert(long state) { | 92 | public synchronized ImmutableNode<K, V> revert(long state) { |
@@ -100,7 +100,7 @@ public class VersionedMapStoreImpl<K, V> implements VersionedMapStore<K, V> { | |||
100 | } | 100 | } |
101 | } | 101 | } |
102 | 102 | ||
103 | public synchronized long commit(Node<K, V> data, VersionedMapImpl<K, V> mapToUpdateRoot) { | 103 | public synchronized long commit(Node<K, V> data, VersionedMapStateImpl<K, V> mapToUpdateRoot) { |
104 | ImmutableNode<K, V> immutable; | 104 | ImmutableNode<K, V> immutable; |
105 | if (data != null) { | 105 | if (data != null) { |
106 | immutable = data.toImmutable(this.nodeCache); | 106 | immutable = data.toImmutable(this.nodeCache); |
@@ -120,8 +120,8 @@ public class VersionedMapStoreImpl<K, V> implements VersionedMapStore<K, V> { | |||
120 | 120 | ||
121 | @Override | 121 | @Override |
122 | public DiffCursor<K, V> getDiffCursor(long fromState, long toState) { | 122 | public DiffCursor<K, V> getDiffCursor(long fromState, long toState) { |
123 | VersionedMapImpl<K, V> map1 = (VersionedMapImpl<K, V>) createMap(fromState); | 123 | VersionedMapStateImpl<K, V> map1 = (VersionedMapStateImpl<K, V>) createMap(fromState); |
124 | VersionedMapImpl<K, V> map2 = (VersionedMapImpl<K, V>) createMap(toState); | 124 | VersionedMapStateImpl<K, V> map2 = (VersionedMapStateImpl<K, V>) createMap(toState); |
125 | InOrderMapCursor<K, V> cursor1 = new InOrderMapCursor<>(map1); | 125 | InOrderMapCursor<K, V> cursor1 = new InOrderMapCursor<>(map1); |
126 | InOrderMapCursor<K, V> cursor2 = new InOrderMapCursor<>(map2); | 126 | InOrderMapCursor<K, V> cursor2 = new InOrderMapCursor<>(map2); |
127 | return new MapDiffCursor<>(this.defaultValue, cursor1, cursor2); | 127 | return new MapDiffCursor<>(this.defaultValue, cursor1, cursor2); |
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 fdd4425e..3c94541f 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 | |||
@@ -5,12 +5,12 @@ | |||
5 | */ | 5 | */ |
6 | package tools.refinery.store.model; | 6 | package tools.refinery.store.model; |
7 | 7 | ||
8 | import tools.refinery.store.map.ContinousHashProvider; | 8 | import tools.refinery.store.map.ContinuousHashProvider; |
9 | import tools.refinery.store.tuple.Tuple; | 9 | import tools.refinery.store.tuple.Tuple; |
10 | import tools.refinery.store.tuple.Tuple1; | 10 | import tools.refinery.store.tuple.Tuple1; |
11 | import tools.refinery.store.tuple.Tuple2; | 11 | import tools.refinery.store.tuple.Tuple2; |
12 | 12 | ||
13 | public class TupleHashProvider implements ContinousHashProvider<Tuple> { | 13 | public class TupleHashProvider implements ContinuousHashProvider<Tuple> { |
14 | protected static final int[] primes = new int[] { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, | 14 | protected static final int[] primes = new int[] { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, |
15 | 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, | 15 | 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, |
16 | 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, | 16 | 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, |
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 deleted file mode 100644 index 14116a90..00000000 --- a/subprojects/store/src/main/java/tools/refinery/store/model/TupleHashProviderBitMagic.java +++ /dev/null | |||
@@ -1,34 +0,0 @@ | |||
1 | /* | ||
2 | * SPDX-FileCopyrightText: 2021-2023 The Refinery Authors <https://refinery.tools/> | ||
3 | * | ||
4 | * SPDX-License-Identifier: EPL-2.0 | ||
5 | */ | ||
6 | package tools.refinery.store.model; | ||
7 | |||
8 | import tools.refinery.store.map.ContinousHashProvider; | ||
9 | import tools.refinery.store.tuple.Tuple; | ||
10 | |||
11 | public class TupleHashProviderBitMagic implements ContinousHashProvider<Tuple> { | ||
12 | |||
13 | @Override | ||
14 | public int getHash(Tuple key, int index) { | ||
15 | if(key.getSize() == 1) { | ||
16 | return key.get(0); | ||
17 | } | ||
18 | |||
19 | int result = 0; | ||
20 | final int startBitIndex = index*30; | ||
21 | final int finalBitIndex = startBitIndex+30; | ||
22 | final int arity = key.getSize(); | ||
23 | |||
24 | for(int i = startBitIndex; i<=finalBitIndex; i++) { | ||
25 | final int selectedKey = key.get(i%arity); | ||
26 | final int selectedPosition = 1<<(i/arity); | ||
27 | if((selectedKey&selectedPosition) != 0) { | ||
28 | result |= 1<<(i%30); | ||
29 | } | ||
30 | } | ||
31 | |||
32 | return result; | ||
33 | } | ||
34 | } | ||
diff --git a/subprojects/store/src/main/java/tools/refinery/store/model/internal/ModelStoreBuilderImpl.java b/subprojects/store/src/main/java/tools/refinery/store/model/internal/ModelStoreBuilderImpl.java index aafbe130..2cc7b19c 100644 --- a/subprojects/store/src/main/java/tools/refinery/store/model/internal/ModelStoreBuilderImpl.java +++ b/subprojects/store/src/main/java/tools/refinery/store/model/internal/ModelStoreBuilderImpl.java | |||
@@ -8,10 +8,10 @@ package tools.refinery.store.model.internal; | |||
8 | import tools.refinery.store.adapter.AdapterUtils; | 8 | import tools.refinery.store.adapter.AdapterUtils; |
9 | import tools.refinery.store.adapter.ModelAdapterBuilder; | 9 | import tools.refinery.store.adapter.ModelAdapterBuilder; |
10 | import tools.refinery.store.map.VersionedMapStore; | 10 | import tools.refinery.store.map.VersionedMapStore; |
11 | import tools.refinery.store.map.VersionedMapStoreImpl; | 11 | import tools.refinery.store.map.VersionedMapStoreFactory; |
12 | import tools.refinery.store.map.VersionedMapStoreFactoryBuilder; | ||
12 | import tools.refinery.store.model.ModelStore; | 13 | import tools.refinery.store.model.ModelStore; |
13 | import tools.refinery.store.model.ModelStoreBuilder; | 14 | import tools.refinery.store.model.ModelStoreBuilder; |
14 | import tools.refinery.store.model.TupleHashProvider; | ||
15 | import tools.refinery.store.representation.AnySymbol; | 15 | import tools.refinery.store.representation.AnySymbol; |
16 | import tools.refinery.store.representation.Symbol; | 16 | import tools.refinery.store.representation.Symbol; |
17 | import tools.refinery.store.tuple.Tuple; | 17 | import tools.refinery.store.tuple.Tuple; |
@@ -77,8 +77,12 @@ public class ModelStoreBuilderImpl implements ModelStoreBuilder { | |||
77 | private <T> void createStores(Map<AnySymbol, VersionedMapStore<Tuple, ?>> stores, | 77 | private <T> void createStores(Map<AnySymbol, VersionedMapStore<Tuple, ?>> stores, |
78 | SymbolEquivalenceClass<T> equivalenceClass, List<AnySymbol> symbols) { | 78 | SymbolEquivalenceClass<T> equivalenceClass, List<AnySymbol> symbols) { |
79 | int size = symbols.size(); | 79 | int size = symbols.size(); |
80 | var storeGroup = VersionedMapStoreImpl.createSharedVersionedMapStores(size, TupleHashProvider.INSTANCE, | 80 | VersionedMapStoreFactory<Tuple,T> mapFactory = VersionedMapStore |
81 | equivalenceClass.defaultValue()); | 81 | .<Tuple,T>builder() |
82 | .strategy(VersionedMapStoreFactoryBuilder.StoreStrategy.DELTA) | ||
83 | .defaultValue(equivalenceClass.defaultValue()) | ||
84 | .build(); | ||
85 | var storeGroup = mapFactory.createGroup(size); | ||
82 | for (int i = 0; i < size; i++) { | 86 | for (int i = 0; i < size; i++) { |
83 | stores.put(symbols.get(i), storeGroup.get(i)); | 87 | stores.put(symbols.get(i), storeGroup.get(i)); |
84 | } | 88 | } |
diff --git a/subprojects/store/src/test/java/tools/refinery/store/map/tests/InOrderCursorTest.java b/subprojects/store/src/test/java/tools/refinery/store/map/tests/InOrderCursorTest.java index 4ada4ea4..98756460 100644 --- a/subprojects/store/src/test/java/tools/refinery/store/map/tests/InOrderCursorTest.java +++ b/subprojects/store/src/test/java/tools/refinery/store/map/tests/InOrderCursorTest.java | |||
@@ -8,8 +8,8 @@ package tools.refinery.store.map.tests; | |||
8 | import org.junit.jupiter.api.Test; | 8 | import org.junit.jupiter.api.Test; |
9 | import tools.refinery.store.map.VersionedMapStore; | 9 | import tools.refinery.store.map.VersionedMapStore; |
10 | import tools.refinery.store.map.VersionedMapStoreFactoryBuilder; | 10 | import tools.refinery.store.map.VersionedMapStoreFactoryBuilder; |
11 | import tools.refinery.store.map.internal.InOrderMapCursor; | 11 | import tools.refinery.store.map.internal.state.InOrderMapCursor; |
12 | import tools.refinery.store.map.internal.VersionedMapImpl; | 12 | import tools.refinery.store.map.internal.state.VersionedMapStateImpl; |
13 | import tools.refinery.store.map.tests.utils.MapTestEnvironment; | 13 | import tools.refinery.store.map.tests.utils.MapTestEnvironment; |
14 | 14 | ||
15 | import static org.junit.jupiter.api.Assertions.*; | 15 | import static org.junit.jupiter.api.Assertions.*; |
@@ -26,7 +26,7 @@ class InOrderCursorTest { | |||
26 | .build() | 26 | .build() |
27 | .createOne(); | 27 | .createOne(); |
28 | 28 | ||
29 | VersionedMapImpl<Integer,String> map = (VersionedMapImpl<Integer,String>) store.createMap(); | 29 | VersionedMapStateImpl<Integer,String> map = (VersionedMapStateImpl<Integer,String>) store.createMap(); |
30 | checkMove(map,0); | 30 | checkMove(map,0); |
31 | 31 | ||
32 | map.put(1,"A"); | 32 | map.put(1,"A"); |
@@ -44,7 +44,7 @@ class InOrderCursorTest { | |||
44 | 44 | ||
45 | } | 45 | } |
46 | 46 | ||
47 | private void checkMove(VersionedMapImpl<Integer,String> map, int num) { | 47 | private void checkMove(VersionedMapStateImpl<Integer,String> map, int num) { |
48 | InOrderMapCursor<Integer,String> cursor = new InOrderMapCursor<>(map); | 48 | InOrderMapCursor<Integer,String> cursor = new InOrderMapCursor<>(map); |
49 | for(int i=0; i<num; i++) { | 49 | for(int i=0; i<num; i++) { |
50 | assertTrue(cursor.move()); | 50 | assertTrue(cursor.move()); |
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 2be49bd9..cc2e425c 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 | |||
@@ -7,7 +7,7 @@ package tools.refinery.store.map.tests; | |||
7 | 7 | ||
8 | import org.junit.jupiter.api.Test; | 8 | import org.junit.jupiter.api.Test; |
9 | import tools.refinery.store.map.VersionedMapStore; | 9 | import tools.refinery.store.map.VersionedMapStore; |
10 | import tools.refinery.store.map.VersionedMapStoreImpl; | 10 | import tools.refinery.store.map.internal.state.VersionedMapStoreStateImpl; |
11 | import tools.refinery.store.model.TupleHashProvider; | 11 | import tools.refinery.store.model.TupleHashProvider; |
12 | import tools.refinery.store.tuple.Tuple; | 12 | import tools.refinery.store.tuple.Tuple; |
13 | 13 | ||
@@ -16,7 +16,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; | |||
16 | class MapUnitTests { | 16 | class MapUnitTests { |
17 | @Test | 17 | @Test |
18 | void defaultTest() { | 18 | void defaultTest() { |
19 | VersionedMapStore<Tuple, Boolean> store = new VersionedMapStoreImpl<>(TupleHashProvider.INSTANCE, false); | 19 | VersionedMapStore<Tuple, Boolean> store = new VersionedMapStoreStateImpl<>(TupleHashProvider.INSTANCE, false); |
20 | var map = store.createMap(); | 20 | var map = store.createMap(); |
21 | var out1 = map.put(Tuple.of(0), true); | 21 | var out1 = map.put(Tuple.of(0), true); |
22 | assertEquals(false, out1); | 22 | assertEquals(false, out1); |
diff --git a/subprojects/store/src/test/java/tools/refinery/store/map/tests/fuzz/MutableImmutableCompareFuzzTest.java b/subprojects/store/src/test/java/tools/refinery/store/map/tests/fuzz/MutableImmutableCompareFuzzTest.java index 420dade6..abfb4791 100644 --- a/subprojects/store/src/test/java/tools/refinery/store/map/tests/fuzz/MutableImmutableCompareFuzzTest.java +++ b/subprojects/store/src/test/java/tools/refinery/store/map/tests/fuzz/MutableImmutableCompareFuzzTest.java | |||
@@ -17,10 +17,10 @@ import org.junit.jupiter.params.ParameterizedTest; | |||
17 | import org.junit.jupiter.params.provider.Arguments; | 17 | import org.junit.jupiter.params.provider.Arguments; |
18 | import org.junit.jupiter.params.provider.MethodSource; | 18 | import org.junit.jupiter.params.provider.MethodSource; |
19 | 19 | ||
20 | import tools.refinery.store.map.ContinousHashProvider; | 20 | import tools.refinery.store.map.ContinuousHashProvider; |
21 | import tools.refinery.store.map.VersionedMapStore; | 21 | import tools.refinery.store.map.VersionedMapStore; |
22 | import tools.refinery.store.map.VersionedMapStoreImpl; | 22 | import tools.refinery.store.map.internal.state.VersionedMapStoreStateImpl; |
23 | import tools.refinery.store.map.internal.VersionedMapImpl; | 23 | import tools.refinery.store.map.internal.state.VersionedMapStateImpl; |
24 | import tools.refinery.store.map.tests.fuzz.utils.FuzzTestUtils; | 24 | import tools.refinery.store.map.tests.fuzz.utils.FuzzTestUtils; |
25 | import tools.refinery.store.map.tests.utils.MapTestEnvironment; | 25 | import tools.refinery.store.map.tests.utils.MapTestEnvironment; |
26 | 26 | ||
@@ -28,11 +28,11 @@ class MutableImmutableCompareFuzzTest { | |||
28 | private void runFuzzTest(String scenario, int seed, int steps, int maxKey, int maxValue, | 28 | private void runFuzzTest(String scenario, int seed, int steps, int maxKey, int maxValue, |
29 | boolean nullDefault, int commitFrequency, boolean evilHash) { | 29 | boolean nullDefault, int commitFrequency, boolean evilHash) { |
30 | String[] values = MapTestEnvironment.prepareValues(maxValue, nullDefault); | 30 | String[] values = MapTestEnvironment.prepareValues(maxValue, nullDefault); |
31 | ContinousHashProvider<Integer> chp = MapTestEnvironment.prepareHashProvider(evilHash); | 31 | ContinuousHashProvider<Integer> chp = MapTestEnvironment.prepareHashProvider(evilHash); |
32 | 32 | ||
33 | VersionedMapStore<Integer, String> store = new VersionedMapStoreImpl<>(chp, values[0]); | 33 | VersionedMapStore<Integer, String> store = new VersionedMapStoreStateImpl<>(chp, values[0]); |
34 | VersionedMapImpl<Integer, String> immutable = (VersionedMapImpl<Integer, String>) store.createMap(); | 34 | VersionedMapStateImpl<Integer, String> immutable = (VersionedMapStateImpl<Integer, String>) store.createMap(); |
35 | VersionedMapImpl<Integer, String> mutable = (VersionedMapImpl<Integer, String>) store.createMap(); | 35 | VersionedMapStateImpl<Integer, String> mutable = (VersionedMapStateImpl<Integer, String>) store.createMap(); |
36 | 36 | ||
37 | Random r = new Random(seed); | 37 | Random r = new Random(seed); |
38 | 38 | ||
@@ -40,8 +40,8 @@ class MutableImmutableCompareFuzzTest { | |||
40 | commitFrequency); | 40 | commitFrequency); |
41 | } | 41 | } |
42 | 42 | ||
43 | private void iterativeRandomPutsAndCommitsAndCompare(String scenario, VersionedMapImpl<Integer, String> immutable, | 43 | private void iterativeRandomPutsAndCommitsAndCompare(String scenario, VersionedMapStateImpl<Integer, String> immutable, |
44 | VersionedMapImpl<Integer, String> mutable, int steps, int maxKey, String[] values, Random r, | 44 | VersionedMapStateImpl<Integer, String> mutable, int steps, int maxKey, String[] values, Random r, |
45 | int commitFrequency) { | 45 | int commitFrequency) { |
46 | for (int i = 0; i < steps; i++) { | 46 | for (int i = 0; i < steps; i++) { |
47 | int index = i + 1; | 47 | int index = i + 1; |
diff --git a/subprojects/store/src/test/java/tools/refinery/store/map/tests/fuzz/SharedStoreFuzzTest.java b/subprojects/store/src/test/java/tools/refinery/store/map/tests/fuzz/SharedStoreFuzzTest.java index 680d962d..b17766b7 100644 --- a/subprojects/store/src/test/java/tools/refinery/store/map/tests/fuzz/SharedStoreFuzzTest.java +++ b/subprojects/store/src/test/java/tools/refinery/store/map/tests/fuzz/SharedStoreFuzzTest.java | |||
@@ -18,10 +18,10 @@ import org.junit.jupiter.params.ParameterizedTest; | |||
18 | import org.junit.jupiter.params.provider.Arguments; | 18 | import org.junit.jupiter.params.provider.Arguments; |
19 | import org.junit.jupiter.params.provider.MethodSource; | 19 | import org.junit.jupiter.params.provider.MethodSource; |
20 | 20 | ||
21 | import tools.refinery.store.map.ContinousHashProvider; | 21 | import tools.refinery.store.map.ContinuousHashProvider; |
22 | import tools.refinery.store.map.VersionedMapStore; | 22 | import tools.refinery.store.map.VersionedMapStore; |
23 | import tools.refinery.store.map.VersionedMapStoreImpl; | 23 | import tools.refinery.store.map.internal.state.VersionedMapStoreStateImpl; |
24 | import tools.refinery.store.map.internal.VersionedMapImpl; | 24 | import tools.refinery.store.map.internal.state.VersionedMapStateImpl; |
25 | import tools.refinery.store.map.tests.fuzz.utils.FuzzTestUtils; | 25 | import tools.refinery.store.map.tests.fuzz.utils.FuzzTestUtils; |
26 | import tools.refinery.store.map.tests.utils.MapTestEnvironment; | 26 | import tools.refinery.store.map.tests.utils.MapTestEnvironment; |
27 | 27 | ||
@@ -31,9 +31,9 @@ class SharedStoreFuzzTest { | |||
31 | private void runFuzzTest(String scenario, int seed, int steps, int maxKey, int maxValue, | 31 | private void runFuzzTest(String scenario, int seed, int steps, int maxKey, int maxValue, |
32 | boolean nullDefault, int commitFrequency, boolean evilHash) { | 32 | boolean nullDefault, int commitFrequency, boolean evilHash) { |
33 | String[] values = MapTestEnvironment.prepareValues(maxValue, nullDefault); | 33 | String[] values = MapTestEnvironment.prepareValues(maxValue, nullDefault); |
34 | ContinousHashProvider<Integer> chp = MapTestEnvironment.prepareHashProvider(evilHash); | 34 | ContinuousHashProvider<Integer> chp = MapTestEnvironment.prepareHashProvider(evilHash); |
35 | 35 | ||
36 | List<VersionedMapStore<Integer, String>> stores = VersionedMapStoreImpl.createSharedVersionedMapStores(5, chp, values[0]); | 36 | List<VersionedMapStore<Integer, String>> stores = VersionedMapStoreStateImpl.createSharedVersionedMapStores(5, chp, values[0]); |
37 | 37 | ||
38 | iterativeRandomPutsAndCommitsThenRestore(scenario, stores, steps, maxKey, values, seed, commitFrequency); | 38 | iterativeRandomPutsAndCommitsThenRestore(scenario, stores, steps, maxKey, values, seed, commitFrequency); |
39 | } | 39 | } |
@@ -42,9 +42,9 @@ class SharedStoreFuzzTest { | |||
42 | int steps, int maxKey, String[] values, int seed, int commitFrequency) { | 42 | int steps, int maxKey, String[] values, int seed, int commitFrequency) { |
43 | // 1. maps with versions | 43 | // 1. maps with versions |
44 | Random r = new Random(seed); | 44 | Random r = new Random(seed); |
45 | List<VersionedMapImpl<Integer, String>> versioneds = new LinkedList<>(); | 45 | List<VersionedMapStateImpl<Integer, String>> versioneds = new LinkedList<>(); |
46 | for (VersionedMapStore<Integer, String> store : stores) { | 46 | for (VersionedMapStore<Integer, String> store : stores) { |
47 | versioneds.add((VersionedMapImpl<Integer, String>) store.createMap()); | 47 | versioneds.add((VersionedMapStateImpl<Integer, String>) store.createMap()); |
48 | } | 48 | } |
49 | 49 | ||
50 | List<Map<Integer, Long>> index2Version = new LinkedList<>(); | 50 | List<Map<Integer, Long>> index2Version = new LinkedList<>(); |
@@ -66,9 +66,9 @@ class SharedStoreFuzzTest { | |||
66 | } | 66 | } |
67 | } | 67 | } |
68 | // 2. create a non-versioned and | 68 | // 2. create a non-versioned and |
69 | List<VersionedMapImpl<Integer, String>> reference = new LinkedList<>(); | 69 | List<VersionedMapStateImpl<Integer, String>> reference = new LinkedList<>(); |
70 | for (VersionedMapStore<Integer, String> store : stores) { | 70 | for (VersionedMapStore<Integer, String> store : stores) { |
71 | reference.add((VersionedMapImpl<Integer, String>) store.createMap()); | 71 | reference.add((VersionedMapStateImpl<Integer, String>) store.createMap()); |
72 | } | 72 | } |
73 | r = new Random(seed); | 73 | r = new Random(seed); |
74 | 74 | ||
diff --git a/subprojects/store/src/test/java/tools/refinery/store/map/tests/utils/MapTestEnvironment.java b/subprojects/store/src/test/java/tools/refinery/store/map/tests/utils/MapTestEnvironment.java index e7348370..401f2866 100644 --- a/subprojects/store/src/test/java/tools/refinery/store/map/tests/utils/MapTestEnvironment.java +++ b/subprojects/store/src/test/java/tools/refinery/store/map/tests/utils/MapTestEnvironment.java | |||
@@ -6,7 +6,7 @@ | |||
6 | package tools.refinery.store.map.tests.utils; | 6 | package tools.refinery.store.map.tests.utils; |
7 | 7 | ||
8 | import tools.refinery.store.map.*; | 8 | import tools.refinery.store.map.*; |
9 | import tools.refinery.store.map.internal.VersionedMapImpl; | 9 | import tools.refinery.store.map.internal.state.VersionedMapStateImpl; |
10 | 10 | ||
11 | import java.util.*; | 11 | import java.util.*; |
12 | import java.util.Map.Entry; | 12 | import java.util.Map.Entry; |
@@ -28,7 +28,7 @@ public class MapTestEnvironment<K, V> { | |||
28 | return values; | 28 | return values; |
29 | } | 29 | } |
30 | 30 | ||
31 | public static ContinousHashProvider<Integer> prepareHashProvider(final boolean evil) { | 31 | public static ContinuousHashProvider<Integer> prepareHashProvider(final boolean evil) { |
32 | // Use maxPrime = 2147483629 | 32 | // Use maxPrime = 2147483629 |
33 | 33 | ||
34 | return (key, index) -> { | 34 | return (key, index) -> { |
@@ -187,7 +187,7 @@ public class MapTestEnvironment<K, V> { | |||
187 | //System.out.println(cursor.getKey() + " " + ((VersionedMapImpl<K, V>) versionedMap).getHashProvider() | 187 | //System.out.println(cursor.getKey() + " " + ((VersionedMapImpl<K, V>) versionedMap).getHashProvider() |
188 | // .getHash(cursor.getKey(), 0)); | 188 | // .getHash(cursor.getKey(), 0)); |
189 | if (previous != null) { | 189 | if (previous != null) { |
190 | int comparisonResult = ((VersionedMapImpl<K, V>) versionedMap).getHashProvider().compare(previous, | 190 | int comparisonResult = ((VersionedMapStateImpl<K, V>) versionedMap).getHashProvider().compare(previous, |
191 | cursor.getKey()); | 191 | cursor.getKey()); |
192 | assertTrue(comparisonResult < 0, scenario + " Cursor order is not incremental!"); | 192 | assertTrue(comparisonResult < 0, scenario + " Cursor order is not incremental!"); |
193 | } | 193 | } |
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 4d4f5e26..5b595da7 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 | |||
@@ -3,7 +3,7 @@ | |||
3 | * | 3 | * |
4 | * SPDX-License-Identifier: EPL-2.0 | 4 | * SPDX-License-Identifier: EPL-2.0 |
5 | */ | 5 | */ |
6 | package tools.refinery.store.model.hashtests; | 6 | package tools.refinery.store.model.hashTests; |
7 | 7 | ||
8 | import static org.junit.jupiter.api.Assertions.assertEquals; | 8 | import static org.junit.jupiter.api.Assertions.assertEquals; |
9 | 9 | ||
@@ -14,10 +14,9 @@ import java.util.Random; | |||
14 | 14 | ||
15 | import org.junit.jupiter.api.Test; | 15 | import org.junit.jupiter.api.Test; |
16 | 16 | ||
17 | import tools.refinery.store.map.ContinousHashProvider; | 17 | import tools.refinery.store.map.ContinuousHashProvider; |
18 | import tools.refinery.store.tuple.Tuple; | 18 | import tools.refinery.store.tuple.Tuple; |
19 | import tools.refinery.store.model.TupleHashProvider; | 19 | import tools.refinery.store.model.TupleHashProvider; |
20 | import tools.refinery.store.model.TupleHashProviderBitMagic; | ||
21 | 20 | ||
22 | class HashEfficiencyTest { | 21 | class HashEfficiencyTest { |
23 | 22 | ||
@@ -95,7 +94,7 @@ class HashEfficiencyTest { | |||
95 | List<Tuple> p = nRandoms(2, amount, 1);; | 94 | List<Tuple> p = nRandoms(2, amount, 1);; |
96 | assertEquals(amount,p.size()); | 95 | assertEquals(amount,p.size()); |
97 | } | 96 | } |
98 | private static double calculateHashClashes(List<Tuple> tuples, ContinousHashProvider<Tuple> chp) { | 97 | private static double calculateHashClashes(List<Tuple> tuples, ContinuousHashProvider<Tuple> chp) { |
99 | int sumClashes = 0; | 98 | int sumClashes = 0; |
100 | 99 | ||
101 | for(int i = 0; i<tuples.size(); i++) { | 100 | for(int i = 0; i<tuples.size(); i++) { |
@@ -108,7 +107,7 @@ class HashEfficiencyTest { | |||
108 | } | 107 | } |
109 | return (sumClashes+0.0) / tuples.size(); | 108 | return (sumClashes+0.0) / tuples.size(); |
110 | } | 109 | } |
111 | private static int calculateHashClash(ContinousHashProvider<Tuple> chp, Tuple a, Tuple b) { | 110 | private static int calculateHashClash(ContinuousHashProvider<Tuple> chp, Tuple a, Tuple b) { |
112 | if(a.equals(b)) return 0; | 111 | if(a.equals(b)) return 0; |
113 | final int bits = 5; | 112 | final int bits = 5; |
114 | final int segments = Integer.SIZE/bits; | 113 | final int segments = Integer.SIZE/bits; |
@@ -131,11 +130,9 @@ class HashEfficiencyTest { | |||
131 | } | 130 | } |
132 | public static void main(String[] args) { | 131 | public static void main(String[] args) { |
133 | List<String> hashNames = new LinkedList<>(); | 132 | List<String> hashNames = new LinkedList<>(); |
134 | List<ContinousHashProvider<Tuple>> hashes = new LinkedList<>(); | 133 | List<ContinuousHashProvider<Tuple>> hashes = new LinkedList<>(); |
135 | hashNames.add("PrimeGroup"); | 134 | hashNames.add("PrimeGroup"); |
136 | hashes.add(new TupleHashProvider()); | 135 | hashes.add(new TupleHashProvider()); |
137 | hashNames.add("BitMagic"); | ||
138 | hashes.add(new TupleHashProviderBitMagic()); | ||
139 | 136 | ||
140 | int[] arities = new int[] {2,3,4,5}; | 137 | int[] arities = new int[] {2,3,4,5}; |
141 | int[] sizes = new int[] {32*32,32*32*8}; | 138 | int[] sizes = new int[] {32*32,32*32*8}; |