pretty print enhancements + comparison of generic functions
This commit is contained in:
parent
bbac7858ae
commit
9e1f679dba
15 changed files with 93 additions and 45 deletions
|
|
@ -1,12 +1,21 @@
|
|||
import { RBTreeWrapper } from "../util/rbtree_wrapper.js";
|
||||
import { indent } from "../util/util.js";
|
||||
import { newProduct } from "./product.js";
|
||||
import { newLeft, newRight } from "./sum.js";
|
||||
|
||||
export const emptyDict = compareFn => RBTreeWrapper.new((x, y) => compareFn(x)(y));
|
||||
// only for debugging
|
||||
function inspectDict(_depth, options, inspect) {
|
||||
const entries = [];
|
||||
this.tree.forEach((key, val) => { entries.push(`${inspect(key, options)} => ${inspect(val, options)}`); });
|
||||
return `{\n${indent(entries.join(',\n'),2)}\n}`;
|
||||
}
|
||||
|
||||
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 emptyDict = compareFn => RBTreeWrapper.new((x, y) => compareFn(x)(y), inspectDict);
|
||||
|
||||
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 remove = dict => key => new RBTreeWrapper(dict.tree.remove(key), inspectDict);
|
||||
export const length = dict => dict.tree.length;
|
||||
|
||||
export const first = dict => dict.tree.begin;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue