aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/store/src
diff options
context:
space:
mode:
authorLibravatar OszkarSemerath <semerath@mit.bme.hu>2023-02-05 00:37:55 +0100
committerLibravatar OszkarSemerath <semerath@mit.bme.hu>2023-02-05 00:37:55 +0100
commitf90f42e8834964b4e3f5a3504d896e64995b9a01 (patch)
tree18da48f45465aa61f0e3eb57bec0b2abb5636fbf /subprojects/store/src
parentCode quality improvements in nodes (diff)
downloadrefinery-f90f42e8834964b4e3f5a3504d896e64995b9a01.tar.gz
refinery-f90f42e8834964b4e3f5a3504d896e64995b9a01.tar.zst
refinery-f90f42e8834964b4e3f5a3504d896e64995b9a01.zip
Code quality improvements in cursors
Diffstat (limited to 'subprojects/store/src')
-rw-r--r--subprojects/store/src/main/java/tools/refinery/store/map/internal/HashClash.java4
-rw-r--r--subprojects/store/src/main/java/tools/refinery/store/map/internal/MapCursor.java12
-rw-r--r--subprojects/store/src/main/java/tools/refinery/store/map/internal/MapDiffCursor.java13
3 files changed, 15 insertions, 14 deletions
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
index 5402ed4a..0806c486 100644
--- 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
@@ -5,12 +5,12 @@ enum HashClash {
5 * Not stuck. 5 * Not stuck.
6 */ 6 */
7 NONE, 7 NONE,
8 8
9 /** 9 /**
10 * Clashed, next we should return the key of cursor 1. 10 * Clashed, next we should return the key of cursor 1.
11 */ 11 */
12 STUCK_CURSOR_1, 12 STUCK_CURSOR_1,
13 13
14 /** 14 /**
15 * Clashed, next we should return the key of cursor 2. 15 * Clashed, next we should return the key of cursor 2.
16 */ 16 */
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/MapCursor.java
index 91a71e3d..f874137b 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/MapCursor.java
@@ -96,7 +96,7 @@ public class MapCursor<K, V> implements Cursor<K, V> {
96 return Set.of(this.map); 96 return Set.of(this.map);
97 } 97 }
98 98
99 public static <K, V> boolean sameSubnode(MapCursor<K, V> cursor1, MapCursor<K, V> cursor2) { 99 public static <K, V> boolean sameSubNode(MapCursor<K, V> cursor1, MapCursor<K, V> cursor2) {
100 Node<K, V> nodeOfCursor1 = cursor1.nodeStack.peek(); 100 Node<K, V> nodeOfCursor1 = cursor1.nodeStack.peek();
101 Node<K, V> nodeOfCursor2 = cursor2.nodeStack.peek(); 101 Node<K, V> nodeOfCursor2 = cursor2.nodeStack.peek();
102 if (nodeOfCursor1 != null && nodeOfCursor2 != null) { 102 if (nodeOfCursor1 != null && nodeOfCursor2 != null) {
@@ -107,10 +107,12 @@ public class MapCursor<K, V> implements Cursor<K, V> {
107 } 107 }
108 108
109 /** 109 /**
110 * @param <K> 110 * Compares the state of two cursors started on two @{@link VersionedMap of the }same
111 * @param <V> 111 * {@link tools.refinery.store.map.VersionedMapStore}.
112 * @param cursor1 112 * @param <K> Key type
113 * @param cursor2 113 * @param <V> Value type
114 * @param cursor1 first cursor
115 * @param cursor2 second cursor
114 * @return Positive number if cursor 1 is behind, negative number if cursor 2 is behind, and 0 if they are at the 116 * @return Positive number if cursor 1 is behind, negative number if cursor 2 is behind, and 0 if they are at the
115 * same position. 117 * same position.
116 */ 118 */
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/MapDiffCursor.java
index 9cd78113..beaff13b 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/MapDiffCursor.java
@@ -131,22 +131,21 @@ public class MapDiffCursor<K, V> implements DiffCursor<K, V>, Cursor<K, V> {
131 131
132 protected void resolveHashClashWithSecondEntry() { 132 protected void resolveHashClashWithSecondEntry() {
133 switch (this.hashClash) { 133 switch (this.hashClash) {
134 case STUCK_CURSOR_1: 134 case STUCK_CURSOR_1 -> {
135 this.hashClash = HashClash.NONE; 135 this.hashClash = HashClash.NONE;
136 this.cursorRelation = 0; 136 this.cursorRelation = 0;
137 this.key = cursor1.key; 137 this.key = cursor1.key;
138 this.fromValue = cursor1.value; 138 this.fromValue = cursor1.value;
139 this.toValue = defaultValue; 139 this.toValue = defaultValue;
140 break; 140 }
141 case STUCK_CURSOR_2: 141 case STUCK_CURSOR_2 -> {
142 this.hashClash = HashClash.NONE; 142 this.hashClash = HashClash.NONE;
143 this.cursorRelation = 0; 143 this.cursorRelation = 0;
144 this.key = cursor2.key; 144 this.key = cursor2.key;
145 this.fromValue = defaultValue; 145 this.fromValue = defaultValue;
146 this.toValue = cursor2.value; 146 this.toValue = cursor2.value;
147 break; 147 }
148 default: 148 default -> throw new IllegalArgumentException("Inconsistent compare result for diffcursor");
149 throw new IllegalArgumentException("Inconsistent compare result for diffcursor");
150 } 149 }
151 } 150 }
152 151
@@ -189,7 +188,7 @@ public class MapDiffCursor<K, V> implements DiffCursor<K, V>, Cursor<K, V> {
189 boolean lastResult = true; 188 boolean lastResult = true;
190 do { 189 do {
191 changed = false; 190 changed = false;
192 if (MapCursor.sameSubnode(cursor1, cursor2)) { 191 if (MapCursor.sameSubNode(cursor1, cursor2)) {
193 lastResult = skipNode(); 192 lastResult = skipNode();
194 changed = true; 193 changed = true;
195 } 194 }