https://github.com/calcit-lang/ternary-tree.ts
TypeScript version of calcit-lang/ternary-tree
https://github.com/calcit-lang/ternary-tree.ts
data-structures typescript
Last synced: 3 months ago
JSON representation
TypeScript version of calcit-lang/ternary-tree
- Host: GitHub
- URL: https://github.com/calcit-lang/ternary-tree.ts
- Owner: calcit-lang
- Created: 2021-01-19T06:59:00.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-04-16T05:28:54.000Z (over 1 year ago)
- Last Synced: 2025-07-08T09:47:45.653Z (3 months ago)
- Topics: data-structures, typescript
- Language: TypeScript
- Homepage:
- Size: 145 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## ternary-tree in TypeScript
> ported from [ternary-tree](https://github.com/calcit-lang/ternary-tree), providing a ternary tree based persistent data structure.
### APIs

Map functions:
```ts
function initTernaryTreeMapFromHashEntries(xs: Array>): TernaryTreeMap;
function initTernaryTreeMap(t: Map): TernaryTreeMap;
function initEmptyTernaryTreeMap(): TernaryTreeMap;function mapLen(tree: TernaryTreeMap): number;
function isMapEmpty(tree: TernaryTreeMap): boolean;
function contains(tree: TernaryTreeMap, item: K, hx: Hash = null as any): boolean;
function mapEqual(xs: TernaryTreeMap, ys: TernaryTreeMap): boolean;function* toPairs(tree: TernaryTreeMap): Generator<[K, T]>;
function* toKeys(tree: TernaryTreeMap): Generator;
function* toValues(tree: TernaryTreeMap): Generator;
function toPairsArray(tree: TernaryTreeMap): Array<[K, T]>;function assocMap(tree: TernaryTreeMap, key: K, item: T, disableBalancing: boolean = false): TernaryTreeMap;
function dissocMap(tree: TernaryTreeMap, key: K): TernaryTreeMap;
function merge(xs: TernaryTreeMap, ys: TernaryTreeMap): TernaryTreeMap;
function mergeSkip(xs: TernaryTreeMap, ys: TernaryTreeMap, skipped: T): TernaryTreeMap;
function mapMapValues(tree: TernaryTreeMap, f: (x: T) => V): TernaryTreeMap;function toHashSortedPairs(tree: TernaryTreeMap): Array<[K, T]>;
function mapToString(tree: TernaryTreeMap): string;
function formatMapInline(tree: TernaryTreeMap, withHash: boolean = false): string;
function checkMapStructure(tree: TernaryTreeMap): boolean;
function getMapDepth(tree: TernaryTreeMap): number;
function forceMapInplaceBalancing(tree: TernaryTreeMap): void;
function sameMapShape(xs: TernaryTreeMap, ys: TernaryTreeMap): boolean;
```List functions:
```ts
function makeTernaryTreeList(size: number, offset: number, xs: /* var */ Array>): TernaryTreeList;
function initTernaryTreeList(xs: Array): TernaryTreeList;
function initEmptyTernaryTreeList(): TernaryTreeList;function* listToItems(tree: TernaryTreeList): Generator;
function* indexToItems(tree: TernaryTreeList): Generator;
function* listToPairs(tree: TernaryTreeList): Generator<[number, T]>;function listLen(tree: TernaryTreeList): number;
function listEqual(xs: TernaryTreeList, ys: TernaryTreeList): boolean;
function listGet(originalTree: TernaryTreeList, originalIdx: number): T;
function first(tree: TernaryTreeList): T;
function last(tree: TernaryTreeList): T;
function slice(tree: TernaryTreeList, startIdx: number, endIdx: number): TernaryTreeList;function findIndex(tree: TernaryTreeList, f: (x: T) => boolean): number;
function indexOf(tree: TernaryTreeList, item: T): number;
function assocList(tree: TernaryTreeList, idx: number, item: T): TernaryTreeList;
function dissocList(tree: TernaryTreeList, idx: number): TernaryTreeList;
function rest(tree: TernaryTreeList): TernaryTreeList;
function butlast(tree: TernaryTreeList): TernaryTreeList;
function insert(tree: TernaryTreeList, idx: number, item: T, after: boolean = false): TernaryTreeList;
function assocBefore(tree: TernaryTreeList, idx: number, item: T, after: boolean = false): TernaryTreeList;
function assocAfter(tree: TernaryTreeList, idx: number, item: T, after: boolean = false): TernaryTreeList;
function prepend(tree: TernaryTreeList, item: T, disableBalancing: boolean = false): TernaryTreeList;
function append(tree: TernaryTreeList, item: T, disableBalancing: boolean = false): TernaryTreeList;
function concat(xs: TernaryTreeList, ys: TernaryTreeList): TernaryTreeList;
function reverse(tree: TernaryTreeList): TernaryTreeList;
function listMapValues(tree: TernaryTreeList, f: (x: T) => V): TernaryTreeList;function sameListShape(xs: TernaryTreeList, ys: TernaryTreeList): boolean;
function getDepth(tree: TernaryTreeList): number;
function listToString(tree: TernaryTreeList): string;
function formatListInline(tree: TernaryTreeList): string;
function checkListStructure(tree: TernaryTreeList): boolean;
function forceListInplaceBalancing(tree: TernaryTreeList): void;
```To overwrite internals behaviors:
```ts
overwriteHashGenerator(f);overwriteComparator(f);
```### License
MIT