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
|
|
@ -15,7 +15,7 @@ export const emptyDict = compareFn => RBTreeWrapper.new((x, y) => compareFn(x)(y
|
|||
|
||||
export const has = dict => key => dict.tree.get(key) !== undefined;
|
||||
export const get = dict => key => dict.tree.get(key);
|
||||
export const set = dict => key => value => new RBTreeWrapper(dict.tree.remove(key).insert(key, value), inspectDict);
|
||||
export const set = key => value => dict => new RBTreeWrapper(dict.tree.remove(key).insert(key, value), inspectDict);
|
||||
export const remove = dict => key => new RBTreeWrapper(dict.tree.remove(key), inspectDict);
|
||||
export const length = dict => dict.tree.length;
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ const mkType = makeTypeParser({
|
|||
export const ModuleDict = [
|
||||
["emptyDict", newDynamic(emptyDict)(mkType("(a -> a -> Ordering) -> (a => b) "))],
|
||||
["has" , newDynamic(has )(mkType("(a => b) -> a -> Bool "))],
|
||||
["set" , newDynamic(set )(mkType("(a => b) -> a -> b -> (a => b) "))],
|
||||
["set" , newDynamic(set )(mkType("a -> b -> (a => b) -> (a => b) "))],
|
||||
["remove" , newDynamic(remove )(mkType("(a => b) -> a -> (a => b) "))],
|
||||
["length" , newDynamic(length )(mkType("(a => b) -> Int "))],
|
||||
["fold" , newDynamic(fold )(mkType("(c -> a -> b -> c) -> c -> (a => b) -> c "))],
|
||||
|
|
|
|||
|
|
@ -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