functionalscript 0.0.282 → 0.0.283
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/types/btree/README.md +79 -52
- package/types/btree/index.js +10 -5
- package/types/btree/test.js +20 -7
package/package.json
CHANGED
package/types/btree/README.md
CHANGED
|
@@ -77,55 +77,82 @@ Posible actions:
|
|
|
77
77
|
|middle| 2|`[n0 v1 ...o v3 n4]`|`[n0 v1 (L VM R) v3 n4]`|`[[n0 v1 L ] VM [ R v3 n4]]`|
|
|
78
78
|
|right | 4|`[n0 v1 n2 v3 ...o]`|`[n0 v1 n2 v3 (L VM R)]`|`[[n0 v1 n2] v3 [ L VM R ]]`|
|
|
79
79
|
|
|
80
|
-
##
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|`
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|`[
|
|
88
|
-
|
|
|
89
|
-
|`[
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
|
100
|
-
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
|
107
|
-
|
|
108
|
-
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
`concat
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|`[
|
|
119
|
-
|
|
|
120
|
-
|`[
|
|
121
|
-
|`
|
|
122
|
-
|
|
|
123
|
-
|`[
|
|
124
|
-
|
|
|
125
|
-
|
|
126
|
-
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|`
|
|
130
|
-
|`
|
|
131
|
-
|`
|
|
80
|
+
## Concat
|
|
81
|
+
|
|
82
|
+
`concat` returns either `Branch1` or `Branch3`
|
|
83
|
+
|
|
84
|
+
|`a` |`b` | |size |
|
|
85
|
+
|------------------|-------------------|-------------------------------------------------|-----|
|
|
86
|
+
|`[av]` |`[bv]` |`[[av,bv]]` | |
|
|
87
|
+
| |`[bv0,bv1]` |`[a,bv0,[bv1]]` | |
|
|
88
|
+
|`[av0,av1]` | |`[[av0],av1,b]` | |
|
|
89
|
+
|`[...aHead,aLast]`|`[bFirst,...bLast]`|`up([...aHead,...concat(aLast,bFirst),...bTail])`|5..11|
|
|
90
|
+
|
|
91
|
+
## Up
|
|
92
|
+
|
|
93
|
+
`up` returns `Branch1` or `Branch3`
|
|
94
|
+
|
|
95
|
+
|`n.lenght`| |
|
|
96
|
+
|----------|--------------------------|
|
|
97
|
+
|5 |`[n]` |
|
|
98
|
+
|7 |`[n[0...2],n[3],n[4...6]]`|
|
|
99
|
+
|9 |`[n[0...2],n[3],n[4...8]]`|
|
|
100
|
+
|11 |`[n[0...4],n[5],n[6...A]]`|
|
|
101
|
+
|
|
102
|
+
## Delete
|
|
103
|
+
|
|
104
|
+
`delete` returns `['leaf', [] | Leaf1]` | `['branch', Branch1 | Branch3 | Branch5]`
|
|
105
|
+
|
|
106
|
+
|type |index|r |
|
|
107
|
+
|------------------|-----|---------------------------------|
|
|
108
|
+
|`[v]` | 0|leaf `[]` |
|
|
109
|
+
|`[v0,v1]` | 0|leaf `[v1]` |
|
|
110
|
+
| | 1|leaf `[v2]` |
|
|
111
|
+
|`[n0,v1,n2]` | 1|branch `concat(n0,n2)` |
|
|
112
|
+
|`[n0,v1,n2,v3,n4]`| 1|branch `[...concat(n0,n2),v3,n4]`|
|
|
113
|
+
| | 3|branch `[n0,v1,...concat(n2,n4)]`|
|
|
114
|
+
|
|
115
|
+
|type |index|nR | |
|
|
116
|
+
|------------------|-----|-------|----------------------------------------|
|
|
117
|
+
|`[n0,v1,n2]` | 0|`[]` |`[[v1, v20]]` |
|
|
118
|
+
| | | |`[[v1],v20,[v21]]` |
|
|
119
|
+
| | |`[nR0]`|`[[nR0, v1, n20, v21, n22]]` |
|
|
120
|
+
| | | |`[[nR0, v1, n20], v21, [n22, v23, n23]]`|
|
|
121
|
+
| | |`nR` |`[r,v1,n2]` |
|
|
122
|
+
| | 2|`[]` |`[[v00, v1]]` |
|
|
123
|
+
| | | |`[[v00],v01,[v1]]` |
|
|
124
|
+
| | |`[nR0]`|`[[n00, v01, n02, v1, nR0]]` |
|
|
125
|
+
| | | |`[[n00, v01, n02], v02, [n03, v1, nR0]]`|
|
|
126
|
+
| | |`nR` |`[n0,v1,r]` |
|
|
127
|
+
|`[n0,v1,n2,v3,n4]`| 0|`[]` |`[[v1,v20],v3,n4]` |
|
|
128
|
+
| | | |`[[v1],v20,[v21],v3,n4]` |
|
|
129
|
+
| | |`[nR0]`|`[[nR0,v1,n20,v21,n22],v3,n4]` |
|
|
130
|
+
| | | |`[[nR0,v1,n20],v21,[n22,v23,n24],v3,n4]`|
|
|
131
|
+
| | |`nR` |`[nR,v1,n2,v3,n4]` |
|
|
132
|
+
| | 2|`[]` |`[[v00,v1],v3,n4]` |
|
|
133
|
+
| | | |`[[v00],v01,[v1],v3,n4]` |
|
|
134
|
+
| | |`[nR0]`|`[[n00,v01,n02,v1,nR0],v3,n4]` |
|
|
135
|
+
| | | |`[[n00,v01,n02],v03,[n04,v1,nR0],v3,n4]`|
|
|
136
|
+
| | |`nR` |`[n0,v1,nR,v2,n4]` |
|
|
137
|
+
| | 4|`[]` |`[n0,v1,[v20,v3]]` |
|
|
138
|
+
| | | |`[n0,v1,[v20],v21,[v3]]` |
|
|
139
|
+
| | |`[nR0]`|`[n0,v1,[n20,v21,n22,v3,nR0]]` |
|
|
140
|
+
| | | |`[n0,v1,[n20,v21,n22],v23,[n24,v3,nR0]]`|
|
|
141
|
+
| | |`nR` |`[n0,v1,n2,v3,nR]` |
|
|
142
|
+
|
|
143
|
+
## Insert
|
|
144
|
+
|
|
145
|
+
`insert` returns `Branch1` or `Branch3`
|
|
146
|
+
|
|
147
|
+
|type | |size|
|
|
148
|
+
|------------------|---------------------------------|----|
|
|
149
|
+
|`[v]` |`[[vI,v]]` | |
|
|
150
|
+
| |`[[v,vI]]` | |
|
|
151
|
+
|`[v0,v1]` |`[[vI],v0,[v1]]` | |
|
|
152
|
+
| |`[[v0],vI,[v1]]` | |
|
|
153
|
+
| |`[[v0],v1,[vI]]` | |
|
|
154
|
+
|`[n0,v1,n2]` |`up([...insert(n0),v1,n2])` |3..5|
|
|
155
|
+
| |`up([n0,v1,...insert(n2)])` |3..5|
|
|
156
|
+
|`[n0,v1,n2,v3,n4]`|`up([...insert(n0),v1,n2,v3,n4])`|5..7|
|
|
157
|
+
| |`up([n0,v1,...insert(n2),v3,n4])`|5..7|
|
|
158
|
+
| |`up([n0,v1,n2,v3,...insert(n4)])`|5..7|
|
package/types/btree/index.js
CHANGED
|
@@ -395,8 +395,13 @@ const up = n => {
|
|
|
395
395
|
* @typedef {readonly[...Head2<T>, ...Head2<T>]} Head4
|
|
396
396
|
*/
|
|
397
397
|
|
|
398
|
-
/**
|
|
399
|
-
|
|
398
|
+
/**
|
|
399
|
+
* @template T
|
|
400
|
+
* @typedef {Head2<T>|Head4<T>} Head
|
|
401
|
+
*/
|
|
402
|
+
|
|
403
|
+
/** @type {<T>(n: Branch3<T> | Branch5<T>) => readonly[Head<T>, Node<T>]} */
|
|
404
|
+
const headLast = n => {
|
|
400
405
|
if (n.length === 3) {
|
|
401
406
|
const [n0, v1, n2] = n
|
|
402
407
|
return [[n0, v1], n2]
|
|
@@ -421,9 +426,9 @@ const concat = a => b => {
|
|
|
421
426
|
default: {
|
|
422
427
|
switch (b.length) {
|
|
423
428
|
case 3: case 5: {
|
|
424
|
-
const [aHead, aLast] =
|
|
425
|
-
const [
|
|
426
|
-
return up([...aHead, ...concat(aLast)(
|
|
429
|
+
const [aHead, aLast] = headLast(a)
|
|
430
|
+
const [bFirst, ...bTail] = b
|
|
431
|
+
return up([...aHead, ...concat(aLast)(bFirst), ...bTail])
|
|
427
432
|
}
|
|
428
433
|
default: { throw 'invalid b node' }
|
|
429
434
|
}
|
package/types/btree/test.js
CHANGED
|
@@ -5,8 +5,10 @@ const { sort } = require('../object')
|
|
|
5
5
|
const { stringCmp } = require('../function/compare')
|
|
6
6
|
const list = require('../list')
|
|
7
7
|
|
|
8
|
+
const jsonStr = json.stringify(sort)
|
|
9
|
+
|
|
8
10
|
/** @type {(sequence: list.List<json.Unknown>) => string} */
|
|
9
|
-
const stringify = sequence =>
|
|
11
|
+
const stringify = sequence => jsonStr(list.toArray(sequence))
|
|
10
12
|
|
|
11
13
|
/** @type {(node: btree.Node<string>) => (value: string) => btree.Node<string>} */
|
|
12
14
|
const set = node => value => {
|
|
@@ -62,29 +64,40 @@ const set = node => value => {
|
|
|
62
64
|
for (let i = 2; i <= 10; i++)
|
|
63
65
|
_map = set(_map)((i * i).toString())
|
|
64
66
|
if (_map.length !== 3) { throw _map }
|
|
65
|
-
|
|
67
|
+
let _s = jsonStr(_map)
|
|
68
|
+
if (_s !== '[[["1","100"],"16",["25","36"]],"4",[["49"],"64",["81","9"]]]') { throw _s }
|
|
69
|
+
|
|
66
70
|
let [a,,b] = _map
|
|
67
71
|
let _c = concat(a)(b)
|
|
68
|
-
// console.log(_c)
|
|
69
72
|
if (_c.length !== 3) { throw _c }
|
|
73
|
+
_s =jsonStr(_c);
|
|
74
|
+
if (_s !== '[[["1","100"],"16",["25"]],"36",[["49"],"64",["81","9"]]]') { throw _s }
|
|
75
|
+
|
|
70
76
|
[a,,b] = _c
|
|
71
77
|
_c = concat(a)(b)
|
|
72
|
-
// console.log(_c)
|
|
73
78
|
if (_c.length !== 1) { throw _c }
|
|
79
|
+
_s = jsonStr(_c);
|
|
80
|
+
if (_s !== '[[["1","100"],"16",["25","49"],"64",["81","9"]]]') { throw _s }
|
|
81
|
+
|
|
74
82
|
let [_r] = _c
|
|
75
83
|
if (_r.length !== 5) { throw _r }
|
|
76
84
|
[a,,b] = _r
|
|
77
85
|
_c = concat(a)(b)
|
|
78
|
-
// console.log(_c)
|
|
79
86
|
if (_c.length !== 3) { throw _c }
|
|
87
|
+
_s = jsonStr(_c);
|
|
88
|
+
if (_s !== '[["1"],"100",["25","49"]]') { throw _s }
|
|
89
|
+
|
|
80
90
|
[a,,b] = _c
|
|
81
91
|
_c = concat(a)(b)
|
|
82
|
-
// console.log(_c)
|
|
83
92
|
if (_c.length !== 3) { throw _c }
|
|
93
|
+
_s = jsonStr(_c);
|
|
94
|
+
if (_s !== '[["1"],"25",["49"]]') { throw _s }
|
|
95
|
+
|
|
84
96
|
[a,,b] = _c
|
|
85
97
|
_c = concat(a)(b)
|
|
86
|
-
// console.log(_c)
|
|
87
98
|
if (_c.length !== 1) { throw _c }
|
|
99
|
+
_s = jsonStr(_c);
|
|
100
|
+
if (_s !== '[["1","49"]]') { throw _s }
|
|
88
101
|
}
|
|
89
102
|
|
|
90
103
|
const test = () => {
|