restructure code a bit, add comparison functions for primitive types and composed types (needed to put values in sets)
This commit is contained in:
parent
3978f7f835
commit
8653bb99c6
12 changed files with 175 additions and 64 deletions
|
|
@ -1,6 +1,7 @@
|
|||
import { add, emptySet, forEach } from "../structures/set.js";
|
||||
import { deepEqual } from "../util/util.js";
|
||||
import {inspect} from "node:util";
|
||||
import { compareSlots } from "../compare/versioning.js";
|
||||
|
||||
// UUID -> Value<a> -> Slot<a>
|
||||
export const newSlot = uuid => value => ({
|
||||
|
|
@ -10,39 +11,6 @@ export const newSlot = uuid => value => ({
|
|||
[inspect.custom]: (depth, options, inspect) => `newSlot(${inspect(uuid)}, ${inspect(value)})`,
|
||||
});
|
||||
|
||||
export const compareSlots = compareElems => slotA => slotB => {
|
||||
if (slotA.depth < slotB.depth) {
|
||||
return -1;
|
||||
}
|
||||
if (slotB.depth < slotA.depth) {
|
||||
return 1;
|
||||
}
|
||||
return compareValues(compareElems)(slotA.value)(slotB.value);
|
||||
};
|
||||
|
||||
export const compareValues = compareElems => valA => valB => {
|
||||
if (valA.kind < valB.kind) {
|
||||
return -1;
|
||||
}
|
||||
if (valB.kind < valA.kind) {
|
||||
return 1;
|
||||
}
|
||||
if (valA.kind === "literal") {
|
||||
return compareElems(valA.out)(valB.out);
|
||||
}
|
||||
if (valA.kind === "read") {
|
||||
return compareSlots(compareElems)(valA.slot)(valB.slot);
|
||||
}
|
||||
if (valA.kind === "transformation") {
|
||||
const cmpIn = compareValues(compareElems)(valA.in)(valB.in);
|
||||
if (cmpIn !== 0) {
|
||||
return cmpIn;
|
||||
}
|
||||
return compareValues(compareElems)(valA.fn)(valB.fn);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// Slot<a> -> Value<a> -> Slot<a>
|
||||
export const overwrite = slot => value => ({
|
||||
overwrites: slot,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { deepEqual } from "../util/util.js";
|
||||
import {inspect} from "node:util";
|
||||
import { inspect } from "node:util";
|
||||
|
||||
// A Value is either:
|
||||
// - a literal, without any dependencies.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue