functionalscript 0.2.0 → 0.2.2

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.
Files changed (248) hide show
  1. package/dev/module.mjs +1 -1
  2. package/jsr.json +59 -59
  3. package/out/com/cpp/module.f.mjs +123 -0
  4. package/out/com/cpp/test.f.mjs +40 -0
  5. package/out/com/cpp/testlib.f.mjs +7 -0
  6. package/out/com/cs/module.f.mjs +95 -0
  7. package/out/com/cs/test.f.mjs +43 -0
  8. package/out/com/cs/testlib.f.mjs +7 -0
  9. package/out/com/rust/module.f.mjs +213 -0
  10. package/out/com/rust/test.f.mjs +123 -0
  11. package/out/com/rust/testlib.f.mjs +7 -0
  12. package/out/com/test/build.f.mjs +98 -0
  13. package/out/com/test/build.mjs +40 -0
  14. package/out/com/types/module.f.mjs +51 -0
  15. package/out/com/types/testlib.f.mjs +30 -0
  16. package/out/commonjs/build/module.f.mjs +107 -0
  17. package/out/commonjs/build/test.f.mjs +102 -0
  18. package/out/commonjs/module/function/module.f.mjs +15 -0
  19. package/out/commonjs/module/module.f.mjs +48 -0
  20. package/out/commonjs/module.f.mjs +10 -0
  21. package/out/commonjs/module.mjs +26 -0
  22. package/out/commonjs/package/dependencies/module.f.mjs +21 -0
  23. package/out/commonjs/package/dependencies/test.f.mjs +15 -0
  24. package/out/commonjs/package/module.f.mjs +40 -0
  25. package/out/commonjs/package/test.f.mjs +27 -0
  26. package/out/commonjs/path/module.f.mjs +171 -0
  27. package/out/commonjs/path/test.f.mjs +231 -0
  28. package/out/commonjs/test.mjs +87 -0
  29. package/out/dev/index.mjs +2 -0
  30. package/out/dev/module.f.mjs +2 -0
  31. package/out/dev/module.mjs +167 -0
  32. package/out/dev/test/module.f.mjs +134 -0
  33. package/out/dev/test.f.mjs +58 -0
  34. package/out/dev/test.mjs +52 -0
  35. package/out/djs/module.f.mjs +75 -0
  36. package/out/djs/parser/module.f.mjs +432 -0
  37. package/out/djs/parser/test.f.mjs +535 -0
  38. package/out/djs/test.f.mjs +84 -0
  39. package/out/djs/tokenizer/module.f.mjs +87 -0
  40. package/out/djs/tokenizer/test.f.mjs +480 -0
  41. package/out/fsc/module.f.mjs +105 -0
  42. package/out/fsc/test.f.mjs +19 -0
  43. package/out/fsm/module.f.mjs +80 -0
  44. package/out/fsm/test.f.mjs +138 -0
  45. package/out/html/module.f.mjs +94 -0
  46. package/out/html/test.f.mjs +45 -0
  47. package/out/issues/test.f.mjs +66 -0
  48. package/out/js/tokenizer/module.f.mjs +686 -0
  49. package/out/js/tokenizer/test.f.mjs +844 -0
  50. package/out/json/module.f.mjs +89 -0
  51. package/out/json/parser/module.f.mjs +224 -0
  52. package/out/json/parser/test.f.mjs +321 -0
  53. package/out/json/serializer/module.f.mjs +67 -0
  54. package/out/json/serializer/test.f.mjs +87 -0
  55. package/out/json/test.f.mjs +61 -0
  56. package/out/json/tokenizer/module.f.mjs +78 -0
  57. package/out/json/tokenizer/test.f.mjs +420 -0
  58. package/out/nanvm-lib/tests/test.f.mjs +87 -0
  59. package/out/nodejs/version/main.mjs +3 -0
  60. package/out/nodejs/version/module.f.mjs +34 -0
  61. package/out/nodejs/version/test.f.mjs +97 -0
  62. package/out/prime_field/module.f.mjs +87 -0
  63. package/out/prime_field/test.f.mjs +145 -0
  64. package/out/secp/module.f.mjs +113 -0
  65. package/out/secp/test.f.mjs +63 -0
  66. package/out/sha2/module.f.mjs +172 -0
  67. package/out/sha2/test.f.mjs +86 -0
  68. package/out/text/ascii/module.f.mjs +154 -0
  69. package/out/text/ascii/test.f.mjs +14 -0
  70. package/out/text/module.f.mjs +19 -0
  71. package/out/text/sgr/module.f.mjs +17 -0
  72. package/out/text/test.f.mjs +19 -0
  73. package/out/text/utf16/module.f.mjs +86 -0
  74. package/out/text/utf16/test.f.mjs +145 -0
  75. package/out/text/utf8/module.f.mjs +126 -0
  76. package/out/text/utf8/test.f.mjs +175 -0
  77. package/out/types/array/module.f.mjs +95 -0
  78. package/out/types/array/test.f.mjs +116 -0
  79. package/out/types/bigfloat/module.f.mjs +77 -0
  80. package/out/types/bigfloat/test.f.mjs +349 -0
  81. package/out/types/bigint/module.f.mjs +114 -0
  82. package/out/types/bigint/test.f.mjs +192 -0
  83. package/out/types/btree/find/module.f.mjs +137 -0
  84. package/out/types/btree/find/test.f.mjs +156 -0
  85. package/out/types/btree/module.f.mjs +34 -0
  86. package/out/types/btree/remove/module.f.mjs +209 -0
  87. package/out/types/btree/remove/test.f.mjs +638 -0
  88. package/out/types/btree/set/module.f.mjs +114 -0
  89. package/out/types/btree/set/test.f.mjs +390 -0
  90. package/out/types/btree/test.f.mjs +83 -0
  91. package/out/types/btree/types/module.f.mjs +50 -0
  92. package/out/types/byte_set/module.f.mjs +42 -0
  93. package/out/types/byte_set/test.f.mjs +123 -0
  94. package/out/types/function/compare/module.f.mjs +22 -0
  95. package/out/types/function/compare/test.f.mjs +8 -0
  96. package/out/types/function/module.f.mjs +44 -0
  97. package/out/types/function/operator/module.f.mjs +60 -0
  98. package/out/types/function/test.f.mjs +15 -0
  99. package/out/types/list/module.f.mjs +269 -0
  100. package/out/types/list/test.f.mjs +401 -0
  101. package/out/types/map/module.f.mjs +54 -0
  102. package/out/types/map/test.f.mjs +115 -0
  103. package/out/types/nibble_set/module.f.mjs +19 -0
  104. package/out/types/nibble_set/test.f.mjs +90 -0
  105. package/out/types/nullable/module.f.mjs +9 -0
  106. package/out/types/nullable/test.f.mjs +12 -0
  107. package/out/types/number/module.f.mjs +12 -0
  108. package/out/types/number/test.f.mjs +126 -0
  109. package/out/types/object/module.f.mjs +27 -0
  110. package/out/types/object/test.f.mjs +17 -0
  111. package/out/types/range/module.f.mjs +6 -0
  112. package/out/types/range/test.f.mjs +18 -0
  113. package/out/types/range_map/module.f.mjs +84 -0
  114. package/out/types/range_map/test.f.mjs +201 -0
  115. package/out/types/result/module.f.mjs +25 -0
  116. package/out/types/result/module.mjs +16 -0
  117. package/out/types/sorted_list/module.f.mjs +102 -0
  118. package/out/types/sorted_list/test.f.mjs +66 -0
  119. package/out/types/sorted_set/module.f.mjs +29 -0
  120. package/out/types/sorted_set/test.f.mjs +80 -0
  121. package/out/types/string/module.f.mjs +17 -0
  122. package/out/types/string/test.f.mjs +58 -0
  123. package/out/types/string_set/module.f.mjs +29 -0
  124. package/out/types/string_set/test.f.mjs +65 -0
  125. package/package.json +5 -4
  126. package/tsconfig.json +2 -2
  127. /package/{com → out/com}/cpp/module.f.d.mts +0 -0
  128. /package/{com → out/com}/cpp/test.f.d.mts +0 -0
  129. /package/{com → out/com}/cpp/testlib.f.d.mts +0 -0
  130. /package/{com → out/com}/cs/module.f.d.mts +0 -0
  131. /package/{com → out/com}/cs/test.f.d.mts +0 -0
  132. /package/{com → out/com}/cs/testlib.f.d.mts +0 -0
  133. /package/{com → out/com}/rust/module.f.d.mts +0 -0
  134. /package/{com → out/com}/rust/test.f.d.mts +0 -0
  135. /package/{com → out/com}/rust/testlib.f.d.mts +0 -0
  136. /package/{com → out/com}/test/build.d.mts +0 -0
  137. /package/{com → out/com}/test/build.f.d.mts +0 -0
  138. /package/{com → out/com}/types/module.f.d.mts +0 -0
  139. /package/{com → out/com}/types/testlib.f.d.mts +0 -0
  140. /package/{commonjs → out/commonjs}/build/module.f.d.mts +0 -0
  141. /package/{commonjs → out/commonjs}/build/test.f.d.mts +0 -0
  142. /package/{commonjs → out/commonjs}/module/function/module.f.d.mts +0 -0
  143. /package/{commonjs → out/commonjs}/module/module.f.d.mts +0 -0
  144. /package/{commonjs → out/commonjs}/module.d.mts +0 -0
  145. /package/{commonjs → out/commonjs}/module.f.d.mts +0 -0
  146. /package/{commonjs → out/commonjs}/package/dependencies/module.f.d.mts +0 -0
  147. /package/{commonjs → out/commonjs}/package/dependencies/test.f.d.mts +0 -0
  148. /package/{commonjs → out/commonjs}/package/module.f.d.mts +0 -0
  149. /package/{commonjs → out/commonjs}/package/test.f.d.mts +0 -0
  150. /package/{commonjs → out/commonjs}/path/module.f.d.mts +0 -0
  151. /package/{commonjs → out/commonjs}/path/test.f.d.mts +0 -0
  152. /package/{commonjs → out/commonjs}/test.d.mts +0 -0
  153. /package/{dev → out/dev}/index.d.mts +0 -0
  154. /package/{dev → out/dev}/module.d.mts +0 -0
  155. /package/{dev → out/dev}/module.f.d.mts +0 -0
  156. /package/{dev → out/dev}/test/module.f.d.mts +0 -0
  157. /package/{dev → out/dev}/test.d.mts +0 -0
  158. /package/{dev → out/dev}/test.f.d.mts +0 -0
  159. /package/{djs → out/djs}/module.f.d.mts +0 -0
  160. /package/{djs → out/djs}/parser/module.f.d.mts +0 -0
  161. /package/{djs → out/djs}/parser/test.f.d.mts +0 -0
  162. /package/{djs → out/djs}/test.f.d.mts +0 -0
  163. /package/{djs → out/djs}/tokenizer/module.f.d.mts +0 -0
  164. /package/{djs → out/djs}/tokenizer/test.f.d.mts +0 -0
  165. /package/{fsc → out/fsc}/module.f.d.mts +0 -0
  166. /package/{fsc → out/fsc}/test.f.d.mts +0 -0
  167. /package/{fsm → out/fsm}/module.f.d.mts +0 -0
  168. /package/{fsm → out/fsm}/test.f.d.mts +0 -0
  169. /package/{html → out/html}/module.f.d.mts +0 -0
  170. /package/{html → out/html}/test.f.d.mts +0 -0
  171. /package/{issues → out/issues}/test.f.d.mts +0 -0
  172. /package/{js → out/js}/tokenizer/module.f.d.mts +0 -0
  173. /package/{js → out/js}/tokenizer/test.f.d.mts +0 -0
  174. /package/{json → out/json}/module.f.d.mts +0 -0
  175. /package/{json → out/json}/parser/module.f.d.mts +0 -0
  176. /package/{json → out/json}/parser/test.f.d.mts +0 -0
  177. /package/{json → out/json}/serializer/module.f.d.mts +0 -0
  178. /package/{json → out/json}/serializer/test.f.d.mts +0 -0
  179. /package/{json → out/json}/test.f.d.mts +0 -0
  180. /package/{json → out/json}/tokenizer/module.f.d.mts +0 -0
  181. /package/{json → out/json}/tokenizer/test.f.d.mts +0 -0
  182. /package/{nanvm-lib → out/nanvm-lib}/tests/test.f.d.mts +0 -0
  183. /package/{nodejs → out/nodejs}/version/main.d.mts +0 -0
  184. /package/{nodejs → out/nodejs}/version/module.f.d.mts +0 -0
  185. /package/{nodejs → out/nodejs}/version/test.f.d.mts +0 -0
  186. /package/{prime_field → out/prime_field}/module.f.d.mts +0 -0
  187. /package/{prime_field → out/prime_field}/test.f.d.mts +0 -0
  188. /package/{secp → out/secp}/module.f.d.mts +0 -0
  189. /package/{secp → out/secp}/test.f.d.mts +0 -0
  190. /package/{sha2 → out/sha2}/module.f.d.mts +0 -0
  191. /package/{sha2 → out/sha2}/test.f.d.mts +0 -0
  192. /package/{text → out/text}/ascii/module.f.d.mts +0 -0
  193. /package/{text → out/text}/ascii/test.f.d.mts +0 -0
  194. /package/{text → out/text}/module.f.d.mts +0 -0
  195. /package/{text → out/text}/sgr/module.f.d.mts +0 -0
  196. /package/{text → out/text}/test.f.d.mts +0 -0
  197. /package/{text → out/text}/utf16/module.f.d.mts +0 -0
  198. /package/{text → out/text}/utf16/test.f.d.mts +0 -0
  199. /package/{text → out/text}/utf8/module.f.d.mts +0 -0
  200. /package/{text → out/text}/utf8/test.f.d.mts +0 -0
  201. /package/{types → out/types}/array/module.f.d.mts +0 -0
  202. /package/{types → out/types}/array/test.f.d.mts +0 -0
  203. /package/{types → out/types}/bigfloat/module.f.d.mts +0 -0
  204. /package/{types → out/types}/bigfloat/test.f.d.mts +0 -0
  205. /package/{types → out/types}/bigint/module.f.d.mts +0 -0
  206. /package/{types → out/types}/bigint/test.f.d.mts +0 -0
  207. /package/{types → out/types}/btree/find/module.f.d.mts +0 -0
  208. /package/{types → out/types}/btree/find/test.f.d.mts +0 -0
  209. /package/{types → out/types}/btree/module.f.d.mts +0 -0
  210. /package/{types → out/types}/btree/remove/module.f.d.mts +0 -0
  211. /package/{types → out/types}/btree/remove/test.f.d.mts +0 -0
  212. /package/{types → out/types}/btree/set/module.f.d.mts +0 -0
  213. /package/{types → out/types}/btree/set/test.f.d.mts +0 -0
  214. /package/{types → out/types}/btree/test.f.d.mts +0 -0
  215. /package/{types → out/types}/btree/types/module.f.d.mts +0 -0
  216. /package/{types → out/types}/byte_set/module.f.d.mts +0 -0
  217. /package/{types → out/types}/byte_set/test.f.d.mts +0 -0
  218. /package/{types → out/types}/function/compare/module.f.d.mts +0 -0
  219. /package/{types → out/types}/function/compare/test.f.d.mts +0 -0
  220. /package/{types → out/types}/function/module.f.d.mts +0 -0
  221. /package/{types → out/types}/function/operator/module.f.d.mts +0 -0
  222. /package/{types → out/types}/function/test.f.d.mts +0 -0
  223. /package/{types → out/types}/list/module.f.d.mts +0 -0
  224. /package/{types → out/types}/list/test.f.d.mts +0 -0
  225. /package/{types → out/types}/map/module.f.d.mts +0 -0
  226. /package/{types → out/types}/map/test.f.d.mts +0 -0
  227. /package/{types → out/types}/nibble_set/module.f.d.mts +0 -0
  228. /package/{types → out/types}/nibble_set/test.f.d.mts +0 -0
  229. /package/{types → out/types}/nullable/module.f.d.mts +0 -0
  230. /package/{types → out/types}/nullable/test.f.d.mts +0 -0
  231. /package/{types → out/types}/number/module.f.d.mts +0 -0
  232. /package/{types → out/types}/number/test.f.d.mts +0 -0
  233. /package/{types → out/types}/object/module.f.d.mts +0 -0
  234. /package/{types → out/types}/object/test.f.d.mts +0 -0
  235. /package/{types → out/types}/range/module.f.d.mts +0 -0
  236. /package/{types → out/types}/range/test.f.d.mts +0 -0
  237. /package/{types → out/types}/range_map/module.f.d.mts +0 -0
  238. /package/{types → out/types}/range_map/test.f.d.mts +0 -0
  239. /package/{types → out/types}/result/module.d.mts +0 -0
  240. /package/{types → out/types}/result/module.f.d.mts +0 -0
  241. /package/{types → out/types}/sorted_list/module.f.d.mts +0 -0
  242. /package/{types → out/types}/sorted_list/test.f.d.mts +0 -0
  243. /package/{types → out/types}/sorted_set/module.f.d.mts +0 -0
  244. /package/{types → out/types}/sorted_set/test.f.d.mts +0 -0
  245. /package/{types → out/types}/string/module.f.d.mts +0 -0
  246. /package/{types → out/types}/string/test.f.d.mts +0 -0
  247. /package/{types → out/types}/string_set/module.f.d.mts +0 -0
  248. /package/{types → out/types}/string_set/test.f.d.mts +0 -0
@@ -0,0 +1,137 @@
1
+ // @ts-self-types="./module.f.d.mts"
2
+ import * as _ from '../types/module.f.mjs';
3
+ import * as List from '../../list/module.f.mjs';
4
+ import * as cmp from '../../function/compare/module.f.mjs';
5
+ const { index3, index5 } = cmp;
6
+ import * as Array from '../../array/module.f.mjs';
7
+ /**
8
+ * @template T
9
+ * @typedef {readonly[cmp.Index3, _.Leaf1<T>]} FirstLeaf1
10
+ */
11
+ /**
12
+ * @template T
13
+ * @typedef {readonly[1, _.Branch3<T>]} FirstBranch3
14
+ */
15
+ /**
16
+ * @template T
17
+ * @typedef {readonly[cmp.Index5, _.Leaf2<T>]} FirstLeaf2
18
+ */
19
+ /**
20
+ * @template T
21
+ * @typedef {readonly[1|3, _.Branch5<T>]} FirstBranch5
22
+ */
23
+ /**
24
+ * @template T
25
+ * @typedef {FirstLeaf1<T> | FirstBranch3<T> | FirstLeaf2<T> | FirstBranch5<T>} First
26
+ */
27
+ /**
28
+ * @template T
29
+ * @typedef {readonly[0|2, _.Branch3<T>]} PathItem3
30
+ */
31
+ /**
32
+ * @template T
33
+ * @typedef {readonly[0|2|4, _.Branch5<T>]} PathItem5
34
+ */
35
+ /**
36
+ * @template T
37
+ * @typedef {PathItem3<T> | PathItem5<T>} PathItem
38
+ */
39
+ /** @type {<T>(item: PathItem<T>) => _.Node<T>} */
40
+ const child = item =>
41
+ /** @type {typeof item extends PathItem<infer T> ? _.Node<T> : never} */ (item[1][item[0]]);
42
+ /**
43
+ * @template T
44
+ * @typedef {List.List<PathItem<T>>} Path
45
+ */
46
+ /**
47
+ * @template T
48
+ * @typedef {{
49
+ * readonly first: First<T>,
50
+ * readonly tail: Path<T>
51
+ * }} Result<T>
52
+ */
53
+ /** @type {<T>(c: cmp.Compare<T>) => (node: _.Node<T>) => Result<T>} */
54
+ export const find = c => {
55
+ const i3 = index3(c);
56
+ const i5 = index5(c);
57
+ /** @typedef {typeof c extends cmp.Compare<infer T> ? T : never} T */
58
+ /** @type {(prior: Path<T>) => (node: _.Node<T>) => Result<T>} */
59
+ const f = tail => node => {
60
+ /** @type {(index: Array.KeyOf<typeof node>) => Result<T>} */
61
+ const append = index => {
62
+ const first = /** @type {PathItem<T>} */ ([index, node]);
63
+ return f({ first, tail })(child(first));
64
+ };
65
+ /** @type {(index: Array.KeyOf<typeof node>) => Result<T>} */
66
+ const done = index => ({ first: /** @type {First<T>} */ ([index, node]), tail });
67
+ switch (node.length) {
68
+ case 1: {
69
+ return done(i3(node[0]));
70
+ }
71
+ case 2: {
72
+ return done(i5(node));
73
+ }
74
+ case 3: {
75
+ const i = i3(node[1]);
76
+ switch (i) {
77
+ case 0:
78
+ case 2: {
79
+ return append(i);
80
+ }
81
+ case 1: {
82
+ return done(i);
83
+ }
84
+ }
85
+ }
86
+ case 5: {
87
+ const i = i5([node[1], node[3]]);
88
+ switch (i) {
89
+ case 0:
90
+ case 2:
91
+ case 4: {
92
+ return append(i);
93
+ }
94
+ case 1:
95
+ case 3: {
96
+ return done(i);
97
+ }
98
+ }
99
+ }
100
+ }
101
+ };
102
+ return f(null);
103
+ };
104
+ /** @type {<T>(first: First<T>) => boolean} */
105
+ export const isFound = ([i]) => {
106
+ switch (i) {
107
+ case 1:
108
+ case 3: {
109
+ return true;
110
+ }
111
+ default: {
112
+ return false;
113
+ }
114
+ }
115
+ };
116
+ /** @type {<T>(first: First<T>) => T | null} */
117
+ export const value = ([i, r]) => {
118
+ switch (i) {
119
+ case 1: {
120
+ switch (r.length) {
121
+ case 1:
122
+ case 2: {
123
+ return r[0];
124
+ }
125
+ default: {
126
+ return r[1];
127
+ }
128
+ }
129
+ }
130
+ case 3: {
131
+ return r.length === 2 ? r[1] : r[3];
132
+ }
133
+ default: {
134
+ return null;
135
+ }
136
+ }
137
+ };
@@ -0,0 +1,156 @@
1
+ import * as _ from './module.f.mjs';
2
+ import * as list from '../../list/module.f.mjs';
3
+ import * as json from '../../../json/module.f.mjs';
4
+ import * as o from '../../object/module.f.mjs';
5
+ const { sort } = o;
6
+ import * as btree from '../types/module.f.mjs';
7
+ import * as string from '../../string/module.f.mjs';
8
+ const { cmp } = string;
9
+ import * as s from '../set/module.f.mjs';
10
+ const jsonStr = json.stringify(sort);
11
+ /** @type {(node: btree.Node<string>) => (value: string) => btree.Node<string>} */
12
+ const set = node => value => s.set(cmp(value))(() => value)(node);
13
+ /** @type {(r: _.Result<json.Unknown>) => string} */
14
+ const str = r => jsonStr(list.toArray(list.map(x => x[0])(r)));
15
+ /** @type {(i: string) => (m: btree.Node<string>) => string} */
16
+ const find = i => m => str(_.find(cmp(i))(m));
17
+ const test = () => {
18
+ /** @type {btree.Node<string>} */
19
+ let _map = ['1'];
20
+ for (let i = 2; i <= 10; i++)
21
+ _map = set(_map)((i * i).toString());
22
+ {
23
+ const s = jsonStr(_map);
24
+ if (s !== '[[["1","100"],"16",["25","36"]],"4",[["49"],"64",["81","9"]]]') {
25
+ throw s;
26
+ }
27
+ }
28
+ //
29
+ {
30
+ const r = find("0")(_map);
31
+ if (r !== '[0,0,0]') {
32
+ throw r;
33
+ }
34
+ }
35
+ {
36
+ const r = find("1")(_map);
37
+ if (r !== '[1,0,0]') {
38
+ throw r;
39
+ }
40
+ }
41
+ {
42
+ const r = find("10")(_map);
43
+ if (r !== '[2,0,0]') {
44
+ throw r;
45
+ }
46
+ }
47
+ {
48
+ const r = find("100")(_map);
49
+ if (r !== '[3,0,0]') {
50
+ throw r;
51
+ }
52
+ }
53
+ {
54
+ const r = find("12")(_map);
55
+ if (r !== '[4,0,0]') {
56
+ throw r;
57
+ }
58
+ }
59
+ {
60
+ const r = find("16")(_map);
61
+ if (r !== '[1,0]') {
62
+ throw r;
63
+ }
64
+ }
65
+ {
66
+ const r = find("17")(_map);
67
+ if (r !== '[0,2,0]') {
68
+ throw r;
69
+ }
70
+ }
71
+ {
72
+ const r = find("25")(_map);
73
+ if (r !== '[1,2,0]') {
74
+ throw r;
75
+ }
76
+ }
77
+ {
78
+ const r = find("26")(_map);
79
+ if (r !== '[2,2,0]') {
80
+ throw r;
81
+ }
82
+ }
83
+ {
84
+ const r = find("36")(_map);
85
+ if (r !== '[3,2,0]') {
86
+ throw r;
87
+ }
88
+ }
89
+ {
90
+ const r = find("37")(_map);
91
+ if (r !== '[4,2,0]') {
92
+ throw r;
93
+ }
94
+ }
95
+ {
96
+ const r = find("4")(_map);
97
+ if (r !== '[1]') {
98
+ throw r;
99
+ }
100
+ }
101
+ {
102
+ const r = find("41")(_map);
103
+ if (r !== '[0,0,2]') {
104
+ throw r;
105
+ }
106
+ }
107
+ {
108
+ const r = find("49")(_map);
109
+ if (r !== '[1,0,2]') {
110
+ throw r;
111
+ }
112
+ }
113
+ {
114
+ const r = find("5")(_map);
115
+ if (r !== '[2,0,2]') {
116
+ throw r;
117
+ }
118
+ }
119
+ {
120
+ const r = find("64")(_map);
121
+ if (r !== '[1,2]') {
122
+ throw r;
123
+ }
124
+ }
125
+ {
126
+ const r = find("65")(_map);
127
+ if (r !== '[0,2,2]') {
128
+ throw r;
129
+ }
130
+ }
131
+ {
132
+ const r = find("81")(_map);
133
+ if (r !== '[1,2,2]') {
134
+ throw r;
135
+ }
136
+ }
137
+ {
138
+ const r = find("85")(_map);
139
+ if (r !== '[2,2,2]') {
140
+ throw r;
141
+ }
142
+ }
143
+ {
144
+ const r = find("9")(_map);
145
+ if (r !== '[3,2,2]') {
146
+ throw r;
147
+ }
148
+ }
149
+ {
150
+ const r = find("91")(_map);
151
+ if (r !== '[4,2,2]') {
152
+ throw r;
153
+ }
154
+ }
155
+ };
156
+ export default test;
@@ -0,0 +1,34 @@
1
+ // @ts-self-types="./module.f.d.mts"
2
+ import * as list from '../list/module.f.mjs';
3
+ const { flat } = list;
4
+ import * as n from '../nullable/module.f.mjs';
5
+ const { map } = n;
6
+ import * as _ from './types/module.f.mjs';
7
+ /** @type {<T>(node: _.Node<T>) => list.Thunk<T>} */
8
+ const nodeValues = node => () => {
9
+ switch (node.length) {
10
+ case 1:
11
+ case 2: {
12
+ return node;
13
+ }
14
+ case 3: {
15
+ return flat([
16
+ nodeValues(node[0]),
17
+ [node[1]],
18
+ nodeValues(node[2])
19
+ ]);
20
+ }
21
+ default: {
22
+ return flat([
23
+ nodeValues(node[0]),
24
+ [node[1]],
25
+ nodeValues(node[2]),
26
+ [node[3]],
27
+ nodeValues(node[4])
28
+ ]);
29
+ }
30
+ }
31
+ };
32
+ export const empty = null;
33
+ /** @type {<T>(tree: _.Tree<T>) => list.List<T>} */
34
+ export const values = map(nodeValues);
@@ -0,0 +1,209 @@
1
+ // @ts-self-types="./module.f.d.mts"
2
+ import * as _ from '../types/module.f.mjs';
3
+ import * as Cmp from '../../function/compare/module.f.mjs';
4
+ import * as find from '../find/module.f.mjs';
5
+ import * as list from '../../list/module.f.mjs';
6
+ const { fold, concat, next } = list;
7
+ import * as Array from '../../array/module.f.mjs';
8
+ import * as n from '../../nullable/module.f.mjs';
9
+ const { map } = n;
10
+ /**
11
+ * @template T
12
+ * @typedef {null | _.Leaf1<T>} Leaf01
13
+ */
14
+ /**
15
+ * @template T
16
+ * @typedef {{
17
+ * readonly first: Leaf01<T>,
18
+ * readonly tail: find.Path<T>
19
+ * }} RemovePath
20
+ */
21
+ /** @type {<T>(tail: find.Path<T>) => (n: _.Node<T>) => readonly[T, RemovePath<T>]} */
22
+ const path = tail => n => {
23
+ switch (n.length) {
24
+ case 1: {
25
+ return [n[0], { first: null, tail }];
26
+ }
27
+ case 2: {
28
+ return [n[0], { first: [n[1]], tail }];
29
+ }
30
+ case 3: {
31
+ return path({ first: [0, n], tail })(n[0]);
32
+ }
33
+ case 5: {
34
+ return path({ first: [0, n], tail })(n[0]);
35
+ }
36
+ }
37
+ };
38
+ /**
39
+ * @template T
40
+ * @typedef {_.Branch1<T> | _.Branch3<T> | _.Branch5<T>} Branch
41
+ */
42
+ /** @type {<T>(a: Branch<T>) => (n: _.Branch3<T>) => _.Branch1<T> | _.Branch3<T>} */
43
+ const reduceValue0 = a => n => {
44
+ const [, v1, n2] = n;
45
+ if (a.length === 1) {
46
+ switch (n2.length) {
47
+ case 3: {
48
+ return [[a[0], v1, ...n2]];
49
+ }
50
+ case 5: {
51
+ return [[a[0], v1, n2[0]], n2[1], [n2[2], n2[3], n2[4]]];
52
+ }
53
+ default: {
54
+ throw 'invalid node';
55
+ }
56
+ }
57
+ }
58
+ else {
59
+ return [a, v1, n2];
60
+ }
61
+ };
62
+ /** @type {<T>(a: Branch<T>) => (n: _.Branch3<T>) => _.Branch1<T> | _.Branch3<T>} */
63
+ const reduceValue2 = a => n => {
64
+ const [n0, v1,] = n;
65
+ if (a.length === 1) {
66
+ switch (n0.length) {
67
+ case 3: {
68
+ return [[...n0, v1, a[0]]];
69
+ }
70
+ case 5: {
71
+ return [[n0[0], n0[1], n0[2]], n0[3], [n0[4], v1, a[0]]];
72
+ }
73
+ default: {
74
+ throw 'invalid node';
75
+ }
76
+ }
77
+ }
78
+ else {
79
+ return [n0, v1, a];
80
+ }
81
+ };
82
+ /** @type {<T>(a: Leaf01<T>) => (n: _.Branch3<T>) => _.Branch1<T> | _.Branch3<T>} */
83
+ const initValue0 = a => n => {
84
+ const [, v1, n2] = n;
85
+ if (a === null) {
86
+ switch (n2.length) {
87
+ case 1: {
88
+ return [[v1, ...n2]];
89
+ }
90
+ case 2: {
91
+ return [[v1], n2[0], [n2[1]]];
92
+ }
93
+ default: {
94
+ throw 'invalid node';
95
+ }
96
+ }
97
+ }
98
+ else {
99
+ return [a, v1, n2];
100
+ }
101
+ };
102
+ /** @type {<T>(a: Leaf01<T>) => (n: _.Branch3<T>) => _.Branch1<T> | _.Branch3<T>} */
103
+ const initValue1 = a => n => {
104
+ const [n0, v1] = n;
105
+ if (a === null) {
106
+ switch (n0.length) {
107
+ case 1: {
108
+ return [[...n0, v1]];
109
+ }
110
+ case 2: {
111
+ return [[n0[0]], n0[1], [v1]];
112
+ }
113
+ default: {
114
+ throw 'invalid node';
115
+ }
116
+ }
117
+ }
118
+ else {
119
+ return [n0, v1, a];
120
+ }
121
+ };
122
+ /**
123
+ * @template A,T
124
+ * @typedef {(a: A) => (n: _.Branch3<T>) => _.Branch1<T> | _.Branch3<T>} Merge
125
+ */
126
+ /** @type {<A, T>(ms: Array.Array2<Merge<A, T>>) => (i: find.PathItem<T>) => (a: A) => Branch<T>} */
127
+ const reduceX = ms => ([i, n]) => a => {
128
+ const [m0, m2] = ms;
129
+ /** @typedef {typeof ms extends Array.Array2<Merge<infer A, infer T>> ? [A,T] : never} AT */
130
+ /** @typedef {AT[0]} A */
131
+ /** @typedef {AT[1]} T */
132
+ /** @type {(m: Merge<A, T>) => Branch<T>} */
133
+ const f = m => {
134
+ const ra = m(a);
135
+ return n.length === 3 ? ra(n) : [...ra([n[0], n[1], n[2]]), n[3], n[4]];
136
+ };
137
+ switch (i) {
138
+ case 0: {
139
+ return f(m0);
140
+ }
141
+ case 2: {
142
+ return f(m2);
143
+ }
144
+ case 4: {
145
+ return [n[0], n[1], ...m2(a)([n[2], n[3], n[4]])];
146
+ }
147
+ }
148
+ };
149
+ const reduce = fold(reduceX([reduceValue0, reduceValue2]));
150
+ const initReduce = reduceX([initValue0, initValue1]);
151
+ /** @type {<T>(c: Cmp.Compare<T>) => (node: _.Node<T>) => _.Tree<T>} */
152
+ export const nodeRemove = c => node => {
153
+ /** @typedef {typeof c extends Cmp.Compare<infer T> ? T : never} T */
154
+ /** @type {() => null | RemovePath<T>} */
155
+ const f = () => {
156
+ const { first, tail } = find.find(c)(node);
157
+ /** @type {(n: _.Node<T>) => (f: (v: T) => find.PathItem<T>) => RemovePath<T>} */
158
+ const branch = n => f => {
159
+ const [v, p] = path(/** @type {find.Path<T>} */ (null))(n);
160
+ return { first: p.first, tail: concat(p.tail)({ first: f(v), tail }) };
161
+ };
162
+ const [i, n] = first;
163
+ switch (i) {
164
+ case 1: {
165
+ switch (n.length) {
166
+ case 1: {
167
+ return { first: null, tail };
168
+ }
169
+ case 2: {
170
+ return { first: [n[1]], tail };
171
+ }
172
+ case 3: {
173
+ return branch(n[2])(v => [2, [n[0], v, n[2]]]);
174
+ }
175
+ case 5: {
176
+ return branch(n[2])(v => [2, [n[0], v, n[2], n[3], n[4]]]);
177
+ }
178
+ }
179
+ }
180
+ case 3: {
181
+ switch (n.length) {
182
+ case 2: {
183
+ return { first: [n[0]], tail };
184
+ }
185
+ case 5: {
186
+ return branch(n[4])(v => [4, [n[0], n[1], n[2], v, n[4]]]);
187
+ }
188
+ }
189
+ }
190
+ default: {
191
+ return null;
192
+ }
193
+ }
194
+ };
195
+ const r = f();
196
+ if (r === null) {
197
+ return node;
198
+ }
199
+ const { first, tail } = r;
200
+ const tailR = next(tail);
201
+ if (tailR === null) {
202
+ return first;
203
+ }
204
+ const { first: tf, tail: tt } = tailR;
205
+ const result = reduce(initReduce(tf)(first))(tt);
206
+ return result.length === 1 ? result[0] : result;
207
+ };
208
+ /** @type {<T>(c: Cmp.Compare<T>) => (tree: _.Tree<T>) => _.Tree<T>} */
209
+ export const remove = c => map(nodeRemove(c));