fix error in static merge algorithm. progress with merging of dictionary-operations
This commit is contained in:
parent
5d028fe030
commit
d5821c9cb9
4 changed files with 115 additions and 71 deletions
|
|
@ -1,22 +1,23 @@
|
|||
import { emptySet, add, length, forEach, has, remove } from "../../structures/set.js";
|
||||
import { getDepth, Slot } from "./value_slot.js";
|
||||
import { compareSlot } from "../compare.js";
|
||||
import { compareSlot } from "./compare.js";
|
||||
import { makeTypeParser } from "../../parser/type_parser.js";
|
||||
import { newDynamic } from "../../primitives/dynamic.js";
|
||||
|
||||
const emptySetOfSlots = emptySet(compareSlot);
|
||||
const emptySetOfSlots = compareElems => emptySet(compareSlot(compareElems));
|
||||
|
||||
export const findLCA = slotA => slotB => {
|
||||
if (compareSlot(slotA)(slotB) === 0) {
|
||||
export const findLCA = compareElems => slotA => slotB => {
|
||||
console.log('compareSlot...', slotA, slotB);
|
||||
if (compareSlot(compareElems)(slotA)(slotB) === 0) {
|
||||
return slotA;
|
||||
}
|
||||
if (getDepth(slotA) > getDepth(slotB)) {
|
||||
// we can assume that slotA.variant === "write"
|
||||
return findLCA(slotA.value.slot)(slotB);
|
||||
return findLCA(compareElems)(slotA.value.slot)(slotB);
|
||||
}
|
||||
else {
|
||||
// we can assume that slotB.variant === "write"
|
||||
return findLCA(slotA)(slotB.value.slot);
|
||||
return findLCA(compareElems)(slotA)(slotB.value.slot);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -24,26 +25,27 @@ export const findLCA = slotA => slotB => {
|
|||
// {slotA} if slotA is younger
|
||||
// {slotB} if slotB is younger
|
||||
// {slotA, slotB} if they are concurrent (conflicting)
|
||||
export const merge = slotA => slotB => {
|
||||
const lca = findLCA(slotA)(slotB);
|
||||
if (compareSlot(lca)(slotA) === 0) {
|
||||
return add(emptySetOfSlots)(slotB);
|
||||
export const merge = compareElems => slotA => slotB => {
|
||||
const lca = findLCA(compareElems)(slotA)(slotB);
|
||||
const emptySet = emptySetOfSlots(compareElems);
|
||||
if (compareSlot(compareElems)(lca)(slotA) === 0) {
|
||||
return add(emptySet)(slotB);
|
||||
}
|
||||
if (compareSlot(lca)(slotB) === 0) {
|
||||
return add(emptySetOfSlots)(slotA);
|
||||
if (compareSlot(compareElems)(lca)(slotB) === 0) {
|
||||
return add(emptySet)(slotA);
|
||||
}
|
||||
const setWithA = add(emptySetOfSlots)(slotA);
|
||||
const setWithA = add(emptySet)(slotA);
|
||||
const setWithAandB = add(setWithA)(slotB);
|
||||
return setWithAandB;
|
||||
};
|
||||
|
||||
export const mergeN = slots => {
|
||||
export const mergeN = compareElems => slots => {
|
||||
let result = slots;
|
||||
forEach(slots)(slotA => {
|
||||
forEach(slots)(slotB => {
|
||||
// compare all non-identical pairs
|
||||
if (compareSlot(slotA)(slotB) !== 0) {
|
||||
const m = merge(slotA)(slotB);
|
||||
if (compareSlot(compareElems)(slotA)(slotB) !== 0) {
|
||||
const m = merge(compareElems)(slotA)(slotB);
|
||||
if (length(m) === 1) {
|
||||
// if in the pair, one is an ancestor of the other,
|
||||
// only keep the other
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue