aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar OszkarSemerath <semerath@mit.bme.hu>2021-08-01 22:13:49 +0200
committerLibravatar OszkarSemerath <semerath@mit.bme.hu>2021-08-01 22:13:49 +0200
commit59fd43462a7c5aa076c10ce3bb16121a7dc7edcc (patch)
tree1bd28bda68125fc70ce9bc330c7bafb2016ae8bf
parentContentEquals test + typo fix (diff)
downloadrefinery-59fd43462a7c5aa076c10ce3bb16121a7dc7edcc.tar.gz
refinery-59fd43462a7c5aa076c10ce3bb16121a7dc7edcc.tar.zst
refinery-59fd43462a7c5aa076c10ce3bb16121a7dc7edcc.zip
KEY,VALUE replaced with K,V to please Sonar
-rw-r--r--model-data/src/main/java/org/eclipse/viatra/solver/data/map/ContinousHashProvider.java2
-rw-r--r--model-data/src/main/java/org/eclipse/viatra/solver/data/map/Cursor.java8
-rw-r--r--model-data/src/main/java/org/eclipse/viatra/solver/data/map/DiffCursor.java2
-rw-r--r--model-data/src/main/java/org/eclipse/viatra/solver/data/map/VersionedMap.java12
-rw-r--r--model-data/src/main/java/org/eclipse/viatra/solver/data/map/VersionedMapStore.java8
-rw-r--r--model-data/src/main/java/org/eclipse/viatra/solver/data/map/VersionedMapStoreImpl.java62
-rw-r--r--model-data/src/main/java/org/eclipse/viatra/solver/data/map/internal/ImmutableNode.java80
-rw-r--r--model-data/src/main/java/org/eclipse/viatra/solver/data/map/internal/MapCursor.java30
-rw-r--r--model-data/src/main/java/org/eclipse/viatra/solver/data/map/internal/MapDiffCursor.java32
-rw-r--r--model-data/src/main/java/org/eclipse/viatra/solver/data/map/internal/MutableNode.java82
-rw-r--r--model-data/src/main/java/org/eclipse/viatra/solver/data/map/internal/Node.java20
-rw-r--r--model-data/src/main/java/org/eclipse/viatra/solver/data/map/internal/VersionedMapImpl.java60
-rw-r--r--model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/utils/MapTestEnvironment.java46
13 files changed, 222 insertions, 222 deletions
diff --git a/model-data/src/main/java/org/eclipse/viatra/solver/data/map/ContinousHashProvider.java b/model-data/src/main/java/org/eclipse/viatra/solver/data/map/ContinousHashProvider.java
index 6ab45c7c..3f019b24 100644
--- a/model-data/src/main/java/org/eclipse/viatra/solver/data/map/ContinousHashProvider.java
+++ b/model-data/src/main/java/org/eclipse/viatra/solver/data/map/ContinousHashProvider.java
@@ -3,7 +3,7 @@ package org.eclipse.viatra.solver.data.map;
3import org.eclipse.viatra.solver.data.map.internal.Node; 3import org.eclipse.viatra.solver.data.map.internal.Node;
4 4
5/** 5/**
6 * A class representing an equivalence relation for a type {@code KEY} with a 6 * A class representing an equivalence relation for a type {@code K} with a
7 * continuous hash function. 7 * continuous hash function.
8 * 8 *
9 * @author Oszkar Semerath 9 * @author Oszkar Semerath
diff --git a/model-data/src/main/java/org/eclipse/viatra/solver/data/map/Cursor.java b/model-data/src/main/java/org/eclipse/viatra/solver/data/map/Cursor.java
index 969f96c9..95e59ee2 100644
--- a/model-data/src/main/java/org/eclipse/viatra/solver/data/map/Cursor.java
+++ b/model-data/src/main/java/org/eclipse/viatra/solver/data/map/Cursor.java
@@ -2,12 +2,12 @@ package org.eclipse.viatra.solver.data.map;
2 2
3import java.util.List; 3import java.util.List;
4 4
5public interface Cursor<KEY,VALUE> { 5public interface Cursor<K,V> {
6 public KEY getKey(); 6 public K getKey();
7 public VALUE getValue(); 7 public V getValue();
8 public boolean isTerminated(); 8 public boolean isTerminated();
9 public boolean move(); 9 public boolean move();
10 public boolean isDirty(); 10 public boolean isDirty();
11 11
12 public List<VersionedMap<KEY,VALUE>> getDependingMaps(); 12 public List<VersionedMap<K,V>> getDependingMaps();
13} 13}
diff --git a/model-data/src/main/java/org/eclipse/viatra/solver/data/map/DiffCursor.java b/model-data/src/main/java/org/eclipse/viatra/solver/data/map/DiffCursor.java
index 2be2e024..7042f7c9 100644
--- a/model-data/src/main/java/org/eclipse/viatra/solver/data/map/DiffCursor.java
+++ b/model-data/src/main/java/org/eclipse/viatra/solver/data/map/DiffCursor.java
@@ -1,5 +1,5 @@
1package org.eclipse.viatra.solver.data.map; 1package org.eclipse.viatra.solver.data.map;
2 2
3public interface DiffCursor<KEY, VALUE> extends Cursor<KEY,VALUE> { 3public interface DiffCursor<K, V> extends Cursor<K,V> {
4 4
5} \ No newline at end of file 5} \ No newline at end of file
diff --git a/model-data/src/main/java/org/eclipse/viatra/solver/data/map/VersionedMap.java b/model-data/src/main/java/org/eclipse/viatra/solver/data/map/VersionedMap.java
index 11077dca..fb42d822 100644
--- a/model-data/src/main/java/org/eclipse/viatra/solver/data/map/VersionedMap.java
+++ b/model-data/src/main/java/org/eclipse/viatra/solver/data/map/VersionedMap.java
@@ -1,11 +1,11 @@
1package org.eclipse.viatra.solver.data.map; 1package org.eclipse.viatra.solver.data.map;
2 2
3public interface VersionedMap<KEY,VALUE> extends Versioned{ 3public interface VersionedMap<K,V> extends Versioned{
4 public void put(KEY key, VALUE value); 4 public void put(K key, V value);
5 public VALUE get(KEY key); 5 public V get(K key);
6 public long getSize(); 6 public long getSize();
7 7
8 public Cursor<KEY,VALUE> getCursor(); 8 public Cursor<K,V> getCursor();
9 public DiffCursor<KEY,VALUE> getDiffCursor(long state); 9 public DiffCursor<K,V> getDiffCursor(long state);
10 public void putAll(Cursor<KEY,VALUE> cursor); 10 public void putAll(Cursor<K,V> cursor);
11} 11}
diff --git a/model-data/src/main/java/org/eclipse/viatra/solver/data/map/VersionedMapStore.java b/model-data/src/main/java/org/eclipse/viatra/solver/data/map/VersionedMapStore.java
index d92e5ad6..9df5f5f6 100644
--- a/model-data/src/main/java/org/eclipse/viatra/solver/data/map/VersionedMapStore.java
+++ b/model-data/src/main/java/org/eclipse/viatra/solver/data/map/VersionedMapStore.java
@@ -1,10 +1,10 @@
1package org.eclipse.viatra.solver.data.map; 1package org.eclipse.viatra.solver.data.map;
2 2
3public interface VersionedMapStore<KEY, VALUE> { 3public interface VersionedMapStore<K, V> {
4 4
5 public VersionedMap<KEY, VALUE> createMap(); 5 public VersionedMap<K, V> createMap();
6 6
7 public VersionedMap<KEY, VALUE> createMap(long state) throws IllegalAccessException; 7 public VersionedMap<K, V> createMap(long state) throws IllegalAccessException;
8 8
9 public DiffCursor<KEY,VALUE> getDiffCursor(long fromState, long toState); 9 public DiffCursor<K,V> getDiffCursor(long fromState, long toState);
10} \ No newline at end of file 10} \ No newline at end of file
diff --git a/model-data/src/main/java/org/eclipse/viatra/solver/data/map/VersionedMapStoreImpl.java b/model-data/src/main/java/org/eclipse/viatra/solver/data/map/VersionedMapStoreImpl.java
index 7b69ae54..5bcbf0c4 100644
--- a/model-data/src/main/java/org/eclipse/viatra/solver/data/map/VersionedMapStoreImpl.java
+++ b/model-data/src/main/java/org/eclipse/viatra/solver/data/map/VersionedMapStoreImpl.java
@@ -12,20 +12,20 @@ import org.eclipse.viatra.solver.data.map.internal.MapDiffCursor;
12import org.eclipse.viatra.solver.data.map.internal.Node; 12import org.eclipse.viatra.solver.data.map.internal.Node;
13import org.eclipse.viatra.solver.data.map.internal.VersionedMapImpl; 13import org.eclipse.viatra.solver.data.map.internal.VersionedMapImpl;
14 14
15public class VersionedMapStoreImpl<KEY, VALUE> implements VersionedMapStore<KEY, VALUE> { 15public class VersionedMapStoreImpl<K, V> implements VersionedMapStore<K, V> {
16 // Configuration 16 // Configuration
17 private final boolean immutableWhenCommiting; 17 private final boolean immutableWhenCommiting;
18 18
19 // Static data 19 // Static data
20 protected final ContinousHashProvider<? super KEY> hashProvider; 20 protected final ContinousHashProvider<? super K> hashProvider;
21 protected final VALUE defaultValue; 21 protected final V defaultValue;
22 22
23 // Dynamic data 23 // Dynamic data
24 protected final Map<Long, ImmutableNode<KEY, VALUE>> states = new HashMap<>(); 24 protected final Map<Long, ImmutableNode<K, V>> states = new HashMap<>();
25 protected final Map<Node<KEY, VALUE>, ImmutableNode<KEY, VALUE>> nodeCache; 25 protected final Map<Node<K, V>, ImmutableNode<K, V>> nodeCache;
26 protected long nextID = 0; 26 protected long nextID = 0;
27 27
28 public VersionedMapStoreImpl(ContinousHashProvider<? super KEY> hashProvider, VALUE defaultValue, 28 public VersionedMapStoreImpl(ContinousHashProvider<? super K> hashProvider, V defaultValue,
29 VersionedMapStoreConfiguration config) { 29 VersionedMapStoreConfiguration config) {
30 this.immutableWhenCommiting = config.immutableWhenCommiting; 30 this.immutableWhenCommiting = config.immutableWhenCommiting;
31 this.hashProvider = hashProvider; 31 this.hashProvider = hashProvider;
@@ -37,42 +37,42 @@ public class VersionedMapStoreImpl<KEY, VALUE> implements VersionedMapStore<KEY,
37 } 37 }
38 } 38 }
39 39
40 private VersionedMapStoreImpl(ContinousHashProvider<? super KEY> hashProvider, VALUE defaultValue, 40 private VersionedMapStoreImpl(ContinousHashProvider<K> hashProvider, V defaultValue,
41 Map<Node<KEY, VALUE>, ImmutableNode<KEY, VALUE>> nodeCache, VersionedMapStoreConfiguration config) { 41 Map<Node<K, V>, ImmutableNode<K, V>> nodeCache, VersionedMapStoreConfiguration config) {
42 this.immutableWhenCommiting = config.immutableWhenCommiting; 42 this.immutableWhenCommiting = config.immutableWhenCommiting;
43 this.hashProvider = hashProvider; 43 this.hashProvider = hashProvider;
44 this.defaultValue = defaultValue; 44 this.defaultValue = defaultValue;
45 this.nodeCache = nodeCache; 45 this.nodeCache = nodeCache;
46 } 46 }
47 47
48 public VersionedMapStoreImpl(ContinousHashProvider<KEY> hashProvider, VALUE defaultValue) { 48 public VersionedMapStoreImpl(ContinousHashProvider<K> hashProvider, V defaultValue) {
49 this(hashProvider, defaultValue, new VersionedMapStoreConfiguration()); 49 this(hashProvider, defaultValue, new VersionedMapStoreConfiguration());
50 } 50 }
51 51
52 public static <KEY, VALUE> List<VersionedMapStore<KEY, VALUE>> createSharedVersionedMapStores(int amount, 52 public static <K, V> List<VersionedMapStore<K, V>> createSharedVersionedMapStores(int amount,
53 ContinousHashProvider<? super KEY> hashProvider, VALUE defaultValue, 53 ContinousHashProvider<K> hashProvider, V defaultValue,
54 VersionedMapStoreConfiguration config) { 54 VersionedMapStoreConfiguration config) {
55 List<VersionedMapStore<KEY, VALUE>> result = new ArrayList<>(amount); 55 List<VersionedMapStore<K, V>> result = new ArrayList<>(amount);
56 if (config.sharedNodeCacheInStoreGroups) { 56 if (config.sharedNodeCacheInStoreGroups) {
57 Map<Node<KEY, VALUE>, ImmutableNode<KEY, VALUE>> nodeCache; 57 Map<Node<K, V>, ImmutableNode<K, V>> nodeCache;
58 if (config.sharedNodeCacheInStore) { 58 if (config.sharedNodeCacheInStore) {
59 nodeCache = new HashMap<>(); 59 nodeCache = new HashMap<>();
60 } else { 60 } else {
61 nodeCache = null; 61 nodeCache = null;
62 } 62 }
63 for (int i = 0; i < amount; i++) { 63 for (int i = 0; i < amount; i++) {
64 result.add(new VersionedMapStoreImpl<KEY, VALUE>(hashProvider, defaultValue, nodeCache, config)); 64 result.add(new VersionedMapStoreImpl<K, V>(hashProvider, defaultValue, nodeCache, config));
65 } 65 }
66 } else { 66 } else {
67 for (int i = 0; i < amount; i++) { 67 for (int i = 0; i < amount; i++) {
68 result.add(new VersionedMapStoreImpl<KEY, VALUE>(hashProvider, defaultValue, config)); 68 result.add(new VersionedMapStoreImpl<K, V>(hashProvider, defaultValue, config));
69 } 69 }
70 } 70 }
71 return result; 71 return result;
72 } 72 }
73 73
74 public static <KEY, VALUE> List<VersionedMapStore<KEY, VALUE>> createSharedVersionedMapStores(int amount, 74 public static <K, V> List<VersionedMapStore<K, V>> createSharedVersionedMapStores(int amount,
75 ContinousHashProvider<? super KEY> hashProvider, VALUE defaultValue) { 75 ContinousHashProvider<K> hashProvider, V defaultValue) {
76 return createSharedVersionedMapStores(amount, hashProvider, defaultValue, new VersionedMapStoreConfiguration()); 76 return createSharedVersionedMapStores(amount, hashProvider, defaultValue, new VersionedMapStoreConfiguration());
77 } 77 }
78 78
@@ -81,17 +81,17 @@ public class VersionedMapStoreImpl<KEY, VALUE> implements VersionedMapStore<KEY,
81 } 81 }
82 82
83 @Override 83 @Override
84 public VersionedMap<KEY, VALUE> createMap() { 84 public VersionedMap<K, V> createMap() {
85 return new VersionedMapImpl<KEY, VALUE>(this, hashProvider, defaultValue); 85 return new VersionedMapImpl<K, V>(this, hashProvider, defaultValue);
86 } 86 }
87 87
88 @Override 88 @Override
89 public VersionedMap<KEY, VALUE> createMap(long state) { 89 public VersionedMap<K, V> createMap(long state) {
90 ImmutableNode<KEY, VALUE> data = revert(state); 90 ImmutableNode<K, V> data = revert(state);
91 return new VersionedMapImpl<KEY, VALUE>(this, hashProvider, defaultValue, data); 91 return new VersionedMapImpl<K, V>(this, hashProvider, defaultValue, data);
92 } 92 }
93 93
94 public synchronized ImmutableNode<KEY, VALUE> revert(long state) { 94 public synchronized ImmutableNode<K, V> revert(long state) {
95 if (states.containsKey(state)) { 95 if (states.containsKey(state)) {
96 return states.get(state); 96 return states.get(state);
97 } else { 97 } else {
@@ -102,8 +102,8 @@ public class VersionedMapStoreImpl<KEY, VALUE> implements VersionedMapStore<KEY,
102 } 102 }
103 } 103 }
104 104
105 public synchronized long commit(Node<KEY, VALUE> data, VersionedMapImpl<KEY, VALUE> mapToUpdateRoot) { 105 public synchronized long commit(Node<K, V> data, VersionedMapImpl<K, V> mapToUpdateRoot) {
106 ImmutableNode<KEY, VALUE> immutable; 106 ImmutableNode<K, V> immutable;
107 if (data != null) { 107 if (data != null) {
108 immutable = data.toImmutable(this.nodeCache); 108 immutable = data.toImmutable(this.nodeCache);
109 } else { 109 } else {
@@ -121,11 +121,11 @@ public class VersionedMapStoreImpl<KEY, VALUE> implements VersionedMapStore<KEY,
121 } 121 }
122 122
123 @Override 123 @Override
124 public DiffCursor<KEY, VALUE> getDiffCursor(long fromState, long toState) { 124 public DiffCursor<K, V> getDiffCursor(long fromState, long toState) {
125 VersionedMap<KEY, VALUE> map1 = createMap(fromState); 125 VersionedMap<K, V> map1 = createMap(fromState);
126 VersionedMap<KEY, VALUE> map2 = createMap(toState); 126 VersionedMap<K, V> map2 = createMap(toState);
127 Cursor<KEY, VALUE> cursor1 = map1.getCursor(); 127 Cursor<K, V> cursor1 = map1.getCursor();
128 Cursor<KEY, VALUE> cursor2 = map2.getCursor(); 128 Cursor<K, V> cursor2 = map2.getCursor();
129 return new MapDiffCursor<KEY, VALUE>(this.hashProvider, this.defaultValue, cursor1, cursor2); 129 return new MapDiffCursor<K, V>(this.hashProvider, this.defaultValue, cursor1, cursor2);
130 } 130 }
131} 131}
diff --git a/model-data/src/main/java/org/eclipse/viatra/solver/data/map/internal/ImmutableNode.java b/model-data/src/main/java/org/eclipse/viatra/solver/data/map/internal/ImmutableNode.java
index 5f293f70..a469326e 100644
--- a/model-data/src/main/java/org/eclipse/viatra/solver/data/map/internal/ImmutableNode.java
+++ b/model-data/src/main/java/org/eclipse/viatra/solver/data/map/internal/ImmutableNode.java
@@ -5,7 +5,7 @@ import java.util.Map;
5 5
6import org.eclipse.viatra.solver.data.map.ContinousHashProvider; 6import org.eclipse.viatra.solver.data.map.ContinousHashProvider;
7 7
8public class ImmutableNode<KEY, VALUE> extends Node<KEY, VALUE> { 8public class ImmutableNode<K, V> extends Node<K, V> {
9 /** 9 /**
10 * Bitmap defining the stored key and values. 10 * Bitmap defining the stored key and values.
11 */ 11 */
@@ -15,7 +15,7 @@ public class ImmutableNode<KEY, VALUE> extends Node<KEY, VALUE> {
15 */ 15 */
16 final int nodeMap; 16 final int nodeMap;
17 /** 17 /**
18 * Stores Keys, Values, and subnodes. Structure: (KEY,VALUE)*,NODE; NODES are stored backwards. 18 * Stores Keys, Values, and subnodes. Structure: (K,V)*,NODE; NODES are stored backwards.
19 */ 19 */
20 final Object[] content; 20 final Object[] content;
21 21
@@ -42,10 +42,10 @@ public class ImmutableNode<KEY, VALUE> extends Node<KEY, VALUE> {
42 * @return an immutable version of the input node. 42 * @return an immutable version of the input node.
43 */ 43 */
44 @SuppressWarnings("unchecked") 44 @SuppressWarnings("unchecked")
45 static <KEY,VALUE> ImmutableNode<KEY,VALUE> constructImmutable(MutableNode<KEY,VALUE> node, Map<Node<KEY, VALUE>, ImmutableNode<KEY, VALUE>> cache) { 45 static <K,V> ImmutableNode<K,V> constructImmutable(MutableNode<K,V> node, Map<Node<K, V>, ImmutableNode<K, V>> cache) {
46 // 1. try to return from cache 46 // 1. try to return from cache
47 if(cache != null) { 47 if(cache != null) {
48 ImmutableNode<KEY, VALUE> cachedResult = cache.get(node); 48 ImmutableNode<K, V> cachedResult = cache.get(node);
49 if(cachedResult != null) { 49 if(cachedResult != null) {
50 // 1.1 Already cached, return from cache. 50 // 1.1 Already cached, return from cache.
51 return cachedResult; 51 return cachedResult;
@@ -74,9 +74,9 @@ public class ImmutableNode<KEY, VALUE> extends Node<KEY, VALUE> {
74 resultContent[datas*2+1] = node.content[i*2+1]; 74 resultContent[datas*2+1] = node.content[i*2+1];
75 datas++; 75 datas++;
76 } else { 76 } else {
77 Node<KEY,VALUE> subnode = (Node<KEY, VALUE>) node.content[i*2+1]; 77 Node<K,V> subnode = (Node<K, V>) node.content[i*2+1];
78 if(subnode != null) { 78 if(subnode != null) {
79 ImmutableNode<KEY, VALUE> immutableSubnode = subnode.toImmutable(cache); 79 ImmutableNode<K, V> immutableSubnode = subnode.toImmutable(cache);
80 resultNodeMap |=bitposition; 80 resultNodeMap |=bitposition;
81 resultContent[size-1-nodes] = immutableSubnode; 81 resultContent[size-1-nodes] = immutableSubnode;
82 nodes++; 82 nodes++;
@@ -85,7 +85,7 @@ public class ImmutableNode<KEY, VALUE> extends Node<KEY, VALUE> {
85 bitposition<<=1; 85 bitposition<<=1;
86 } 86 }
87 final int resultHash = node.hashCode(); 87 final int resultHash = node.hashCode();
88 ImmutableNode<KEY,VALUE> newImmutable = new ImmutableNode<>(resultDataMap, resultNodeMap, resultContent, resultHash); 88 ImmutableNode<K,V> newImmutable = new ImmutableNode<>(resultDataMap, resultNodeMap, resultContent, resultHash);
89 89
90 // 3. save new immutable. 90 // 3. save new immutable.
91 if(cache != null) { 91 if(cache != null) {
@@ -100,15 +100,15 @@ public class ImmutableNode<KEY, VALUE> extends Node<KEY, VALUE> {
100 100
101 @SuppressWarnings("unchecked") 101 @SuppressWarnings("unchecked")
102 @Override 102 @Override
103 public VALUE getValue(KEY key, ContinousHashProvider<? super KEY> hashProvider, VALUE defaultValue, int hash, int depth) { 103 public V getValue(K key, ContinousHashProvider<? super K> hashProvider, V defaultValue, int hash, int depth) {
104 int selectedHashFragment = hashFragment(hash,shiftDepth(depth)); 104 int selectedHashFragment = hashFragment(hash,shiftDepth(depth));
105 int bitposition = 1 << selectedHashFragment; 105 int bitposition = 1 << selectedHashFragment;
106 // If the key is stored as a data 106 // If the key is stored as a data
107 if((dataMap & bitposition) != 0) { 107 if((dataMap & bitposition) != 0) {
108 int keyIndex = 2*index(dataMap, bitposition); 108 int keyIndex = 2*index(dataMap, bitposition);
109 KEY keyCandidate = (KEY) content[keyIndex]; 109 K keyCandidate = (K) content[keyIndex];
110 if(keyCandidate.equals(key)) { 110 if(keyCandidate.equals(key)) {
111 return (VALUE) content[keyIndex+1]; 111 return (V) content[keyIndex+1];
112 } else { 112 } else {
113 return defaultValue; 113 return defaultValue;
114 } 114 }
@@ -116,7 +116,7 @@ public class ImmutableNode<KEY, VALUE> extends Node<KEY, VALUE> {
116 // the key is stored as a node 116 // the key is stored as a node
117 else if((nodeMap & bitposition) != 0) { 117 else if((nodeMap & bitposition) != 0) {
118 int keyIndex = content.length-1-index(nodeMap, bitposition); 118 int keyIndex = content.length-1-index(nodeMap, bitposition);
119 ImmutableNode<KEY,VALUE> subNode = (ImmutableNode<KEY,VALUE>) content[keyIndex]; 119 ImmutableNode<K,V> subNode = (ImmutableNode<K,V>) content[keyIndex];
120 int newDepth = depth+1; 120 int newDepth = depth+1;
121 int newHash = newHash(hashProvider, key, hash, newDepth); 121 int newHash = newHash(hashProvider, key, hash, newDepth);
122 return subNode.getValue(key, hashProvider, defaultValue, newHash, newDepth); 122 return subNode.getValue(key, hashProvider, defaultValue, newHash, newDepth);
@@ -129,25 +129,25 @@ public class ImmutableNode<KEY, VALUE> extends Node<KEY, VALUE> {
129 129
130 @SuppressWarnings("unchecked") 130 @SuppressWarnings("unchecked")
131 @Override 131 @Override
132 public Node<KEY,VALUE> putValue(KEY key, VALUE value, ContinousHashProvider<? super KEY> hashProvider, VALUE defaultValue, int hash, int depth) { 132 public Node<K,V> putValue(K key, V value, ContinousHashProvider<? super K> hashProvider, V defaultValue, int hash, int depth) {
133 int selectedHashFragment = hashFragment(hash,shiftDepth(depth)); 133 int selectedHashFragment = hashFragment(hash,shiftDepth(depth));
134 int bitposition = 1 << selectedHashFragment; 134 int bitposition = 1 << selectedHashFragment;
135 if((dataMap & bitposition) != 0) { 135 if((dataMap & bitposition) != 0) {
136 int keyIndex = 2*index(dataMap, bitposition); 136 int keyIndex = 2*index(dataMap, bitposition);
137 KEY keyCandidate = (KEY) content[keyIndex]; 137 K keyCandidate = (K) content[keyIndex];
138 if(keyCandidate.equals(key)) { 138 if(keyCandidate.equals(key)) {
139 if(value == defaultValue) { 139 if(value == defaultValue) {
140 // delete 140 // delete
141 MutableNode<KEY, VALUE> mutable = this.toMutable(); 141 MutableNode<K, V> mutable = this.toMutable();
142 Node<KEY, VALUE> result = mutable.removeEntry(selectedHashFragment); 142 Node<K, V> result = mutable.removeEntry(selectedHashFragment);
143 return result; 143 return result;
144 } else if(value == content[keyIndex+1]) { 144 } else if(value == content[keyIndex+1]) {
145 // dont change 145 // dont change
146 return this; 146 return this;
147 } else { 147 } else {
148 // update existing value 148 // update existing value
149 MutableNode<KEY, VALUE> mutable = this.toMutable(); 149 MutableNode<K, V> mutable = this.toMutable();
150 Node<KEY, VALUE> result = mutable.updateValue(value, selectedHashFragment); 150 Node<K, V> result = mutable.updateValue(value, selectedHashFragment);
151 return result; 151 return result;
152 } 152 }
153 } else { 153 } else {
@@ -156,31 +156,31 @@ public class ImmutableNode<KEY, VALUE> extends Node<KEY, VALUE> {
156 return this; 156 return this;
157 } else { 157 } else {
158 // add new key + value 158 // add new key + value
159 MutableNode<KEY, VALUE> mutable = this.toMutable(); 159 MutableNode<K, V> mutable = this.toMutable();
160 Node<KEY, VALUE> result = mutable.putValue(key, value, hashProvider, defaultValue, hash, depth); 160 Node<K, V> result = mutable.putValue(key, value, hashProvider, defaultValue, hash, depth);
161 return result; 161 return result;
162 } 162 }
163 } 163 }
164 } else if((nodeMap & bitposition)!=0) { 164 } else if((nodeMap & bitposition)!=0) {
165 165
166 int keyIndex = content.length-1-index(nodeMap, bitposition); 166 int keyIndex = content.length-1-index(nodeMap, bitposition);
167 ImmutableNode<KEY,VALUE> subNode = (ImmutableNode<KEY,VALUE>) content[keyIndex]; 167 ImmutableNode<K,V> subNode = (ImmutableNode<K,V>) content[keyIndex];
168 int newDepth = depth+1; 168 int newDepth = depth+1;
169 int newHash = newHash(hashProvider, key, hash, newDepth); 169 int newHash = newHash(hashProvider, key, hash, newDepth);
170 Node<KEY,VALUE> newsubNode = subNode.putValue(key, value, hashProvider, defaultValue, newHash, newDepth); 170 Node<K,V> newsubNode = subNode.putValue(key, value, hashProvider, defaultValue, newHash, newDepth);
171 171
172 if(subNode == newsubNode) { 172 if(subNode == newsubNode) {
173 // nothing changed 173 // nothing changed
174 return this; 174 return this;
175 } else { 175 } else {
176 MutableNode<KEY, VALUE> mutable = toMutable(); 176 MutableNode<K, V> mutable = toMutable();
177 Node<KEY, VALUE> result = mutable.updateWithSubNode(selectedHashFragment, newsubNode, value.equals(defaultValue)); 177 Node<K, V> result = mutable.updateWithSubNode(selectedHashFragment, newsubNode, value.equals(defaultValue));
178 return result; 178 return result;
179 } 179 }
180 } else { 180 } else {
181 // add new key + value 181 // add new key + value
182 MutableNode<KEY, VALUE> mutable = this.toMutable(); 182 MutableNode<K, V> mutable = this.toMutable();
183 Node<KEY, VALUE> result = mutable.putValue(key, value, hashProvider, defaultValue, hash, depth); 183 Node<K, V> result = mutable.putValue(key, value, hashProvider, defaultValue, hash, depth);
184 return result; 184 return result;
185 } 185 }
186 } 186 }
@@ -191,40 +191,40 @@ public class ImmutableNode<KEY, VALUE> extends Node<KEY, VALUE> {
191 public long getSize() { 191 public long getSize() {
192 int result = Integer.bitCount(this.dataMap); 192 int result = Integer.bitCount(this.dataMap);
193 for(int subnodeIndex = 0; subnodeIndex < Integer.bitCount(this.nodeMap); subnodeIndex++) { 193 for(int subnodeIndex = 0; subnodeIndex < Integer.bitCount(this.nodeMap); subnodeIndex++) {
194 ImmutableNode<KEY,VALUE> subnode = 194 ImmutableNode<K,V> subnode =
195 (ImmutableNode<KEY, VALUE>) this.content[this.content.length-1-subnodeIndex]; 195 (ImmutableNode<K, V>) this.content[this.content.length-1-subnodeIndex];
196 result += subnode.getSize(); 196 result += subnode.getSize();
197 } 197 }
198 return result; 198 return result;
199 } 199 }
200 200
201 @Override 201 @Override
202 protected MutableNode<KEY,VALUE> toMutable() { 202 protected MutableNode<K,V> toMutable() {
203 return new MutableNode<KEY,VALUE>(this); 203 return new MutableNode<K,V>(this);
204 } 204 }
205 205
206 @Override 206 @Override
207 public ImmutableNode<KEY, VALUE> toImmutable( 207 public ImmutableNode<K, V> toImmutable(
208 Map<Node<KEY, VALUE>, ImmutableNode<KEY, VALUE>> cache) { 208 Map<Node<K, V>, ImmutableNode<K, V>> cache) {
209 return this; 209 return this;
210 } 210 }
211 211
212 @Override 212 @Override
213 protected MutableNode<KEY, VALUE> isMutable() { 213 protected MutableNode<K, V> isMutable() {
214 return null; 214 return null;
215 } 215 }
216 216
217 @SuppressWarnings("unchecked") 217 @SuppressWarnings("unchecked")
218 @Override 218 @Override
219 boolean moveToNext(MapCursor<KEY, VALUE> cursor) { 219 boolean moveToNext(MapCursor<K, V> cursor) {
220 // 1. try to move to data 220 // 1. try to move to data
221 int datas = Integer.bitCount(this.dataMap); 221 int datas = Integer.bitCount(this.dataMap);
222 if(cursor.dataIndex != MapCursor.IndexFinish) { 222 if(cursor.dataIndex != MapCursor.IndexFinish) {
223 int newDataIndex = cursor.dataIndex + 1; 223 int newDataIndex = cursor.dataIndex + 1;
224 if(newDataIndex < datas) { 224 if(newDataIndex < datas) {
225 cursor.dataIndex = newDataIndex; 225 cursor.dataIndex = newDataIndex;
226 cursor.key = (KEY) this.content[newDataIndex*2]; 226 cursor.key = (K) this.content[newDataIndex*2];
227 cursor.value = (VALUE) this.content[newDataIndex*2+1]; 227 cursor.value = (V) this.content[newDataIndex*2+1];
228 return true; 228 return true;
229 } else { 229 } else {
230 cursor.dataIndex = MapCursor.IndexFinish; 230 cursor.dataIndex = MapCursor.IndexFinish;
@@ -236,7 +236,7 @@ public class ImmutableNode<KEY, VALUE> extends Node<KEY, VALUE> {
236 int newNodeIndex = cursor.nodeIndexStack.peek() + 1; 236 int newNodeIndex = cursor.nodeIndexStack.peek() + 1;
237 if(newNodeIndex < nodes) { 237 if(newNodeIndex < nodes) {
238 // 2.1 found next subnode, move down to the subnode 238 // 2.1 found next subnode, move down to the subnode
239 Node<KEY, VALUE> subnode = (Node<KEY, VALUE>) this.content[this.content.length-1-newNodeIndex]; 239 Node<K, V> subnode = (Node<K, V>) this.content[this.content.length-1-newNodeIndex];
240 cursor.dataIndex = MapCursor.IndexStart; 240 cursor.dataIndex = MapCursor.IndexStart;
241 cursor.nodeIndexStack.pop(); 241 cursor.nodeIndexStack.pop();
242 cursor.nodeIndexStack.push(newNodeIndex); 242 cursor.nodeIndexStack.push(newNodeIndex);
@@ -248,7 +248,7 @@ public class ImmutableNode<KEY, VALUE> extends Node<KEY, VALUE> {
248 cursor.nodeStack.pop(); 248 cursor.nodeStack.pop();
249 cursor.nodeIndexStack.pop(); 249 cursor.nodeIndexStack.pop();
250 if(!cursor.nodeStack.isEmpty()) { 250 if(!cursor.nodeStack.isEmpty()) {
251 Node<KEY, VALUE> supernode = cursor.nodeStack.peek(); 251 Node<K, V> supernode = cursor.nodeStack.peek();
252 return supernode.moveToNext(cursor); 252 return supernode.moveToNext(cursor);
253 } else { 253 } else {
254 cursor.key = null; 254 cursor.key = null;
@@ -290,7 +290,7 @@ public class ImmutableNode<KEY, VALUE> extends Node<KEY, VALUE> {
290 for(int i = 0; i<factor; i++) { 290 for(int i = 0; i<factor; i++) {
291 if((nodeMask & nodeMap)!=0) { 291 if((nodeMask & nodeMap)!=0) {
292 @SuppressWarnings("unchecked") 292 @SuppressWarnings("unchecked")
293 Node<KEY,VALUE> subNode = (Node<KEY, VALUE>) content[content.length-1-index(nodeMap, nodeMask)]; 293 Node<K,V> subNode = (Node<K, V>) content[content.length-1-index(nodeMap, nodeMask)];
294 builder.append("\n"); 294 builder.append("\n");
295 subNode.prettyPrint(builder, depth+1, i); 295 subNode.prettyPrint(builder, depth+1, i);
296 } 296 }
@@ -300,7 +300,7 @@ public class ImmutableNode<KEY, VALUE> extends Node<KEY, VALUE> {
300 300
301 @SuppressWarnings("unchecked") 301 @SuppressWarnings("unchecked")
302 @Override 302 @Override
303 public void checkIntegrity(ContinousHashProvider<? super KEY> hashProvider, VALUE defaultValue, int depth) { 303 public void checkIntegrity(ContinousHashProvider<? super K> hashProvider, V defaultValue, int depth) {
304 if(depth>0) { 304 if(depth>0) {
305 boolean orphaned = Integer.bitCount(dataMap) == 1 && nodeMap == 0; 305 boolean orphaned = Integer.bitCount(dataMap) == 1 && nodeMap == 0;
306 if(orphaned) { 306 if(orphaned) {
@@ -311,7 +311,7 @@ public class ImmutableNode<KEY, VALUE> extends Node<KEY, VALUE> {
311 311
312 // check subnodes 312 // check subnodes
313 for(int i = 0; i<Integer.bitCount(nodeMap); i++) { 313 for(int i = 0; i<Integer.bitCount(nodeMap); i++) {
314 Node<KEY,VALUE> subnode = (Node<KEY, VALUE>) this.content[this.content.length-1-i]; 314 Node<K,V> subnode = (Node<K, V>) this.content[this.content.length-1-i];
315 if(! (subnode instanceof ImmutableNode<?,?>)) { 315 if(! (subnode instanceof ImmutableNode<?,?>)) {
316 throw new IllegalStateException("Immutable node contains mutable subnodes!"); 316 throw new IllegalStateException("Immutable node contains mutable subnodes!");
317 } else { 317 } else {
diff --git a/model-data/src/main/java/org/eclipse/viatra/solver/data/map/internal/MapCursor.java b/model-data/src/main/java/org/eclipse/viatra/solver/data/map/internal/MapCursor.java
index 6c177611..a18d540d 100644
--- a/model-data/src/main/java/org/eclipse/viatra/solver/data/map/internal/MapCursor.java
+++ b/model-data/src/main/java/org/eclipse/viatra/solver/data/map/internal/MapCursor.java
@@ -8,25 +8,25 @@ import java.util.List;
8import org.eclipse.viatra.solver.data.map.Cursor; 8import org.eclipse.viatra.solver.data.map.Cursor;
9import org.eclipse.viatra.solver.data.map.VersionedMap; 9import org.eclipse.viatra.solver.data.map.VersionedMap;
10 10
11public class MapCursor<KEY,VALUE> implements Cursor<KEY,VALUE> { 11public class MapCursor<K,V> implements Cursor<K,V> {
12 // Constants 12 // Constants
13 static int IndexStart = -1; 13 static int IndexStart = -1;
14 static int IndexFinish = -2; 14 static int IndexFinish = -2;
15 15
16 // Tree stack 16 // Tree stack
17 ArrayDeque<Node<KEY,VALUE>> nodeStack; 17 ArrayDeque<Node<K,V>> nodeStack;
18 ArrayDeque<Integer> nodeIndexStack; 18 ArrayDeque<Integer> nodeIndexStack;
19 int dataIndex; 19 int dataIndex;
20 20
21 // Values 21 // Values
22 KEY key; 22 K key;
23 VALUE value; 23 V value;
24 24
25 // Hash code for checking concurrent modifications 25 // Hash code for checking concurrent modifications
26 final VersionedMap<KEY,VALUE> map; 26 final VersionedMap<K,V> map;
27 final int creationHash; 27 final int creationHash;
28 28
29 public MapCursor(Node<KEY, VALUE> root, VersionedMap<KEY,VALUE> map) { 29 public MapCursor(Node<K, V> root, VersionedMap<K,V> map) {
30 // Initializing tree stack 30 // Initializing tree stack
31 super(); 31 super();
32 this.nodeStack = new ArrayDeque<>(); 32 this.nodeStack = new ArrayDeque<>();
@@ -47,11 +47,11 @@ public class MapCursor<KEY,VALUE> implements Cursor<KEY,VALUE> {
47 this.creationHash = map.hashCode(); 47 this.creationHash = map.hashCode();
48 } 48 }
49 49
50 public KEY getKey() { 50 public K getKey() {
51 return key; 51 return key;
52 } 52 }
53 53
54 public VALUE getValue() { 54 public V getValue() {
55 return value; 55 return value;
56 } 56 }
57 57
@@ -83,13 +83,13 @@ public class MapCursor<KEY,VALUE> implements Cursor<KEY,VALUE> {
83 return this.map.hashCode() != this.creationHash; 83 return this.map.hashCode() != this.creationHash;
84 } 84 }
85 @Override 85 @Override
86 public List<VersionedMap<KEY, VALUE>> getDependingMaps() { 86 public List<VersionedMap<K, V>> getDependingMaps() {
87 return List.of(this.map); 87 return List.of(this.map);
88 } 88 }
89 89
90 public static <KEY,VALUE> boolean sameSubnode(MapCursor<KEY,VALUE> cursor1, MapCursor<KEY,VALUE> cursor2) { 90 public static <K,V> boolean sameSubnode(MapCursor<K,V> cursor1, MapCursor<K,V> cursor2) {
91 Node<KEY, VALUE> nodeOfCursor1 = cursor1.nodeStack.peek(); 91 Node<K, V> nodeOfCursor1 = cursor1.nodeStack.peek();
92 Node<KEY, VALUE> nodeOfCursor2 = cursor2.nodeStack.peek(); 92 Node<K, V> nodeOfCursor2 = cursor2.nodeStack.peek();
93 if(nodeOfCursor1 != null && nodeOfCursor2 != null) { 93 if(nodeOfCursor1 != null && nodeOfCursor2 != null) {
94 return nodeOfCursor1.equals(nodeOfCursor2); 94 return nodeOfCursor1.equals(nodeOfCursor2);
95 } else { 95 } else {
@@ -99,13 +99,13 @@ public class MapCursor<KEY,VALUE> implements Cursor<KEY,VALUE> {
99 99
100 /** 100 /**
101 * 101 *
102 * @param <KEY> 102 * @param <K>
103 * @param <VALUE> 103 * @param <V>
104 * @param cursor1 104 * @param cursor1
105 * @param cursor2 105 * @param cursor2
106 * @returnv Positive number if cursor 1 is behind, negative number if cursor 2 is behind, and 0 if they are at the same position. 106 * @returnv Positive number if cursor 1 is behind, negative number if cursor 2 is behind, and 0 if they are at the same position.
107 */ 107 */
108 public static <KEY,VALUE> int compare(MapCursor<KEY,VALUE> cursor1, MapCursor<KEY,VALUE> cursor2) { 108 public static <K,V> int compare(MapCursor<K,V> cursor1, MapCursor<K,V> cursor2) {
109 // two cursors are equally deep 109 // two cursors are equally deep
110 Iterator<Integer> stack1 = cursor1.nodeIndexStack.descendingIterator(); 110 Iterator<Integer> stack1 = cursor1.nodeIndexStack.descendingIterator();
111 Iterator<Integer> stack2 = cursor2.nodeIndexStack.descendingIterator(); 111 Iterator<Integer> stack2 = cursor2.nodeIndexStack.descendingIterator();
diff --git a/model-data/src/main/java/org/eclipse/viatra/solver/data/map/internal/MapDiffCursor.java b/model-data/src/main/java/org/eclipse/viatra/solver/data/map/internal/MapDiffCursor.java
index 8d7cda14..9e3a47ab 100644
--- a/model-data/src/main/java/org/eclipse/viatra/solver/data/map/internal/MapDiffCursor.java
+++ b/model-data/src/main/java/org/eclipse/viatra/solver/data/map/internal/MapDiffCursor.java
@@ -14,19 +14,19 @@ import org.eclipse.viatra.solver.data.map.VersionedMap;
14 * @author Oszkar Semerath 14 * @author Oszkar Semerath
15 * 15 *
16 */ 16 */
17public class MapDiffCursor<KEY,VALUE> implements DiffCursor<KEY, VALUE>, Cursor<KEY,VALUE>{ 17public class MapDiffCursor<K,V> implements DiffCursor<K, V>, Cursor<K,V>{
18 /** 18 /**
19 * Default value representing missing elements. 19 * Default value representing missing elements.
20 */ 20 */
21 private VALUE defaultValue; 21 private V defaultValue;
22 private MapCursor<KEY,VALUE> cursor1; 22 private MapCursor<K,V> cursor1;
23 private MapCursor<KEY,VALUE> cursor2; 23 private MapCursor<K,V> cursor2;
24 private ContinousHashProvider<? super KEY> hashProvider; 24 private ContinousHashProvider<? super K> hashProvider;
25 25
26 // Values 26 // Values
27 private KEY key; 27 private K key;
28 private VALUE fromValue; 28 private V fromValue;
29 private VALUE toValue; 29 private V toValue;
30 30
31 // State 31 // State
32 /** 32 /**
@@ -44,25 +44,25 @@ public class MapDiffCursor<KEY,VALUE> implements DiffCursor<KEY, VALUE>, Cursor<
44 */ 44 */
45 private int hashClash=0; 45 private int hashClash=0;
46 46
47 public MapDiffCursor(ContinousHashProvider<? super KEY> hashProvider, VALUE defaultValue, Cursor<KEY, VALUE> cursor1, Cursor<KEY, VALUE> cursor2) { 47 public MapDiffCursor(ContinousHashProvider<? super K> hashProvider, V defaultValue, Cursor<K, V> cursor1, Cursor<K, V> cursor2) {
48 super(); 48 super();
49 this.hashProvider = hashProvider; 49 this.hashProvider = hashProvider;
50 this.defaultValue = defaultValue; 50 this.defaultValue = defaultValue;
51 this.cursor1 = (MapCursor<KEY, VALUE>) cursor1; 51 this.cursor1 = (MapCursor<K, V>) cursor1;
52 this.cursor2 = (MapCursor<KEY, VALUE>) cursor2; 52 this.cursor2 = (MapCursor<K, V>) cursor2;
53 } 53 }
54 54
55 public KEY getKey() { 55 public K getKey() {
56 return key; 56 return key;
57 } 57 }
58 public VALUE getFromValue() { 58 public V getFromValue() {
59 return fromValue; 59 return fromValue;
60 } 60 }
61 public VALUE getToValue() { 61 public V getToValue() {
62 return toValue; 62 return toValue;
63 } 63 }
64 @Override 64 @Override
65 public VALUE getValue() { 65 public V getValue() {
66 return getToValue(); 66 return getToValue();
67 } 67 }
68 public boolean isTerminated() { 68 public boolean isTerminated() {
@@ -73,7 +73,7 @@ public class MapDiffCursor<KEY,VALUE> implements DiffCursor<KEY, VALUE>, Cursor<
73 return this.cursor1.isDirty() || this.cursor2.isDirty(); 73 return this.cursor1.isDirty() || this.cursor2.isDirty();
74 } 74 }
75 @Override 75 @Override
76 public List<VersionedMap<KEY, VALUE>> getDependingMaps() { 76 public List<VersionedMap<K, V>> getDependingMaps() {
77 return Stream.concat( 77 return Stream.concat(
78 cursor1.getDependingMaps().stream(), 78 cursor1.getDependingMaps().stream(),
79 cursor2.getDependingMaps().stream() 79 cursor2.getDependingMaps().stream()
diff --git a/model-data/src/main/java/org/eclipse/viatra/solver/data/map/internal/MutableNode.java b/model-data/src/main/java/org/eclipse/viatra/solver/data/map/internal/MutableNode.java
index f28405da..322e2128 100644
--- a/model-data/src/main/java/org/eclipse/viatra/solver/data/map/internal/MutableNode.java
+++ b/model-data/src/main/java/org/eclipse/viatra/solver/data/map/internal/MutableNode.java
@@ -5,7 +5,7 @@ import java.util.Map;
5 5
6import org.eclipse.viatra.solver.data.map.ContinousHashProvider; 6import org.eclipse.viatra.solver.data.map.ContinousHashProvider;
7 7
8public class MutableNode<KEY, VALUE> extends Node<KEY, VALUE> { 8public class MutableNode<K, V> extends Node<K, V> {
9 int cachedHash; 9 int cachedHash;
10 protected Object[] content; 10 protected Object[] content;
11 11
@@ -14,14 +14,14 @@ public class MutableNode<KEY, VALUE> extends Node<KEY, VALUE> {
14 updateHash(); 14 updateHash();
15 } 15 }
16 16
17 public static <KEY, VALUE> MutableNode<KEY, VALUE> initialize(KEY key, VALUE value, 17 public static <K, V> MutableNode<K, V> initialize(K key, V value,
18 ContinousHashProvider<? super KEY> hashProvider, VALUE defaultValue) { 18 ContinousHashProvider<? super K> hashProvider, V defaultValue) {
19 if (value == defaultValue) { 19 if (value == defaultValue) {
20 return null; 20 return null;
21 } else { 21 } else {
22 int hash = hashProvider.getHash(key, 0); 22 int hash = hashProvider.getHash(key, 0);
23 int fragment = hashFragment(hash, 0); 23 int fragment = hashFragment(hash, 0);
24 MutableNode<KEY, VALUE> res = new MutableNode<KEY, VALUE>(); 24 MutableNode<K, V> res = new MutableNode<K, V>();
25 res.content[2 * fragment] = key; 25 res.content[2 * fragment] = key;
26 res.content[2 * fragment + 1] = value; 26 res.content[2 * fragment + 1] = value;
27 res.updateHash(); 27 res.updateHash();
@@ -34,7 +34,7 @@ public class MutableNode<KEY, VALUE> extends Node<KEY, VALUE> {
34 * 34 *
35 * @param node 35 * @param node
36 */ 36 */
37 protected MutableNode(ImmutableNode<KEY, VALUE> node) { 37 protected MutableNode(ImmutableNode<K, V> node) {
38 this.content = new Object[2 * factor]; 38 this.content = new Object[2 * factor];
39 int dataUsed = 0; 39 int dataUsed = 0;
40 int nodeUsed = 0; 40 int nodeUsed = 0;
@@ -54,18 +54,18 @@ public class MutableNode<KEY, VALUE> extends Node<KEY, VALUE> {
54 54
55 @SuppressWarnings("unchecked") 55 @SuppressWarnings("unchecked")
56 @Override 56 @Override
57 public VALUE getValue(KEY key, ContinousHashProvider<? super KEY> hashProvider, VALUE defaultValue, int hash, 57 public V getValue(K key, ContinousHashProvider<? super K> hashProvider, V defaultValue, int hash,
58 int depth) { 58 int depth) {
59 int selectedHashFragment = hashFragment(hash, shiftDepth(depth)); 59 int selectedHashFragment = hashFragment(hash, shiftDepth(depth));
60 KEY keyCandidate = (KEY) this.content[2 * selectedHashFragment]; 60 K keyCandidate = (K) this.content[2 * selectedHashFragment];
61 if (keyCandidate != null) { 61 if (keyCandidate != null) {
62 if (keyCandidate.equals(key)) { 62 if (keyCandidate.equals(key)) {
63 return (VALUE) this.content[2 * selectedHashFragment + 1]; 63 return (V) this.content[2 * selectedHashFragment + 1];
64 } else { 64 } else {
65 return defaultValue; 65 return defaultValue;
66 } 66 }
67 } else { 67 } else {
68 Node<KEY, VALUE> nodeCandidate = (Node<KEY, VALUE>) content[2 * selectedHashFragment + 1]; 68 Node<K, V> nodeCandidate = (Node<K, V>) content[2 * selectedHashFragment + 1];
69 if (nodeCandidate != null) { 69 if (nodeCandidate != null) {
70 int newDepth = depth + 1; 70 int newDepth = depth + 1;
71 int newHash = newHash(hashProvider, key, hash, newDepth); 71 int newHash = newHash(hashProvider, key, hash, newDepth);
@@ -78,10 +78,10 @@ public class MutableNode<KEY, VALUE> extends Node<KEY, VALUE> {
78 78
79 @SuppressWarnings("unchecked") 79 @SuppressWarnings("unchecked")
80 @Override 80 @Override
81 public Node<KEY, VALUE> putValue(KEY key, VALUE value, ContinousHashProvider<? super KEY> hashProvider, 81 public Node<K, V> putValue(K key, V value, ContinousHashProvider<? super K> hashProvider,
82 VALUE defaultValue, int hash, int depth) { 82 V defaultValue, int hash, int depth) {
83 int selectedHashFragment = hashFragment(hash, shiftDepth(depth)); 83 int selectedHashFragment = hashFragment(hash, shiftDepth(depth));
84 KEY keyCandidate = (KEY) content[2 * selectedHashFragment]; 84 K keyCandidate = (K) content[2 * selectedHashFragment];
85 if (keyCandidate != null) { 85 if (keyCandidate != null) {
86 // If has key 86 // If has key
87 if (keyCandidate.equals(key)) { 87 if (keyCandidate.equals(key)) {
@@ -104,10 +104,10 @@ public class MutableNode<KEY, VALUE> extends Node<KEY, VALUE> {
104 } 104 }
105 } else { 105 } else {
106 // If it does not have key, check for value 106 // If it does not have key, check for value
107 Node<KEY, VALUE> nodeCandidate = (Node<KEY, VALUE>) content[2 * selectedHashFragment + 1]; 107 Node<K, V> nodeCandidate = (Node<K, V>) content[2 * selectedHashFragment + 1];
108 if (nodeCandidate != null) { 108 if (nodeCandidate != null) {
109 // If it has value, it is a subnode -> upate that 109 // If it has value, it is a subnode -> upate that
110 Node<KEY, VALUE> newNode = nodeCandidate.putValue(key, value, hashProvider, defaultValue, 110 Node<K, V> newNode = nodeCandidate.putValue(key, value, hashProvider, defaultValue,
111 newHash(hashProvider, key, hash, depth + 1), depth + 1); 111 newHash(hashProvider, key, hash, depth + 1), depth + 1);
112 return updateWithSubNode(selectedHashFragment, newNode, value.equals(defaultValue)); 112 return updateWithSubNode(selectedHashFragment, newNode, value.equals(defaultValue));
113 } else { 113 } else {
@@ -123,7 +123,7 @@ public class MutableNode<KEY, VALUE> extends Node<KEY, VALUE> {
123 } 123 }
124 } 124 }
125 125
126 private Node<KEY, VALUE> addEntry(KEY key, VALUE value, int selectedHashFragment) { 126 private Node<K, V> addEntry(K key, V value, int selectedHashFragment) {
127 content[2 * selectedHashFragment] = key; 127 content[2 * selectedHashFragment] = key;
128 content[2 * selectedHashFragment + 1] = value; 128 content[2 * selectedHashFragment + 1] = value;
129 updateHash(); 129 updateHash();
@@ -137,7 +137,7 @@ public class MutableNode<KEY, VALUE> extends Node<KEY, VALUE> {
137 * @param selectedHashFragment 137 * @param selectedHashFragment
138 * @return 138 * @return
139 */ 139 */
140 Node<KEY, VALUE> updateValue(VALUE value, int selectedHashFragment) { 140 Node<K, V> updateValue(V value, int selectedHashFragment) {
141 content[2 * selectedHashFragment + 1] = value; 141 content[2 * selectedHashFragment + 1] = value;
142 updateHash(); 142 updateHash();
143 return this; 143 return this;
@@ -149,7 +149,7 @@ public class MutableNode<KEY, VALUE> extends Node<KEY, VALUE> {
149 * @param newNode 149 * @param newNode
150 * @return 150 * @return
151 */ 151 */
152 Node<KEY, VALUE> updateWithSubNode(int selectedHashFragment, Node<KEY, VALUE> newNode, boolean deletionHappened) { 152 Node<K, V> updateWithSubNode(int selectedHashFragment, Node<K, V> newNode, boolean deletionHappened) {
153 if (deletionHappened) { 153 if (deletionHappened) {
154 if (newNode == null) { 154 if (newNode == null) {
155 // Check whether this node become empty 155 // Check whether this node become empty
@@ -162,7 +162,7 @@ public class MutableNode<KEY, VALUE> extends Node<KEY, VALUE> {
162 } 162 }
163 } else { 163 } else {
164 // check whether newNode is orphan; 164 // check whether newNode is orphan;
165 MutableNode<KEY, VALUE> immutableNewNode = newNode.isMutable(); 165 MutableNode<K, V> immutableNewNode = newNode.isMutable();
166 if (immutableNewNode != null) { 166 if (immutableNewNode != null) {
167 int orphaned = immutableNewNode.isOrphaned(); 167 int orphaned = immutableNewNode.isOrphaned();
168 if (orphaned >= 0) { 168 if (orphaned >= 0) {
@@ -191,7 +191,7 @@ public class MutableNode<KEY, VALUE> extends Node<KEY, VALUE> {
191 } 191 }
192 192
193 @Override 193 @Override
194 protected MutableNode<KEY, VALUE> isMutable() { 194 protected MutableNode<K, V> isMutable() {
195 return this; 195 return this;
196 } 196 }
197 197
@@ -212,12 +212,12 @@ public class MutableNode<KEY, VALUE> extends Node<KEY, VALUE> {
212 } 212 }
213 213
214 @SuppressWarnings("unchecked") 214 @SuppressWarnings("unchecked")
215 private Node<KEY, VALUE> moveDownAndSplit(ContinousHashProvider<? super KEY> hashProvider, KEY newKey, 215 private Node<K, V> moveDownAndSplit(ContinousHashProvider<? super K> hashProvider, K newKey,
216 VALUE newValue, KEY previousKey, int hashOfNewKey, int depth, int selectedHashFragmentOfCurrentDepth) { 216 V newValue, K previousKey, int hashOfNewKey, int depth, int selectedHashFragmentOfCurrentDepth) {
217 VALUE previousValue = (VALUE) content[2 * selectedHashFragmentOfCurrentDepth + 1]; 217 V previousValue = (V) content[2 * selectedHashFragmentOfCurrentDepth + 1];
218 218
219 // final int newHash = newHash(hashProvider, newKey, hashOfNewKey, newDepth); 219 // final int newHash = newHash(hashProvider, newKey, hashOfNewKey, newDepth);
220 MutableNode<KEY, VALUE> newSubNode = newNodeWithTwoEntries(hashProvider, previousKey, previousValue, 220 MutableNode<K, V> newSubNode = newNodeWithTwoEntries(hashProvider, previousKey, previousValue,
221 hashProvider.getHash(previousKey, hashDepth(depth)), newKey, newValue, hashOfNewKey, depth + 1); 221 hashProvider.getHash(previousKey, hashDepth(depth)), newKey, newValue, hashOfNewKey, depth + 1);
222 222
223 content[2 * selectedHashFragmentOfCurrentDepth] = null; 223 content[2 * selectedHashFragmentOfCurrentDepth] = null;
@@ -226,8 +226,8 @@ public class MutableNode<KEY, VALUE> extends Node<KEY, VALUE> {
226 return this; 226 return this;
227 } 227 }
228 228
229 private MutableNode<KEY, VALUE> newNodeWithTwoEntries(ContinousHashProvider<? super KEY> hashProvider, KEY key1, 229 private MutableNode<K, V> newNodeWithTwoEntries(ContinousHashProvider<? super K> hashProvider, K key1,
230 VALUE value1, int oldHash1, KEY key2, VALUE value2, int oldHash2, int newdepth) { 230 V value1, int oldHash1, K key2, V value2, int oldHash2, int newdepth) {
231// final int depthLimit = 4000; 231// final int depthLimit = 4000;
232// if(newdepth>depthLimit) { 232// if(newdepth>depthLimit) {
233// final int newHashes = 4000/numberOfFactors; 233// final int newHashes = 4000/numberOfFactors;
@@ -239,7 +239,7 @@ public class MutableNode<KEY, VALUE> extends Node<KEY, VALUE> {
239 int newFragment1 = hashFragment(newHash1, shiftDepth(newdepth)); 239 int newFragment1 = hashFragment(newHash1, shiftDepth(newdepth));
240 int newFragment2 = hashFragment(newHash2, shiftDepth(newdepth)); 240 int newFragment2 = hashFragment(newHash2, shiftDepth(newdepth));
241 241
242 MutableNode<KEY, VALUE> subNode = new MutableNode<KEY, VALUE>(); 242 MutableNode<K, V> subNode = new MutableNode<K, V>();
243 if (newFragment1 != newFragment2) { 243 if (newFragment1 != newFragment2) {
244 subNode.content[newFragment1 * 2] = key1; 244 subNode.content[newFragment1 * 2] = key1;
245 subNode.content[newFragment1 * 2 + 1] = value1; 245 subNode.content[newFragment1 * 2 + 1] = value1;
@@ -247,7 +247,7 @@ public class MutableNode<KEY, VALUE> extends Node<KEY, VALUE> {
247 subNode.content[newFragment2 * 2] = key2; 247 subNode.content[newFragment2 * 2] = key2;
248 subNode.content[newFragment2 * 2 + 1] = value2; 248 subNode.content[newFragment2 * 2 + 1] = value2;
249 } else { 249 } else {
250 MutableNode<KEY, VALUE> subSubNode = newNodeWithTwoEntries(hashProvider, key1, value1, newHash1, key2, 250 MutableNode<K, V> subSubNode = newNodeWithTwoEntries(hashProvider, key1, value1, newHash1, key2,
251 value2, newHash2, newdepth + 1); 251 value2, newHash2, newdepth + 1);
252 subNode.content[newFragment1 * 2 + 1] = subSubNode; 252 subNode.content[newFragment1 * 2 + 1] = subSubNode;
253 } 253 }
@@ -255,7 +255,7 @@ public class MutableNode<KEY, VALUE> extends Node<KEY, VALUE> {
255 return subNode; 255 return subNode;
256 } 256 }
257 257
258 Node<KEY, VALUE> removeEntry(int selectedHashFragment) { 258 Node<K, V> removeEntry(int selectedHashFragment) {
259 content[2 * selectedHashFragment] = null; 259 content[2 * selectedHashFragment] = null;
260 content[2 * selectedHashFragment + 1] = null; 260 content[2 * selectedHashFragment + 1] = null;
261 if (hasContent()) { 261 if (hasContent()) {
@@ -274,7 +274,7 @@ public class MutableNode<KEY, VALUE> extends Node<KEY, VALUE> {
274 if (content[i * 2] != null) { 274 if (content[i * 2] != null) {
275 size++; 275 size++;
276 } else { 276 } else {
277 Node<KEY, VALUE> nodeCandidate = (Node<KEY, VALUE>) content[i * 2 + 1]; 277 Node<K, V> nodeCandidate = (Node<K, V>) content[i * 2 + 1];
278 if (nodeCandidate != null) { 278 if (nodeCandidate != null) {
279 size += nodeCandidate.getSize(); 279 size += nodeCandidate.getSize();
280 } 280 }
@@ -284,26 +284,26 @@ public class MutableNode<KEY, VALUE> extends Node<KEY, VALUE> {
284 } 284 }
285 285
286 @Override 286 @Override
287 protected MutableNode<KEY, VALUE> toMutable() { 287 protected MutableNode<K, V> toMutable() {
288 return this; 288 return this;
289 } 289 }
290 290
291 @Override 291 @Override
292 public ImmutableNode<KEY, VALUE> toImmutable(Map<Node<KEY, VALUE>, ImmutableNode<KEY, VALUE>> cache) { 292 public ImmutableNode<K, V> toImmutable(Map<Node<K, V>, ImmutableNode<K, V>> cache) {
293 return ImmutableNode.constructImmutable(this, cache); 293 return ImmutableNode.constructImmutable(this, cache);
294 } 294 }
295 295
296 @SuppressWarnings("unchecked") 296 @SuppressWarnings("unchecked")
297 @Override 297 @Override
298 boolean moveToNext(MapCursor<KEY, VALUE> cursor) { 298 boolean moveToNext(MapCursor<K, V> cursor) {
299 // 1. try to move to data 299 // 1. try to move to data
300 if (cursor.dataIndex != MapCursor.IndexFinish) { 300 if (cursor.dataIndex != MapCursor.IndexFinish) {
301 for (int index = cursor.dataIndex + 1; index < factor; index++) { 301 for (int index = cursor.dataIndex + 1; index < factor; index++) {
302 if (this.content[index * 2] != null) { 302 if (this.content[index * 2] != null) {
303 // 1.1 found next data 303 // 1.1 found next data
304 cursor.dataIndex = index; 304 cursor.dataIndex = index;
305 cursor.key = (KEY) this.content[index * 2]; 305 cursor.key = (K) this.content[index * 2];
306 cursor.value = (VALUE) this.content[index * 2 + 1]; 306 cursor.value = (V) this.content[index * 2 + 1];
307 return true; 307 return true;
308 } 308 }
309 } 309 }
@@ -314,7 +314,7 @@ public class MutableNode<KEY, VALUE> extends Node<KEY, VALUE> {
314 for (int index = cursor.nodeIndexStack.peek() + 1; index < factor; index++) { 314 for (int index = cursor.nodeIndexStack.peek() + 1; index < factor; index++) {
315 if (this.content[index * 2] == null && this.content[index * 2 + 1] != null) { 315 if (this.content[index * 2] == null && this.content[index * 2 + 1] != null) {
316 // 2.1 found next subnode, move down to the subnode 316 // 2.1 found next subnode, move down to the subnode
317 Node<KEY, VALUE> subnode = (Node<KEY, VALUE>) this.content[index * 2 + 1]; 317 Node<K, V> subnode = (Node<K, V>) this.content[index * 2 + 1];
318 318
319 cursor.dataIndex = MapCursor.IndexStart; 319 cursor.dataIndex = MapCursor.IndexStart;
320 cursor.nodeIndexStack.pop(); 320 cursor.nodeIndexStack.pop();
@@ -329,7 +329,7 @@ public class MutableNode<KEY, VALUE> extends Node<KEY, VALUE> {
329 cursor.nodeStack.pop(); 329 cursor.nodeStack.pop();
330 cursor.nodeIndexStack.pop(); 330 cursor.nodeIndexStack.pop();
331 if (!cursor.nodeStack.isEmpty()) { 331 if (!cursor.nodeStack.isEmpty()) {
332 Node<KEY, VALUE> supernode = cursor.nodeStack.peek(); 332 Node<K, V> supernode = cursor.nodeStack.peek();
333 return supernode.moveToNext(cursor); 333 return supernode.moveToNext(cursor);
334 } else { 334 } else {
335 cursor.key = null; 335 cursor.key = null;
@@ -369,7 +369,7 @@ public class MutableNode<KEY, VALUE> extends Node<KEY, VALUE> {
369 for (int i = 0; i < factor; i++) { 369 for (int i = 0; i < factor; i++) {
370 if (content[2 * i] == null && content[2 * i + 1] != null) { 370 if (content[2 * i] == null && content[2 * i + 1] != null) {
371 @SuppressWarnings("unchecked") 371 @SuppressWarnings("unchecked")
372 Node<KEY, VALUE> subNode = (Node<KEY, VALUE>) content[2 * i + 1]; 372 Node<K, V> subNode = (Node<K, V>) content[2 * i + 1];
373 builder.append("\n"); 373 builder.append("\n");
374 subNode.prettyPrint(builder, depth + 1, i); 374 subNode.prettyPrint(builder, depth + 1, i);
375 } 375 }
@@ -378,7 +378,7 @@ public class MutableNode<KEY, VALUE> extends Node<KEY, VALUE> {
378 378
379 @SuppressWarnings({ "unchecked" }) 379 @SuppressWarnings({ "unchecked" })
380 @Override 380 @Override
381 public void checkIntegrity(ContinousHashProvider<? super KEY> hashProvider, VALUE defaultValue, int depth) { 381 public void checkIntegrity(ContinousHashProvider<? super K> hashProvider, V defaultValue, int depth) {
382 // check for orphan nodes 382 // check for orphan nodes
383 if(depth>0) { 383 if(depth>0) {
384 int orphaned = isOrphaned(); 384 int orphaned = isOrphaned();
@@ -389,8 +389,8 @@ public class MutableNode<KEY, VALUE> extends Node<KEY, VALUE> {
389 // check the place of data 389 // check the place of data
390 for (int i = 0; i < factor; i++) { 390 for (int i = 0; i < factor; i++) {
391 if (this.content[2 * i] != null) { 391 if (this.content[2 * i] != null) {
392 KEY key = (KEY) this.content[2 * i]; 392 K key = (K) this.content[2 * i];
393 VALUE value = (VALUE) this.content[2 * i + 1]; 393 V value = (V) this.content[2 * i + 1];
394 394
395 if (value == defaultValue) { 395 if (value == defaultValue) {
396 throw new IllegalStateException("Node contains default value!"); 396 throw new IllegalStateException("Node contains default value!");
@@ -407,7 +407,7 @@ public class MutableNode<KEY, VALUE> extends Node<KEY, VALUE> {
407 // check subnodes 407 // check subnodes
408 for (int i = 0; i < factor; i++) { 408 for (int i = 0; i < factor; i++) {
409 if (this.content[2 * i + 1] != null && this.content[2 * i] == null) { 409 if (this.content[2 * i + 1] != null && this.content[2 * i] == null) {
410 Node<KEY, VALUE> subNode = (Node<KEY, VALUE>) this.content[2 * i + 1]; 410 Node<K, V> subNode = (Node<K, V>) this.content[2 * i + 1];
411 subNode.checkIntegrity(hashProvider, defaultValue, depth + 1); 411 subNode.checkIntegrity(hashProvider, defaultValue, depth + 1);
412 } 412 }
413 } 413 }
diff --git a/model-data/src/main/java/org/eclipse/viatra/solver/data/map/internal/Node.java b/model-data/src/main/java/org/eclipse/viatra/solver/data/map/internal/Node.java
index 2176af87..f1efaa76 100644
--- a/model-data/src/main/java/org/eclipse/viatra/solver/data/map/internal/Node.java
+++ b/model-data/src/main/java/org/eclipse/viatra/solver/data/map/internal/Node.java
@@ -4,7 +4,7 @@ import java.util.Map;
4 4
5import org.eclipse.viatra.solver.data.map.ContinousHashProvider; 5import org.eclipse.viatra.solver.data.map.ContinousHashProvider;
6 6
7public abstract class Node<KEY,VALUE>{ 7public abstract class Node<K,V>{
8 public static final int branchingFactorBit = 5; 8 public static final int branchingFactorBit = 5;
9 public static final int factor = 1<<branchingFactorBit; 9 public static final int factor = 1<<branchingFactorBit;
10 protected static final int numberOfFactors = Integer.SIZE / branchingFactorBit; 10 protected static final int numberOfFactors = Integer.SIZE / branchingFactorBit;
@@ -46,7 +46,7 @@ public abstract class Node<KEY,VALUE>{
46 * @param depth The depth. 46 * @param depth The depth.
47 * @return The new hash code. 47 * @return The new hash code.
48 */ 48 */
49 protected int newHash(final ContinousHashProvider<? super KEY> hashProvider, KEY key, int hash, int depth) { 49 protected int newHash(final ContinousHashProvider<? super K> hashProvider, K key, int hash, int depth) {
50 final int hashDepth = hashDepth(depth); 50 final int hashDepth = hashDepth(depth);
51 if(hashDepth>=ContinousHashProvider.MAX_PRACTICAL_DEPTH) { 51 if(hashDepth>=ContinousHashProvider.MAX_PRACTICAL_DEPTH) {
52 throw new IllegalArgumentException("Key "+key+" have the clashing hashcode over the practical depth limitation ("+ContinousHashProvider.MAX_PRACTICAL_DEPTH+")!"); 52 throw new IllegalArgumentException("Key "+key+" have the clashing hashcode over the practical depth limitation ("+ContinousHashProvider.MAX_PRACTICAL_DEPTH+")!");
@@ -57,20 +57,20 @@ public abstract class Node<KEY,VALUE>{
57 } 57 }
58 58
59 59
60 abstract public VALUE getValue(KEY key, ContinousHashProvider<? super KEY> hashProvider, VALUE defaultValue, int hash, int depth); 60 abstract public V getValue(K key, ContinousHashProvider<? super K> hashProvider, V defaultValue, int hash, int depth);
61 abstract public Node<KEY,VALUE> putValue(KEY key, VALUE value, ContinousHashProvider<? super KEY> hashProvider, VALUE defaultValue, int hash, int depth); 61 abstract public Node<K,V> putValue(K key, V value, ContinousHashProvider<? super K> hashProvider, V defaultValue, int hash, int depth);
62 abstract public long getSize(); 62 abstract public long getSize();
63 63
64 abstract MutableNode<KEY, VALUE> toMutable(); 64 abstract MutableNode<K, V> toMutable();
65 public abstract ImmutableNode<KEY, VALUE> toImmutable( 65 public abstract ImmutableNode<K, V> toImmutable(
66 Map<Node<KEY, VALUE>,ImmutableNode<KEY, VALUE>> cache); 66 Map<Node<K, V>,ImmutableNode<K, V>> cache);
67 protected abstract MutableNode<KEY, VALUE> isMutable(); 67 protected abstract MutableNode<K, V> isMutable();
68 /** 68 /**
69 * Moves a {@link MapCursor} to its next position. 69 * Moves a {@link MapCursor} to its next position.
70 * @param cursor the cursor 70 * @param cursor the cursor
71 * @return Whether there was a next value to move on. 71 * @return Whether there was a next value to move on.
72 */ 72 */
73 abstract boolean moveToNext(MapCursor<KEY,VALUE> cursor); 73 abstract boolean moveToNext(MapCursor<K,V> cursor);
74 74
75 ///////// FOR printing 75 ///////// FOR printing
76 abstract public void prettyPrint(StringBuilder builder, int depth, int code); 76 abstract public void prettyPrint(StringBuilder builder, int depth, int code);
@@ -80,6 +80,6 @@ public abstract class Node<KEY,VALUE>{
80 prettyPrint(stringBuilder, 0, -1); 80 prettyPrint(stringBuilder, 0, -1);
81 return stringBuilder.toString(); 81 return stringBuilder.toString();
82 } 82 }
83 public void checkIntegrity(ContinousHashProvider<? super KEY> hashProvider, VALUE defaultValue, int depth) {} 83 public void checkIntegrity(ContinousHashProvider<? super K> hashProvider, V defaultValue, int depth) {}
84 84
85} 85}
diff --git a/model-data/src/main/java/org/eclipse/viatra/solver/data/map/internal/VersionedMapImpl.java b/model-data/src/main/java/org/eclipse/viatra/solver/data/map/internal/VersionedMapImpl.java
index 715a9d74..d04e7117 100644
--- a/model-data/src/main/java/org/eclipse/viatra/solver/data/map/internal/VersionedMapImpl.java
+++ b/model-data/src/main/java/org/eclipse/viatra/solver/data/map/internal/VersionedMapImpl.java
@@ -14,20 +14,20 @@ import org.eclipse.viatra.solver.data.map.VersionedMapStoreImpl;
14 * Not threadSafe in itself 14 * Not threadSafe in itself
15 * @author Oszkar Semerath 15 * @author Oszkar Semerath
16 * 16 *
17 * @param <KEY> 17 * @param <K>
18 * @param <VALUE> 18 * @param <V>
19 */ 19 */
20public class VersionedMapImpl<KEY,VALUE> implements VersionedMap<KEY,VALUE>{ 20public class VersionedMapImpl<K,V> implements VersionedMap<K,V>{
21 protected final VersionedMapStoreImpl<KEY,VALUE> store; 21 protected final VersionedMapStoreImpl<K,V> store;
22 22
23 protected final ContinousHashProvider<? super KEY> hashProvider; 23 protected final ContinousHashProvider<? super K> hashProvider;
24 protected final VALUE defaultValue; 24 protected final V defaultValue;
25 protected Node<KEY,VALUE> root; 25 protected Node<K,V> root;
26 26
27 public VersionedMapImpl( 27 public VersionedMapImpl(
28 VersionedMapStoreImpl<KEY,VALUE> store, 28 VersionedMapStoreImpl<K,V> store,
29 ContinousHashProvider<? super KEY> hashProvider, 29 ContinousHashProvider<? super K> hashProvider,
30 VALUE defaultValue) 30 V defaultValue)
31 { 31 {
32 this.store = store; 32 this.store = store;
33 this.hashProvider = hashProvider; 33 this.hashProvider = hashProvider;
@@ -35,9 +35,9 @@ public class VersionedMapImpl<KEY,VALUE> implements VersionedMap<KEY,VALUE>{
35 this.root = null; 35 this.root = null;
36 } 36 }
37 public VersionedMapImpl( 37 public VersionedMapImpl(
38 VersionedMapStoreImpl<KEY,VALUE> store, 38 VersionedMapStoreImpl<K,V> store,
39 ContinousHashProvider<? super KEY> hashProvider, 39 ContinousHashProvider<? super K> hashProvider,
40 VALUE defaultValue, Node<KEY,VALUE> data) 40 V defaultValue, Node<K,V> data)
41 { 41 {
42 this.store = store; 42 this.store = store;
43 this.hashProvider = hashProvider; 43 this.hashProvider = hashProvider;
@@ -45,14 +45,14 @@ public class VersionedMapImpl<KEY,VALUE> implements VersionedMap<KEY,VALUE>{
45 this.root = data; 45 this.root = data;
46 } 46 }
47 47
48 public VALUE getDefaultValue() { 48 public V getDefaultValue() {
49 return defaultValue; 49 return defaultValue;
50 } 50 }
51 public ContinousHashProvider<? super KEY> getHashProvider() { 51 public ContinousHashProvider<? super K> getHashProvider() {
52 return hashProvider; 52 return hashProvider;
53 } 53 }
54 @Override 54 @Override
55 public void put(KEY key, VALUE value) { 55 public void put(K key, V value) {
56 if(root!=null) { 56 if(root!=null) {
57 root = root.putValue(key, value, hashProvider, defaultValue, hashProvider.getHash(key, 0), 0); 57 root = root.putValue(key, value, hashProvider, defaultValue, hashProvider.getHash(key, 0), 0);
58 } else { 58 } else {
@@ -61,16 +61,16 @@ public class VersionedMapImpl<KEY,VALUE> implements VersionedMap<KEY,VALUE>{
61 } 61 }
62 62
63 @Override 63 @Override
64 public void putAll(Cursor<KEY, VALUE> cursor) { 64 public void putAll(Cursor<K, V> cursor) {
65 if(cursor.getDependingMaps().contains(this)) { 65 if(cursor.getDependingMaps().contains(this)) {
66 List<KEY> keys = new LinkedList<>(); 66 List<K> keys = new LinkedList<>();
67 List<VALUE> values = new LinkedList<>(); 67 List<V> values = new LinkedList<>();
68 while(cursor.move()) { 68 while(cursor.move()) {
69 keys.add(cursor.getKey()); 69 keys.add(cursor.getKey());
70 values.add(cursor.getValue()); 70 values.add(cursor.getValue());
71 } 71 }
72 Iterator<KEY> keyIterator = keys.iterator(); 72 Iterator<K> keyIterator = keys.iterator();
73 Iterator<VALUE> valueIterator = values.iterator(); 73 Iterator<V> valueIterator = values.iterator();
74 while(keyIterator.hasNext()) { 74 while(keyIterator.hasNext()) {
75 this.put(keyIterator.next(), valueIterator.next()); 75 this.put(keyIterator.next(), valueIterator.next());
76 } 76 }
@@ -82,7 +82,7 @@ public class VersionedMapImpl<KEY,VALUE> implements VersionedMap<KEY,VALUE>{
82 } 82 }
83 83
84 @Override 84 @Override
85 public VALUE get(KEY key) { 85 public V get(K key) {
86 if(root!=null) { 86 if(root!=null) {
87 return root.getValue(key, hashProvider, defaultValue, hashProvider.getHash(key, 0), 0); 87 return root.getValue(key, hashProvider, defaultValue, hashProvider.getHash(key, 0), 0);
88 } else { 88 } else {
@@ -99,16 +99,16 @@ public class VersionedMapImpl<KEY,VALUE> implements VersionedMap<KEY,VALUE>{
99 } 99 }
100 100
101 @Override 101 @Override
102 public Cursor<KEY, VALUE> getCursor() { 102 public Cursor<K, V> getCursor() {
103 MapCursor<KEY,VALUE> cursor = new MapCursor<>(this.root,this); 103 MapCursor<K,V> cursor = new MapCursor<>(this.root,this);
104 return cursor; 104 return cursor;
105 } 105 }
106 @Override 106 @Override
107 public DiffCursor<KEY, VALUE> getDiffCursor(long toVersion) { 107 public DiffCursor<K, V> getDiffCursor(long toVersion) {
108 Cursor<KEY, VALUE> fromCursor = this.getCursor(); 108 Cursor<K, V> fromCursor = this.getCursor();
109 VersionedMap<KEY, VALUE> toMap = this.store.createMap(toVersion); 109 VersionedMap<K, V> toMap = this.store.createMap(toVersion);
110 Cursor<KEY, VALUE> toCursor = toMap.getCursor(); 110 Cursor<K, V> toCursor = toMap.getCursor();
111 return new MapDiffCursor<KEY, VALUE>(this.hashProvider,this.defaultValue, fromCursor, toCursor); 111 return new MapDiffCursor<K, V>(this.hashProvider,this.defaultValue, fromCursor, toCursor);
112 112
113 } 113 }
114 114
@@ -117,7 +117,7 @@ public class VersionedMapImpl<KEY,VALUE> implements VersionedMap<KEY,VALUE>{
117 public long commit() { 117 public long commit() {
118 return this.store.commit(root,this); 118 return this.store.commit(root,this);
119 } 119 }
120 public void setRoot(Node<KEY, VALUE> root) { 120 public void setRoot(Node<K, V> root) {
121 this.root = root; 121 this.root = root;
122 } 122 }
123 123
diff --git a/model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/utils/MapTestEnvironment.java b/model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/utils/MapTestEnvironment.java
index 8b1760e1..8fd4bece 100644
--- a/model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/utils/MapTestEnvironment.java
+++ b/model-data/src/test/java/org/eclipse/viatra/solver/data/map/tests/utils/MapTestEnvironment.java
@@ -15,7 +15,7 @@ import org.eclipse.viatra.solver.data.map.Cursor;
15import org.eclipse.viatra.solver.data.map.VersionedMap; 15import org.eclipse.viatra.solver.data.map.VersionedMap;
16import org.eclipse.viatra.solver.data.map.internal.VersionedMapImpl; 16import org.eclipse.viatra.solver.data.map.internal.VersionedMapImpl;
17 17
18public class MapTestEnvironment<KEY, VALUE> { 18public class MapTestEnvironment<K, V> {
19 public static String[] prepareValues(int maxValue) { 19 public static String[] prepareValues(int maxValue) {
20 String[] values = new String[maxValue]; 20 String[] values = new String[maxValue];
21 values[0] = "DEFAULT"; 21 values[0] = "DEFAULT";
@@ -55,11 +55,11 @@ public class MapTestEnvironment<KEY, VALUE> {
55 55
56 } 56 }
57 57
58 public static <KEY, VALUE> void compareTwoMaps(String title, VersionedMapImpl<KEY, VALUE> map1, 58 public static <K, V> void compareTwoMaps(String title, VersionedMapImpl<K, V> map1,
59 VersionedMapImpl<KEY, VALUE> map2) { 59 VersionedMapImpl<K, V> map2) {
60 // 1. Comparing cursors. 60 // 1. Comparing cursors.
61 Cursor<KEY, VALUE> cursor1 = map1.getCursor(); 61 Cursor<K, V> cursor1 = map1.getCursor();
62 Cursor<KEY, VALUE> cursor2 = map2.getCursor(); 62 Cursor<K, V> cursor2 = map2.getCursor();
63 while (!cursor1.isTerminated()) { 63 while (!cursor1.isTerminated()) {
64 if (cursor2.isTerminated()) { 64 if (cursor2.isTerminated()) {
65 fail("cursor 2 terminated before cursor1"); 65 fail("cursor 2 terminated before cursor1");
@@ -78,14 +78,14 @@ public class MapTestEnvironment<KEY, VALUE> {
78 assertEquals(map2, map1, title + ": 2.equals(1)"); 78 assertEquals(map2, map1, title + ": 2.equals(1)");
79 } 79 }
80 80
81 public VersionedMapImpl<KEY, VALUE> sut; 81 public VersionedMapImpl<K, V> sut;
82 Map<KEY, VALUE> oracle = new HashMap<KEY, VALUE>(); 82 Map<K, V> oracle = new HashMap<K, V>();
83 83
84 public MapTestEnvironment(VersionedMapImpl<KEY, VALUE> sut) { 84 public MapTestEnvironment(VersionedMapImpl<K, V> sut) {
85 this.sut = sut; 85 this.sut = sut;
86 } 86 }
87 87
88 public void put(KEY key, VALUE value) { 88 public void put(K key, V value) {
89 sut.put(key, value); 89 sut.put(key, value);
90 if (value != sut.getDefaultValue()) { 90 if (value != sut.getDefaultValue()) {
91 oracle.put(key, value); 91 oracle.put(key, value);
@@ -105,9 +105,9 @@ public class MapTestEnvironment<KEY, VALUE> {
105 // 1. Checking: if Reference contains <key,value> pair, then SUT contains 105 // 1. Checking: if Reference contains <key,value> pair, then SUT contains
106 // <key,value> pair. 106 // <key,value> pair.
107 // Tests get functions 107 // Tests get functions
108 for (Entry<KEY, VALUE> entry : oracle.entrySet()) { 108 for (Entry<K, V> entry : oracle.entrySet()) {
109 VALUE sutValue = sut.get(entry.getKey()); 109 V sutValue = sut.get(entry.getKey());
110 VALUE oracleValue = entry.getValue(); 110 V oracleValue = entry.getValue();
111 if (sutValue != oracleValue) { 111 if (sutValue != oracleValue) {
112 printComparison(); 112 printComparison();
113 fail(title + ": Non-equivalent get(" + entry.getKey() + ") results: SUT=" + sutValue + ", Oracle=" 113 fail(title + ": Non-equivalent get(" + entry.getKey() + ") results: SUT=" + sutValue + ", Oracle="
@@ -119,13 +119,13 @@ public class MapTestEnvironment<KEY, VALUE> {
119 // <key,value> pair. 119 // <key,value> pair.
120 // Tests iterators 120 // Tests iterators
121 int elementsInSutEntrySet = 0; 121 int elementsInSutEntrySet = 0;
122 Cursor<KEY, VALUE> cursor = sut.getCursor(); 122 Cursor<K, V> cursor = sut.getCursor();
123 while (cursor.move()) { 123 while (cursor.move()) {
124 elementsInSutEntrySet++; 124 elementsInSutEntrySet++;
125 KEY key = cursor.getKey(); 125 K key = cursor.getKey();
126 VALUE sutValue = cursor.getValue(); 126 V sutValue = cursor.getValue();
127 // System.out.println(key + " -> " + sutValue); 127 // System.out.println(key + " -> " + sutValue);
128 VALUE oracleValue = oracle.get(key); 128 V oracleValue = oracle.get(key);
129 if (sutValue != oracleValue) { 129 if (sutValue != oracleValue) {
130 printComparison(); 130 printComparison();
131 fail(title + ": Non-equivalent entry in iterator: SUT=<" + key + "," + sutValue + ">, Oracle=<" + key 131 fail(title + ": Non-equivalent entry in iterator: SUT=<" + key + "," + sutValue + ">, Oracle=<" + key
@@ -166,23 +166,23 @@ public class MapTestEnvironment<KEY, VALUE> {
166 printEntrySet(oracle.entrySet().iterator()); 166 printEntrySet(oracle.entrySet().iterator());
167 } 167 }
168 168
169 private void printEntrySet(Iterator<Entry<KEY, VALUE>> iterator) { 169 private void printEntrySet(Iterator<Entry<K, V>> iterator) {
170 TreeMap<KEY, VALUE> treemap = new TreeMap<>(); 170 TreeMap<K, V> treemap = new TreeMap<>();
171 while (iterator.hasNext()) { 171 while (iterator.hasNext()) {
172 Entry<KEY, VALUE> entry = iterator.next(); 172 Entry<K, V> entry = iterator.next();
173 treemap.put(entry.getKey(), entry.getValue()); 173 treemap.put(entry.getKey(), entry.getValue());
174 } 174 }
175 for (Entry<KEY, VALUE> e : treemap.entrySet()) { 175 for (Entry<K, V> e : treemap.entrySet()) {
176 System.out.println("\t" + e.getKey() + " -> " + e.getValue()); 176 System.out.println("\t" + e.getKey() + " -> " + e.getValue());
177 } 177 }
178 } 178 }
179 179
180 private void printEntrySet(Cursor<KEY, VALUE> cursor) { 180 private void printEntrySet(Cursor<K, V> cursor) {
181 TreeMap<KEY, VALUE> treemap = new TreeMap<>(); 181 TreeMap<K, V> treemap = new TreeMap<>();
182 while (cursor.move()) { 182 while (cursor.move()) {
183 treemap.put(cursor.getKey(), cursor.getValue()); 183 treemap.put(cursor.getKey(), cursor.getValue());
184 } 184 }
185 for (Entry<KEY, VALUE> e : treemap.entrySet()) { 185 for (Entry<K, V> e : treemap.entrySet()) {
186 System.out.println("\t" + e.getKey() + " -> " + e.getValue()); 186 System.out.println("\t" + e.getKey() + " -> " + e.getValue());
187 } 187 }
188 } 188 }