Skip to content

Commit

Permalink
[fact] Register conflicts on delta object instead of locally #20
Browse files Browse the repository at this point in the history
  • Loading branch information
slarse committed Feb 24, 2020
1 parent 6419b75 commit ed53b9c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
31 changes: 30 additions & 1 deletion src/main/java/se/kth/spork/merge/TStar.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class TStar<T,V> {
private Map<T, Set<Content<T,V>>> content;
private Map<T, T> classRepMap;
private Set<Pcs<T>> star;
private Map<Pcs<T>, Set<Pcs<T>>> structuralConflicts;

// never add anything to this set!
private final Set<Pcs<T>> EMPTY_PCS_SET = new HashSet<>();
Expand All @@ -33,6 +34,7 @@ public TStar(Map<T, T> classRepMap, Function<T, V> getContent, Set<Pcs<T>>... tr
content = new HashMap<>();
star = new HashSet<>();
Arrays.stream(trees).forEach(t -> add(t, getContent));
structuralConflicts = new HashMap<>();
}

/**
Expand Down Expand Up @@ -107,7 +109,6 @@ public boolean contains(Content<T,V> cont) {
return content.getOrDefault(cont.getContext().getPredecessor(), new HashSet<>()).contains(cont);
}


/**
* Remove the PCS from all lookup tables, except for the contents table. Also remove it from the *-set.
*
Expand All @@ -130,6 +131,34 @@ public void remove(Content<T,V> cont) {
content.get(cont.getContext().getPredecessor()).remove(cont);
}

/**
* Register a conflict in a bi-directional lookup table.
*
* @param first A PCS triple that conflicts with second.
* @param second A PCS triple that conflicts with first.
*/
public void registerStructuralConflict(Pcs<T> first, Pcs<T> second) {
addToLookupTable(first, second, structuralConflicts);
addToLookupTable(second, first, structuralConflicts);
}

/**
* @return A copy of the internal structural conflicts lookup table.
*/
public Map<Pcs<T>, Set<Pcs<T>>> getStructuralConflicts() {
return new HashMap<>(structuralConflicts);
}

/**
* Check if a PCS is involved in a structural conflict.
*
* @param pcs A PCS triple.
* @return true iff the argument is involved in a structural conflict.
*/
public boolean inStructuralConflict(Pcs<T> pcs) {
return structuralConflicts.containsKey(pcs);
}

/**
* Add a tree to this T*. This entails converting the entire PCS tree to its class representatives. Each
* "class representative PCS" is then added to the predecessor and successor lookup tables, and their contents
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/se/kth/spork/merge/TdmMerge.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public class TdmMerge {
*/
public static <T,V> void resolveRawMerge(TStar<T,V> base, TStar<T,V> delta) {
List<Conflict<Content<T,V>>> contentConflicts = new ArrayList<>();
List<Conflict<Pcs<T>>> structuralConflicts = new ArrayList<>();

for (Pcs<T> pcs : delta.getStar()) {
if (!delta.contains(pcs)) // was removed as otherPcs
Expand All @@ -55,12 +54,13 @@ public static <T,V> void resolveRawMerge(TStar<T,V> base, TStar<T,V> delta) {
} else if (base.contains(pcs)) {
delta.remove(pcs);
} else {
structuralConflicts.add(new Conflict<>(pcs, otherPcs));
delta.registerStructuralConflict(pcs, otherPcs);
}
}
}


Map<Pcs<T>, Set<Pcs<T>>> structuralConflicts = delta.getStructuralConflicts();
if (!contentConflicts.isEmpty()) {
LOGGER.warn("CONTENT CONFLICTS DETECTED: " + contentConflicts);
}
Expand Down

0 comments on commit ed53b9c

Please sign in to comment.