// Tiny wrapper around function-red-black-tree that overrides the [inspect.custom] symbol so when we print it (during debugging) we just see the (key=>value)-pairs instead of the tree structure. import createRBTree from "functional-red-black-tree"; import { inspect } from "util"; export class RBTreeWrapper { constructor(tree) { this.tree = tree; } static new(compareFn) { return new RBTreeWrapper(createRBTree(compareFn)) } // pretty print to console [inspect.custom](depth, options, inspect) { const entries = []; this.tree.forEach((key, val) => { entries.push(`${inspect(key)} => ${inspect(val)}`); }); return `RBTree(${this.tree.length}) {${entries.join(', ')}}`; } }