reorganize directory and file structure

This commit is contained in:
Joeri Exelmans 2025-05-07 13:44:49 +02:00
parent 1d826ea8d4
commit 48390b8556
99 changed files with 1155 additions and 1629 deletions

29
lib/structures/set.js Normal file
View file

@ -0,0 +1,29 @@
import { newRight } from "./sum.js";
import { newProduct } from "./product.js";
import { unit } from "../primitives/unit.js";
import { RBTreeWrapper } from "../util/rbtree_wrapper.js";
// (a -> a -> Int) -> Set(a)
export const emptySet = compareFn => RBTreeWrapper.new((x, y) => compareFn(x)(y));
export const has = set => key => set.tree.get(key) === true;
export const add = set => key => set.tree.get(key) === true ? set : new RBTreeWrapper(set.tree.insert(key, true));
export const remove = set => key => new RBTreeWrapper(set.tree.remove(key));
export const length = set => set.tree.length;
export const first = set => set.tree.begin;
export const last = set => set.tree.end;
// test if iterator is 'done', and if not, get element and advance iterator.
export const read = iter => {
if (iter !== undefined && iter.valid) {
return newRight(newProduct(iter.key)(iter.clone().next()));
}
else {
return newLeft(unit);
}
};
export const forEach = set => fn => {
set.tree.forEach(key => { fn(key); });
};