Skip to content

Commit c95b20e

Browse files
committed
[fix] Fix non-deterministic move conflict detection, fix #101
1 parent fee080a commit c95b20e

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

src/main/java/se/kth/spork/base3dm/ChangeSet.java

+10-9
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.util.*;
44
import java.util.function.Function;
5+
import java.util.stream.Collectors;
56
import java.util.stream.Stream;
67

78
/**
@@ -60,34 +61,34 @@ public Map<T, Set<Content<T,V>>> getContents() {
6061

6162
/**
6263
* @param pcs A PCS triple.
63-
* @return Another PCS that matches the argument PCS on everything but root.
64+
* @return All PCSes that are root conflicting with the provided PCS.
6465
*/
65-
public Optional<Pcs<T>> getOtherRoot(Pcs<T> pcs) {
66+
public List<Pcs<T>> getOtherRoots(Pcs<T> pcs) {
6667
return Stream.of(pcs.getPredecessor(), pcs.getSuccessor()).flatMap(
6768
node -> Stream.of(predecessors.get(node), successors.get(node))
6869
.filter(Objects::nonNull)
6970
.flatMap(Set::stream)
70-
).filter(p -> !p.getRoot().equals(pcs.getRoot())).findFirst();
71+
).filter(p -> !p.getRoot().equals(pcs.getRoot())).collect(Collectors.toList());
7172
}
7273

7374
/**
7475
* @param pcs A PCS triple.
75-
* @return Another PCS that matches the argument PCS on everything but successor.
76+
* @return All PCSes that are successor conflicting with the provided PCS.
7677
*/
77-
public Optional<Pcs<T>> getOtherSuccessor(Pcs<T> pcs) {
78+
public List<Pcs<T>> getOtherSuccessors(Pcs<T> pcs) {
7879
return predecessors.getOrDefault(pcs.getPredecessor(), EMPTY_PCS_SET).stream()
7980
.filter(p -> !p.getSuccessor().equals(pcs.getSuccessor()))
80-
.findFirst();
81+
.collect(Collectors.toList());
8182
}
8283

8384
/**
8485
* @param pcs A PCS triple.
85-
* @return Another PCS that matches the argument PCS on everything but predecessor.
86+
* @return All PCSes that are predecessor conflicting with the provided PCS.
8687
*/
87-
public Optional<Pcs<T>> getOtherPredecessor(Pcs<T> pcs) {
88+
public List<Pcs<T>> getOtherPredecessors(Pcs<T> pcs) {
8889
return successors.getOrDefault(pcs.getSuccessor(), EMPTY_PCS_SET).stream()
8990
.filter(p -> !p.getPredecessor().equals(pcs.getPredecessor()))
90-
.findFirst();
91+
.collect(Collectors.toList());
9192
}
9293

9394
/**

src/main/java/se/kth/spork/base3dm/TdmMerge.java

+6-8
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,13 @@ public static <T extends ListNode,V> void resolveRawMerge(ChangeSet<T,V> base, C
3939
mergeContent(pcs.getPredecessor(), base, delta);
4040
mergeContent(pcs.getSuccessor(), base, delta);
4141

42-
Optional<Pcs<T>> other = delta.getOtherRoot(pcs);
43-
if (!other.isPresent())
44-
other = delta.getOtherPredecessor(pcs);
45-
if (!other.isPresent())
46-
other = delta.getOtherSuccessor(pcs);
47-
48-
if (other.isPresent()) {
49-
Pcs<T> otherPcs = other.get();
42+
List<Pcs<T>> others = delta.getOtherRoots(pcs);
43+
if (others.isEmpty())
44+
others = delta.getOtherPredecessors(pcs);
45+
if (others.isEmpty())
46+
others = delta.getOtherSuccessors(pcs);
5047

48+
for (Pcs<T> otherPcs : others) {
5149
if (base.contains(otherPcs)) {
5250
delta.remove(otherPcs);
5351
} else if (base.contains(pcs)) {

0 commit comments

Comments
 (0)