reorganize directory and file structure
This commit is contained in:
parent
1d826ea8d4
commit
48390b8556
99 changed files with 1155 additions and 1629 deletions
22
lib/structures/dict.js
Normal file
22
lib/structures/dict.js
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
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);
|
||||
}
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue