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
|
|
@ -2,87 +2,129 @@ import { newDynamic } from "../lib/primitives/dynamic.js";
|
|||
import { Char, Int } from "../lib/primitives/primitive_types.js";
|
||||
import { fnType } from "../lib/structures/type_constructors.types.js";
|
||||
import { pretty } from "../lib/util/pretty.js";
|
||||
import { newLiteral, newSlot, read, transform, write } from "../lib/versioning/value_slot.js";
|
||||
import { merge, mergeN } from "../lib/versioning/merge.js";
|
||||
import { newLiteral, newSlot, read, transform, write } from "../lib/versioning/static/value_slot.js";
|
||||
import { merge, mergeN } from "../lib/versioning/static/merge.js";
|
||||
import { union } from "../lib/structures/set.js";
|
||||
import { emptyDict, set } from "../lib/structures/dict.js";
|
||||
import { compareInts, compareStrings } from "../lib/compare/primitives.js";
|
||||
import { compareDicts } from "../lib/compare/structures.js";
|
||||
|
||||
const inc = x => x + 1n;
|
||||
const incLiteral = newLiteral(newDynamic(inc)(fnType(_=>Int)(_=>Int)));
|
||||
|
||||
|
||||
console.log("##############");
|
||||
console.log("## Counting ##");
|
||||
console.log("##############");
|
||||
// {
|
||||
// console.log("##############");
|
||||
// console.log("## Counting ##");
|
||||
// console.log("##############");
|
||||
|
||||
const counterOneSlot = write
|
||||
(newSlot("1d61577e704613f4e48b164852aedd20"))
|
||||
(newLiteral(newDynamic(1n)(Int)));
|
||||
// const counterOneSlot = write
|
||||
// (newSlot("1d61577e704613f4e48b164852aedd20"))
|
||||
// (newLiteral(newDynamic(1n)(Int)));
|
||||
|
||||
console.log(pretty({counterOneSlot}));
|
||||
// console.log(pretty({counterOneSlot}));
|
||||
|
||||
const valueOne = read(counterOneSlot);
|
||||
// const valueOne = read(counterOneSlot);
|
||||
|
||||
console.log(pretty({valueOne}));
|
||||
// console.log(pretty({valueOne}));
|
||||
|
||||
const onePlusOne = transform
|
||||
(valueOne)
|
||||
(incLiteral);
|
||||
// const onePlusOne = transform
|
||||
// (valueOne)
|
||||
// (incLiteral);
|
||||
|
||||
console.log(pretty({onePlusOne}));
|
||||
// console.log(pretty({onePlusOne}));
|
||||
|
||||
const onePlusOnePlusOne = transform
|
||||
(onePlusOne)
|
||||
(incLiteral);
|
||||
// const onePlusOnePlusOne = transform
|
||||
// (onePlusOne)
|
||||
// (incLiteral);
|
||||
|
||||
console.log(pretty({onePlusOnePlusOne}));
|
||||
// console.log(pretty({onePlusOnePlusOne}));
|
||||
// }
|
||||
|
||||
// // console.log("#############");
|
||||
// // console.log("## Summing ##");
|
||||
// // console.log("#############");
|
||||
|
||||
// // const priceSlot = newSlot(Symbol('price'))(newLiteral(20.66));
|
||||
// // const taxSlot = newSlot(Symbol('tax'))(newLiteral(4.34));
|
||||
|
||||
// // const total =
|
||||
// // transform(read(priceSlot))(
|
||||
// // transform(read(taxSlot))(
|
||||
// // newLiteral(tax => price => price + tax)));
|
||||
|
||||
// // console.log(pretty({total}))
|
||||
|
||||
// // const totalPlusOne = transform(total)(newLiteral(inc));
|
||||
|
||||
// // console.log(pretty({totalPlusOne}));
|
||||
|
||||
// // verifyValue(totalPlusOne);
|
||||
|
||||
// // console.log("getReadDependencies(totalPlusOne):", getReadDependencies(totalPlusOne));
|
||||
|
||||
|
||||
// {
|
||||
// console.log("###############");
|
||||
// console.log("## Branching ##");
|
||||
// console.log("###############");
|
||||
|
||||
// console.log("#############");
|
||||
// console.log("## Summing ##");
|
||||
// console.log("#############");
|
||||
// const initialSlot = newSlot("Slot__4a029b3d758bcd1fffbf495531c95537");
|
||||
|
||||
// const priceSlot = newSlot(Symbol('price'))(newLiteral(20.66));
|
||||
// const taxSlot = newSlot(Symbol('tax'))(newLiteral(4.34));
|
||||
// const slotA = write(initialSlot)(newLiteral(newDynamic("a")(Char)));
|
||||
// const slotB = write(slotA )(newLiteral(newDynamic("b")(Char)));
|
||||
// const slotC = write(initialSlot)(newLiteral(newDynamic("c")(Char)));
|
||||
|
||||
// const total =
|
||||
// transform(read(priceSlot))(
|
||||
// transform(read(taxSlot))(
|
||||
// newLiteral(tax => price => price + tax)));
|
||||
// const slotAB = merge(slotA)(slotB);
|
||||
// const slotAC = merge(slotA)(slotC);
|
||||
// const slotBC = merge(slotB)(slotC);
|
||||
|
||||
// console.log(pretty({total}))
|
||||
// console.log({slotAB, slotAC, slotBC});
|
||||
|
||||
// const totalPlusOne = transform(total)(newLiteral(inc));
|
||||
// const un = union(slotAC)(slotBC);
|
||||
|
||||
// console.log(pretty({totalPlusOne}));
|
||||
// const merged = mergeN(un);
|
||||
|
||||
// verifyValue(totalPlusOne);
|
||||
// console.log("merged:", merged);
|
||||
// }
|
||||
|
||||
// console.log("getReadDependencies(totalPlusOne):", getReadDependencies(totalPlusOne));
|
||||
{
|
||||
console.log("#################");
|
||||
console.log("## Dict insert ##");
|
||||
console.log("#################");
|
||||
|
||||
const dictSlot = write
|
||||
(newSlot("MyDictSlot__d2e87499d9cf46b5c86d420c2057f52f"))
|
||||
(newLiteral(emptyDict(compareStrings)));
|
||||
|
||||
const insertedX = write(dictSlot)
|
||||
(transform
|
||||
(read(dictSlot)) // input
|
||||
(transform // fn (set "x" => 1n)
|
||||
(newLiteral(1n))
|
||||
(transform
|
||||
(newLiteral("x"))
|
||||
(newLiteral(set))
|
||||
)));
|
||||
const insertedY = write(dictSlot)
|
||||
(transform
|
||||
(read(dictSlot)) // input
|
||||
(transform // fn (set "y" => 2n)
|
||||
(newLiteral(2n))
|
||||
(transform
|
||||
(newLiteral("y"))
|
||||
(newLiteral(set))
|
||||
)));
|
||||
|
||||
console.log("###############");
|
||||
console.log("## Branching ##");
|
||||
console.log("###############");
|
||||
const merged = merge
|
||||
(compareDicts(compareStrings)(compareInts))
|
||||
(insertedX)
|
||||
(insertedY);
|
||||
|
||||
const initialSlot = newSlot("Slot__4a029b3d758bcd1fffbf495531c95537");
|
||||
|
||||
const slotA = write(initialSlot)(newLiteral(newDynamic("a")(Char)));
|
||||
const slotB = write(slotA )(newLiteral(newDynamic("b")(Char)));
|
||||
const slotC = write(initialSlot)(newLiteral(newDynamic("c")(Char)));
|
||||
|
||||
const slotAB = merge(slotA)(slotB);
|
||||
const slotAC = merge(slotA)(slotC);
|
||||
const slotBC = merge(slotB)(slotC);
|
||||
|
||||
console.log({slotAB, slotAC, slotBC});
|
||||
|
||||
const un = union(slotAC)(slotBC);
|
||||
|
||||
const merged = mergeN(un);
|
||||
|
||||
console.log("merged:", merged);
|
||||
// is a conflict, but shouldn't be one...
|
||||
// can we add the 'domain knowledge' that the composition of two non-key-overlapping dict.set-operations is commutative?
|
||||
console.log({merged});
|
||||
}
|
||||
|
||||
// // console.log(compareSlots(intCompare)(fiveSlot)(fiveSlot));
|
||||
// // console.log(compareSlots(intCompare)(sixSlot)(sixSlot));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue