27 lines
863 B
JavaScript
27 lines
863 B
JavaScript
import { RBTreeWrapper } from "../util/rbtree_wrapper.js";
|
|
import { newProduct } from "./product.js";
|
|
import { newLeft, newRight } from "./sum.js";
|
|
|
|
export const emptyDict = compareFn => RBTreeWrapper.new((x, y) => compareFn(x)(y));
|
|
|
|
export const has = dict => key => dict.tree.get(key) === true;
|
|
export const set = dict => key => value => new RBTreeWrapper(dict.tree.remove(key).insert(key, value));
|
|
export const remove = dict => key => new RBTreeWrapper(dict.tree.remove(key));
|
|
export const length = dict => dict.tree.length;
|
|
|
|
export const first = dict => dict.tree.begin;
|
|
export const last = dict => dict.tree.end;
|
|
|
|
export const read = iter => {
|
|
if (iter !== undefined && iter.valid) {
|
|
return newRight(
|
|
newProduct(
|
|
newProduct(iter.key)(iter.value)
|
|
(iter.clone().next())
|
|
)
|
|
);
|
|
}
|
|
else {
|
|
return newLeft(unit);
|
|
}
|
|
};
|