|
1 |
| -import {Empty} from './3-tree/index.js'; |
| 1 | +import assert from 'assert'; |
| 2 | +import {Split} from './0-core/split/Split.js'; |
| 3 | +import {One} from './1-digit/1-One.js'; |
| 4 | +import {Two} from './1-digit/2-Two.js'; |
| 5 | +import {Three} from './1-digit/3-Three.js'; |
| 6 | +import {Four} from './1-digit/4-Four.js'; |
| 7 | +import {Tree} from './3-tree/base/Tree.js'; |
| 8 | +import {Empty} from './3-tree/implementations/0-Empty.js'; |
| 9 | +import {Deep} from './3-tree/implementations/2-Deep.js'; |
2 | 10 |
|
3 | 11 | export const empty = (M) => new Empty(M);
|
4 | 12 | export {from} from './0-core/index.js';
|
| 13 | + |
| 14 | +export const leftTree = (treeSplit) => { |
| 15 | + assert(treeSplit instanceof Split); |
| 16 | + return treeSplit.left; |
| 17 | +}; |
| 18 | + |
| 19 | +export const rightTree = (treeSplit) => { |
| 20 | + assert(treeSplit instanceof Split); |
| 21 | + return treeSplit.right; |
| 22 | +}; |
| 23 | + |
| 24 | +export const middleElement = (treeSplit) => { |
| 25 | + assert(treeSplit instanceof Split); |
| 26 | + return treeSplit.middle; |
| 27 | +}; |
| 28 | + |
| 29 | +export const leftDigit = (tree) => { |
| 30 | + assert(tree instanceof Deep); |
| 31 | + return tree.left; |
| 32 | +}; |
| 33 | + |
| 34 | +export const rightDigit = (tree) => { |
| 35 | + assert(tree instanceof Deep); |
| 36 | + return tree.right; |
| 37 | +}; |
| 38 | + |
| 39 | +export const middleTree = (tree) => { |
| 40 | + assert(tree instanceof Deep); |
| 41 | + return tree.middle; |
| 42 | +}; |
| 43 | + |
| 44 | +export const embeddedMeasure = (tree) => { |
| 45 | + assert(tree instanceof Tree); |
| 46 | + return tree.force().M; |
| 47 | +}; |
| 48 | + |
| 49 | +export const nodes = (M, left, right) => { |
| 50 | + assert( |
| 51 | + left instanceof One || |
| 52 | + left instanceof Two || |
| 53 | + left instanceof Three || |
| 54 | + left instanceof Four, |
| 55 | + ); |
| 56 | + assert( |
| 57 | + right instanceof One || |
| 58 | + right instanceof Two || |
| 59 | + right instanceof Three || |
| 60 | + right instanceof Four, |
| 61 | + ); |
| 62 | + return left._nodes(M, right); |
| 63 | +}; |
| 64 | + |
| 65 | +export const nodesWithList = (M, left, list, right) => { |
| 66 | + assert( |
| 67 | + left instanceof One || |
| 68 | + left instanceof Two || |
| 69 | + left instanceof Three || |
| 70 | + left instanceof Four, |
| 71 | + ); |
| 72 | + assert(Number.isInteger(list.length) && list.length >= 1 && list.length <= 4); |
| 73 | + assert( |
| 74 | + right instanceof One || |
| 75 | + right instanceof Two || |
| 76 | + right instanceof Three || |
| 77 | + right instanceof Four, |
| 78 | + ); |
| 79 | + return left._nodes_with_list(M, list, right); |
| 80 | +}; |
| 81 | + |
| 82 | +export const digitSize = (digit) => { |
| 83 | + assert( |
| 84 | + digit instanceof One || |
| 85 | + digit instanceof Two || |
| 86 | + digit instanceof Three || |
| 87 | + digit instanceof Four, |
| 88 | + ); |
| 89 | + if (digit instanceof One) return 1; |
| 90 | + if (digit instanceof Two) return 2; |
| 91 | + if (digit instanceof Three) return 3; |
| 92 | + return 4; |
| 93 | +}; |
0 commit comments