@algomotion/spec 0.0.0-stage → 1.0.0-alpha.1
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/LICENSE +675 -0
- package/dist/.tsbuildinfo +1 -0
- package/dist/common.d.ts +136 -0
- package/dist/common.d.ts.map +1 -0
- package/dist/common.js +181 -0
- package/dist/common.js.map +1 -0
- package/dist/errors.d.ts +71 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +43 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/json-schema.d.ts +3 -0
- package/dist/json-schema.d.ts.map +1 -0
- package/dist/json-schema.js +16 -0
- package/dist/json-schema.js.map +1 -0
- package/dist/kinds/array.d.ts +171 -0
- package/dist/kinds/array.d.ts.map +1 -0
- package/dist/kinds/array.js +179 -0
- package/dist/kinds/array.js.map +1 -0
- package/dist/kinds/btree.d.ts +190 -0
- package/dist/kinds/btree.d.ts.map +1 -0
- package/dist/kinds/btree.js +274 -0
- package/dist/kinds/btree.js.map +1 -0
- package/dist/kinds/graph.d.ts +227 -0
- package/dist/kinds/graph.d.ts.map +1 -0
- package/dist/kinds/graph.js +229 -0
- package/dist/kinds/graph.js.map +1 -0
- package/dist/kinds/hash-table.d.ts +108 -0
- package/dist/kinds/hash-table.d.ts.map +1 -0
- package/dist/kinds/hash-table.js +133 -0
- package/dist/kinds/hash-table.js.map +1 -0
- package/dist/kinds/index.d.ts +98 -0
- package/dist/kinds/index.d.ts.map +1 -0
- package/dist/kinds/index.js +53 -0
- package/dist/kinds/index.js.map +1 -0
- package/dist/kinds/kind.d.ts +73 -0
- package/dist/kinds/kind.d.ts.map +1 -0
- package/dist/kinds/kind.js +4 -0
- package/dist/kinds/kind.js.map +1 -0
- package/dist/kinds/linear.d.ts +24 -0
- package/dist/kinds/linear.d.ts.map +1 -0
- package/dist/kinds/linear.js +26 -0
- package/dist/kinds/linear.js.map +1 -0
- package/dist/kinds/linked-list.d.ts +132 -0
- package/dist/kinds/linked-list.d.ts.map +1 -0
- package/dist/kinds/linked-list.js +95 -0
- package/dist/kinds/linked-list.js.map +1 -0
- package/dist/kinds/plane.d.ts +190 -0
- package/dist/kinds/plane.d.ts.map +1 -0
- package/dist/kinds/plane.js +206 -0
- package/dist/kinds/plane.js.map +1 -0
- package/dist/kinds/priority-queue.d.ts +120 -0
- package/dist/kinds/priority-queue.d.ts.map +1 -0
- package/dist/kinds/priority-queue.js +108 -0
- package/dist/kinds/priority-queue.js.map +1 -0
- package/dist/kinds/queue.d.ts +94 -0
- package/dist/kinds/queue.d.ts.map +1 -0
- package/dist/kinds/queue.js +59 -0
- package/dist/kinds/queue.js.map +1 -0
- package/dist/kinds/stack.d.ts +70 -0
- package/dist/kinds/stack.d.ts.map +1 -0
- package/dist/kinds/stack.js +50 -0
- package/dist/kinds/stack.js.map +1 -0
- package/dist/kinds/table.d.ts +65 -0
- package/dist/kinds/table.d.ts.map +1 -0
- package/dist/kinds/table.js +116 -0
- package/dist/kinds/table.js.map +1 -0
- package/dist/kinds/tree.d.ts +272 -0
- package/dist/kinds/tree.d.ts.map +1 -0
- package/dist/kinds/tree.js +380 -0
- package/dist/kinds/tree.js.map +1 -0
- package/dist/parse.d.ts +26 -0
- package/dist/parse.d.ts.map +1 -0
- package/dist/parse.js +380 -0
- package/dist/parse.js.map +1 -0
- package/dist/result.d.ts +16 -0
- package/dist/result.d.ts.map +1 -0
- package/dist/result.js +3 -0
- package/dist/result.js.map +1 -0
- package/dist/share.d.ts +68 -0
- package/dist/share.d.ts.map +1 -0
- package/dist/share.js +319 -0
- package/dist/share.js.map +1 -0
- package/dist/version.d.ts +108 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +167 -0
- package/dist/version.js.map +1 -0
- package/dist/visualization.d.ts +3591 -0
- package/dist/visualization.d.ts.map +1 -0
- package/dist/visualization.js +131 -0
- package/dist/visualization.js.map +1 -0
- package/package.json +45 -4
- package/schema/visualization.schema.json +5717 -0
- package/README.md +0 -3
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `array` structure kind: a sequence of elements with stable ids.
|
|
3
|
+
*
|
|
4
|
+
* Mark semantics (implemented by the core reducer, documented here because
|
|
5
|
+
* they are part of the protocol):
|
|
6
|
+
* - `compare`, `highlight` and the swap mark set by `swap` are transient:
|
|
7
|
+
* they last for one step.
|
|
8
|
+
* - `pointer` and `settle` persist until changed.
|
|
9
|
+
*
|
|
10
|
+
* An array may carry a pattern (ADR 0037): a second row under the text,
|
|
11
|
+
* shifted so that its first element sits under text position `shift`.
|
|
12
|
+
* `align` moves it and `check` compares one of its elements with the text
|
|
13
|
+
* above; the reducer decides whether they match. The text is fixed while
|
|
14
|
+
* a pattern is aligned under it.
|
|
15
|
+
*/
|
|
16
|
+
import { z } from 'zod';
|
|
17
|
+
import { Element } from '../common.ts';
|
|
18
|
+
import { type DeclIssue, type KindSpec } from './kind.ts';
|
|
19
|
+
/** @deprecated Use `Element`; kept as the array-specific name. */
|
|
20
|
+
export declare const ArrayElement: z.ZodObject<{
|
|
21
|
+
id: z.ZodString;
|
|
22
|
+
value: z.ZodUnion<readonly [z.ZodNumber, z.ZodString, z.ZodBoolean, z.ZodNull]>;
|
|
23
|
+
}, z.core.$strict>;
|
|
24
|
+
export type ArrayElement = Element;
|
|
25
|
+
/** Most elements a pattern holds. */
|
|
26
|
+
export declare const MAX_PATTERN = 64;
|
|
27
|
+
/** Canonical declaration: every element has an explicit id. */
|
|
28
|
+
export declare const ArrayDecl: z.ZodObject<{
|
|
29
|
+
kind: z.ZodLiteral<"array">;
|
|
30
|
+
label: z.ZodOptional<z.ZodString>;
|
|
31
|
+
place: z.ZodOptional<z.ZodEnum<{
|
|
32
|
+
main: "main";
|
|
33
|
+
side: "side";
|
|
34
|
+
}>>;
|
|
35
|
+
view: z.ZodOptional<z.ZodEnum<{
|
|
36
|
+
row: "row";
|
|
37
|
+
tree: "tree";
|
|
38
|
+
heap: "heap";
|
|
39
|
+
}>>;
|
|
40
|
+
initial: z.ZodArray<z.ZodObject<{
|
|
41
|
+
id: z.ZodString;
|
|
42
|
+
value: z.ZodUnion<readonly [z.ZodNumber, z.ZodString, z.ZodBoolean, z.ZodNull]>;
|
|
43
|
+
}, z.core.$strict>>;
|
|
44
|
+
pattern: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
45
|
+
id: z.ZodString;
|
|
46
|
+
value: z.ZodUnion<readonly [z.ZodNumber, z.ZodString, z.ZodBoolean, z.ZodNull]>;
|
|
47
|
+
}, z.core.$strict>>>;
|
|
48
|
+
shift: z.ZodOptional<z.ZodInt>;
|
|
49
|
+
}, z.core.$strict>;
|
|
50
|
+
export type ArrayDecl = z.infer<typeof ArrayDecl>;
|
|
51
|
+
/**
|
|
52
|
+
* Authoring declaration: `initial` may also be a list of bare values, which
|
|
53
|
+
* are given ids e0, e1, …
|
|
54
|
+
*/
|
|
55
|
+
export declare const ArrayDeclInput: z.ZodObject<{
|
|
56
|
+
kind: z.ZodLiteral<"array">;
|
|
57
|
+
label: z.ZodOptional<z.ZodString>;
|
|
58
|
+
place: z.ZodOptional<z.ZodEnum<{
|
|
59
|
+
main: "main";
|
|
60
|
+
side: "side";
|
|
61
|
+
}>>;
|
|
62
|
+
view: z.ZodOptional<z.ZodEnum<{
|
|
63
|
+
row: "row";
|
|
64
|
+
tree: "tree";
|
|
65
|
+
heap: "heap";
|
|
66
|
+
}>>;
|
|
67
|
+
shift: z.ZodOptional<z.ZodInt>;
|
|
68
|
+
initial: z.ZodUnion<readonly [z.ZodArray<z.ZodObject<{
|
|
69
|
+
id: z.ZodString;
|
|
70
|
+
value: z.ZodUnion<readonly [z.ZodNumber, z.ZodString, z.ZodBoolean, z.ZodNull]>;
|
|
71
|
+
}, z.core.$strict>>, z.ZodArray<z.ZodUnion<readonly [z.ZodNumber, z.ZodString, z.ZodBoolean, z.ZodNull]>>]>;
|
|
72
|
+
pattern: z.ZodOptional<z.ZodUnion<readonly [z.ZodArray<z.ZodObject<{
|
|
73
|
+
id: z.ZodString;
|
|
74
|
+
value: z.ZodUnion<readonly [z.ZodNumber, z.ZodString, z.ZodBoolean, z.ZodNull]>;
|
|
75
|
+
}, z.core.$strict>>, z.ZodArray<z.ZodUnion<readonly [z.ZodNumber, z.ZodString, z.ZodBoolean, z.ZodNull]>>]>>;
|
|
76
|
+
}, z.core.$strict>;
|
|
77
|
+
export type ArrayDeclInput = z.infer<typeof ArrayDeclInput>;
|
|
78
|
+
/** Expands the bare-value shorthand into explicit elements (ADR 0007). */
|
|
79
|
+
export declare function normalizeArrayDecl(input: ArrayDeclInput): ArrayDecl;
|
|
80
|
+
/** A pattern needs the row view, and its shift is within the text. */
|
|
81
|
+
export declare function validateArrayDecl(decl: ArrayDecl): DeclIssue[];
|
|
82
|
+
export declare const ArrayAction: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
83
|
+
type: z.ZodLiteral<"set">;
|
|
84
|
+
index: z.ZodInt;
|
|
85
|
+
value: z.ZodUnion<readonly [z.ZodNumber, z.ZodString, z.ZodBoolean, z.ZodNull]>;
|
|
86
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
87
|
+
type: z.ZodLiteral<"swap">;
|
|
88
|
+
i: z.ZodInt;
|
|
89
|
+
j: z.ZodInt;
|
|
90
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
91
|
+
type: z.ZodLiteral<"insert">;
|
|
92
|
+
index: z.ZodInt;
|
|
93
|
+
element: z.ZodObject<{
|
|
94
|
+
id: z.ZodString;
|
|
95
|
+
value: z.ZodUnion<readonly [z.ZodNumber, z.ZodString, z.ZodBoolean, z.ZodNull]>;
|
|
96
|
+
}, z.core.$strict>;
|
|
97
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
98
|
+
type: z.ZodLiteral<"remove">;
|
|
99
|
+
index: z.ZodInt;
|
|
100
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
101
|
+
type: z.ZodLiteral<"compare">;
|
|
102
|
+
i: z.ZodInt;
|
|
103
|
+
j: z.ZodInt;
|
|
104
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
105
|
+
type: z.ZodLiteral<"highlight">;
|
|
106
|
+
indices: z.ZodArray<z.ZodInt>;
|
|
107
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
108
|
+
type: z.ZodLiteral<"pointer">;
|
|
109
|
+
name: z.ZodString;
|
|
110
|
+
index: z.ZodNullable<z.ZodInt>;
|
|
111
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
112
|
+
type: z.ZodLiteral<"settle">;
|
|
113
|
+
index: z.ZodInt;
|
|
114
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
115
|
+
type: z.ZodLiteral<"align">;
|
|
116
|
+
shift: z.ZodInt;
|
|
117
|
+
matched: z.ZodOptional<z.ZodInt>;
|
|
118
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
119
|
+
type: z.ZodLiteral<"check">;
|
|
120
|
+
j: z.ZodInt;
|
|
121
|
+
}, z.core.$strict>], "type">;
|
|
122
|
+
export type ArrayAction = z.infer<typeof ArrayAction>;
|
|
123
|
+
/** Authoring actions: `insert` also accepts a bare value. */
|
|
124
|
+
export declare const ArrayActionInput: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
125
|
+
type: z.ZodLiteral<"set">;
|
|
126
|
+
index: z.ZodInt;
|
|
127
|
+
value: z.ZodUnion<readonly [z.ZodNumber, z.ZodString, z.ZodBoolean, z.ZodNull]>;
|
|
128
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
129
|
+
type: z.ZodLiteral<"swap">;
|
|
130
|
+
i: z.ZodInt;
|
|
131
|
+
j: z.ZodInt;
|
|
132
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
133
|
+
type: z.ZodLiteral<"insert">;
|
|
134
|
+
index: z.ZodInt;
|
|
135
|
+
element: z.ZodUnion<readonly [z.ZodObject<{
|
|
136
|
+
id: z.ZodString;
|
|
137
|
+
value: z.ZodUnion<readonly [z.ZodNumber, z.ZodString, z.ZodBoolean, z.ZodNull]>;
|
|
138
|
+
}, z.core.$strict>, z.ZodUnion<readonly [z.ZodNumber, z.ZodString, z.ZodBoolean, z.ZodNull]>]>;
|
|
139
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
140
|
+
type: z.ZodLiteral<"remove">;
|
|
141
|
+
index: z.ZodInt;
|
|
142
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
143
|
+
type: z.ZodLiteral<"compare">;
|
|
144
|
+
i: z.ZodInt;
|
|
145
|
+
j: z.ZodInt;
|
|
146
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
147
|
+
type: z.ZodLiteral<"highlight">;
|
|
148
|
+
indices: z.ZodArray<z.ZodInt>;
|
|
149
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
150
|
+
type: z.ZodLiteral<"pointer">;
|
|
151
|
+
name: z.ZodString;
|
|
152
|
+
index: z.ZodNullable<z.ZodInt>;
|
|
153
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
154
|
+
type: z.ZodLiteral<"settle">;
|
|
155
|
+
index: z.ZodInt;
|
|
156
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
157
|
+
type: z.ZodLiteral<"align">;
|
|
158
|
+
shift: z.ZodInt;
|
|
159
|
+
matched: z.ZodOptional<z.ZodInt>;
|
|
160
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
161
|
+
type: z.ZodLiteral<"check">;
|
|
162
|
+
j: z.ZodInt;
|
|
163
|
+
}, z.core.$strict>], "type">;
|
|
164
|
+
export type ArrayActionInput = z.infer<typeof ArrayActionInput>;
|
|
165
|
+
export declare const arraySpec: KindSpec<{
|
|
166
|
+
decl: ArrayDecl;
|
|
167
|
+
declInput: ArrayDeclInput;
|
|
168
|
+
action: ArrayAction;
|
|
169
|
+
actionInput: ArrayActionInput;
|
|
170
|
+
}>;
|
|
171
|
+
//# s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,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAEhE,eAAO,MAAM,SAAS,EAAE,QAAQ,CAAC;IAC/B,IAAI,EAAE,SAAS,CAAC;IAChB,SAAS,EAAE,cAAc,CAAC;IAC1B,MAAM,EAAE,WAAW,CAAC;IACpB,WAAW,EAAE,gBAAgB,CAAC;CAC/B,CA2BA,CAAC"}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `array` structure kind: a sequence of elements with stable ids.
|
|
3
|
+
*
|
|
4
|
+
* Mark semantics (implemented by the core reducer, documented here because
|
|
5
|
+
* they are part of the protocol):
|
|
6
|
+
* - `compare`, `highlight` and the swap mark set by `swap` are transient:
|
|
7
|
+
* they last for one step.
|
|
8
|
+
* - `pointer` and `settle` persist until changed.
|
|
9
|
+
*
|
|
10
|
+
* An array may carry a pattern (ADR 0037): a second row under the text,
|
|
11
|
+
* shifted so that its first element sits under text position `shift`.
|
|
12
|
+
* `align` moves it and `check` compares one of its elements with the text
|
|
13
|
+
* above; the reducer decides whether they match. The text is fixed while
|
|
14
|
+
* a pattern is aligned under it.
|
|
15
|
+
*/
|
|
16
|
+
import { z } from 'zod';
|
|
17
|
+
import { Element, ElementInput, Index, isElement, LIMITS, Place, PointerName, Scalar, } from "../common.js";
|
|
18
|
+
import { typesOf } from "./kind.js";
|
|
19
|
+
/** @deprecated Use `Element`; kept as the array-specific name. */
|
|
20
|
+
export const ArrayElement = Element;
|
|
21
|
+
const View = z
|
|
22
|
+
.enum(['row', 'tree', 'heap'])
|
|
23
|
+
.optional()
|
|
24
|
+
.describe('How to draw the array: "row" (default); "tree", a complete binary tree where index i has children 2i+1 and 2i+2; or "heap", that tree with the row under it, both drawn from the one array, as textbooks draw heaps.');
|
|
25
|
+
/** Most elements a pattern holds. */
|
|
26
|
+
export const MAX_PATTERN = 64;
|
|
27
|
+
const Shift = z
|
|
28
|
+
.int()
|
|
29
|
+
.min(0)
|
|
30
|
+
.max(LIMITS.elementsPerStructure)
|
|
31
|
+
.optional()
|
|
32
|
+
.describe('Text position under which the pattern starts, from 0 to the text length (default 0).');
|
|
33
|
+
/** Canonical declaration: every element has an explicit id. */
|
|
34
|
+
export const ArrayDecl = z
|
|
35
|
+
.strictObject({
|
|
36
|
+
kind: z.literal('array'),
|
|
37
|
+
label: z.string().max(LIMITS.textLength).optional(),
|
|
38
|
+
place: Place.optional(),
|
|
39
|
+
view: View,
|
|
40
|
+
initial: z.array(Element).max(LIMITS.elementsPerStructure),
|
|
41
|
+
pattern: z.array(Element).min(1).max(MAX_PATTERN).optional(),
|
|
42
|
+
shift: Shift,
|
|
43
|
+
})
|
|
44
|
+
.describe('An array structure.');
|
|
45
|
+
/**
|
|
46
|
+
* Authoring declaration: `initial` may also be a list of bare values, which
|
|
47
|
+
* are given ids e0, e1, …
|
|
48
|
+
*/
|
|
49
|
+
export const ArrayDeclInput = ArrayDecl.extend({
|
|
50
|
+
initial: z
|
|
51
|
+
.union([
|
|
52
|
+
z.array(Element).max(LIMITS.elementsPerStructure),
|
|
53
|
+
z.array(Scalar).max(LIMITS.elementsPerStructure),
|
|
54
|
+
])
|
|
55
|
+
.describe('Initial contents: either bare values like [5, 3, 8] (ids "e0", "e1", … are generated) or elements like [{ "id": "a", "value": 5 }].'),
|
|
56
|
+
pattern: z
|
|
57
|
+
.union([
|
|
58
|
+
z.array(Element).min(1).max(MAX_PATTERN),
|
|
59
|
+
z.array(Scalar).min(1).max(MAX_PATTERN),
|
|
60
|
+
])
|
|
61
|
+
.optional()
|
|
62
|
+
.describe('A pattern drawn under the text at `shift`, for string matching: values (ids "p0", "p1", … are generated) or elements.'),
|
|
63
|
+
});
|
|
64
|
+
/** Expands the bare-value shorthand into explicit elements (ADR 0007). */
|
|
65
|
+
export function normalizeArrayDecl(input) {
|
|
66
|
+
const initial = input.initial.map((x, k) => isElement(x) ? x : { id: `e${k}`, value: x });
|
|
67
|
+
const { pattern: given, ...rest } = input;
|
|
68
|
+
if (given === undefined)
|
|
69
|
+
return { ...rest, initial };
|
|
70
|
+
// Generated pattern ids skip the ids already written.
|
|
71
|
+
const taken = new Set([
|
|
72
|
+
...initial.map((e) => e.id),
|
|
73
|
+
...given.filter(isElement).map((e) => e.id),
|
|
74
|
+
]);
|
|
75
|
+
let next = 0;
|
|
76
|
+
const fresh = () => {
|
|
77
|
+
while (taken.has(`p${next}`))
|
|
78
|
+
next++;
|
|
79
|
+
return `p${next++}`;
|
|
80
|
+
};
|
|
81
|
+
const pattern = given.map((x) => isElement(x) ? x : { id: fresh(), value: x });
|
|
82
|
+
return { ...rest, initial, pattern };
|
|
83
|
+
}
|
|
84
|
+
/** A pattern needs the row view, and its shift is within the text. */
|
|
85
|
+
export function validateArrayDecl(decl) {
|
|
86
|
+
const issues = [];
|
|
87
|
+
if (decl.pattern !== undefined && (decl.view ?? 'row') !== 'row')
|
|
88
|
+
issues.push({
|
|
89
|
+
path: ['pattern'],
|
|
90
|
+
message: `A pattern is drawn under a row; the "${decl.view}" view has none`,
|
|
91
|
+
hint: 'Leave out `view`, or set it to "row".',
|
|
92
|
+
});
|
|
93
|
+
if (decl.shift !== undefined && decl.pattern === undefined)
|
|
94
|
+
issues.push({
|
|
95
|
+
path: ['shift'],
|
|
96
|
+
message: 'A shift places a pattern, and this array has none',
|
|
97
|
+
});
|
|
98
|
+
if ((decl.shift ?? 0) > decl.initial.length)
|
|
99
|
+
issues.push({
|
|
100
|
+
path: ['shift'],
|
|
101
|
+
message: `The shift is ${decl.shift}, past the text of ${decl.initial.length} elements`,
|
|
102
|
+
hint: `Valid shifts are 0 to ${decl.initial.length}.`,
|
|
103
|
+
});
|
|
104
|
+
return issues;
|
|
105
|
+
}
|
|
106
|
+
const Indices = z.array(Index).min(1).max(LIMITS.elementsPerStructure);
|
|
107
|
+
const actions = (element) => z.discriminatedUnion('type', [
|
|
108
|
+
// Actions that change data.
|
|
109
|
+
z
|
|
110
|
+
.strictObject({ type: z.literal('set'), index: Index, value: Scalar })
|
|
111
|
+
.describe('Replace the value at `index`; the element keeps its id.'),
|
|
112
|
+
z
|
|
113
|
+
.strictObject({ type: z.literal('swap'), i: Index, j: Index })
|
|
114
|
+
.describe('Swap the elements at positions `i` and `j`, marking both as swapped for this step.'),
|
|
115
|
+
z
|
|
116
|
+
.strictObject({ type: z.literal('insert'), index: Index, element })
|
|
117
|
+
.describe('Insert `element` before position `index`; `index` equal to the length appends.'),
|
|
118
|
+
z
|
|
119
|
+
.strictObject({ type: z.literal('remove'), index: Index })
|
|
120
|
+
.describe('Remove the element at `index`.'),
|
|
121
|
+
// Actions that only change marks.
|
|
122
|
+
z
|
|
123
|
+
.strictObject({ type: z.literal('compare'), i: Index, j: Index })
|
|
124
|
+
.describe('Mark positions `i` and `j` as being compared (this step only).'),
|
|
125
|
+
z
|
|
126
|
+
.strictObject({ type: z.literal('highlight'), indices: Indices })
|
|
127
|
+
.describe('Highlight the given positions (this step only).'),
|
|
128
|
+
z
|
|
129
|
+
.strictObject({
|
|
130
|
+
type: z.literal('pointer'),
|
|
131
|
+
name: PointerName,
|
|
132
|
+
index: Index.nullable(),
|
|
133
|
+
})
|
|
134
|
+
.describe('Point the named pointer (e.g. "i", "lo") at `index`; null removes it.'),
|
|
135
|
+
z
|
|
136
|
+
.strictObject({ type: z.literal('settle'), index: Index })
|
|
137
|
+
.describe('Mark the element at `index` as in its final position.'),
|
|
138
|
+
// Actions on the pattern (ADR 0037).
|
|
139
|
+
z
|
|
140
|
+
.strictObject({
|
|
141
|
+
type: z.literal('align'),
|
|
142
|
+
shift: z.int().min(0).max(LIMITS.elementsPerStructure),
|
|
143
|
+
matched: z.int().min(0).max(MAX_PATTERN).optional(),
|
|
144
|
+
})
|
|
145
|
+
.describe('Move the pattern so that its first element is under text position `shift`; its first `matched` elements (default 0) are marked as matched, and must equal the text above them.'),
|
|
146
|
+
z
|
|
147
|
+
.strictObject({ type: z.literal('check'), j: Index })
|
|
148
|
+
.describe('Compare pattern element `j` with the text element above it (position shift + j): both are marked as compared in this step, and if they are equal, `j` is marked as matched until the next `align`.'),
|
|
149
|
+
]);
|
|
150
|
+
export const ArrayAction = actions(Element);
|
|
151
|
+
/** Authoring actions: `insert` also accepts a bare value. */
|
|
152
|
+
export const ArrayActionInput = actions(ElementInput);
|
|
153
|
+
export const arraySpec = {
|
|
154
|
+
kind: 'array',
|
|
155
|
+
decl: ArrayDecl,
|
|
156
|
+
declInput: ArrayDeclInput,
|
|
157
|
+
action: ArrayAction,
|
|
158
|
+
actionInput: ArrayActionInput,
|
|
159
|
+
actionTypes: typesOf(ArrayAction),
|
|
160
|
+
normalizeDecl: normalizeArrayDecl,
|
|
161
|
+
declIds: (decl) => [
|
|
162
|
+
...decl.initial.map((e, k) => ({ id: e.id, path: ['initial', k, 'id'] })),
|
|
163
|
+
...(decl.pattern ?? []).map((e, k) => ({
|
|
164
|
+
id: e.id,
|
|
165
|
+
path: ['pattern', k, 'id'],
|
|
166
|
+
})),
|
|
167
|
+
],
|
|
168
|
+
validateDecl: validateArrayDecl,
|
|
169
|
+
normalizeAction: (action, ctx) => action.type === 'insert' && !isElement(action.element)
|
|
170
|
+
? {
|
|
171
|
+
...action,
|
|
172
|
+
element: { id: ctx.allocateId('e'), value: action.element },
|
|
173
|
+
}
|
|
174
|
+
: action,
|
|
175
|
+
introducedIds: (action) => action.type === 'insert'
|
|
176
|
+
? [{ id: action.element.id, path: ['element', 'id'] }]
|
|
177
|
+
: [],
|
|
178
|
+
};
|
|
179
|
+
//# sourceMappingURL=array.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"array.js","sourceRoot":"","sources":["../../src/kinds/array.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EACL,OAAO,EACP,YAAY,EACZ,KAAK,EACL,SAAS,EACT,MAAM,EACN,KAAK,EACL,WAAW,EACX,MAAM,GACP,MAAM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AAC,IAAI,KAAK,QAAQ;QACtB,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,OAAO,CAAC,EAAE,EAAE,IAAI,EAAE,CAAC,SAAS,EAAE,IAAI,CAAC,EAAE,CAAC;QACtD,CAAC,CAAC,EAAE;CACT,CAAC"}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `btree` kind (ADR 0035): multiway search trees whose nodes hold
|
|
3
|
+
* several keys in order, such as B-trees and 2-3-4 trees. A node has no
|
|
4
|
+
* children (a leaf) or one more than its keys; child `i` hangs from the
|
|
5
|
+
* gap left of key `i`. Keys are elements: they keep their ids when they
|
|
6
|
+
* move between nodes, so a drawing can follow them.
|
|
7
|
+
*
|
|
8
|
+
* A tree always has a root: an empty tree is a root leaf with no keys, as
|
|
9
|
+
* CLRS's B-TREE-CREATE makes it. The kind enforces no minimum degree, no
|
|
10
|
+
* key order and no level leaves: recipes keep those rules. Every action
|
|
11
|
+
* keeps the shape valid.
|
|
12
|
+
*
|
|
13
|
+
* Marks: `highlight` lasts one step; `settle`, `pointer` and `annotate`
|
|
14
|
+
* persist.
|
|
15
|
+
*/
|
|
16
|
+
import { z } from 'zod';
|
|
17
|
+
import { type DeclIssue, type KindSpec } from './kind.ts';
|
|
18
|
+
/** Most keys one node holds. */
|
|
19
|
+
export declare const MAX_NODE_KEYS = 32;
|
|
20
|
+
export declare const BTreeNode: z.ZodObject<{
|
|
21
|
+
id: z.ZodString;
|
|
22
|
+
keys: z.ZodArray<z.ZodObject<{
|
|
23
|
+
id: z.ZodString;
|
|
24
|
+
value: z.ZodUnion<readonly [z.ZodNumber, z.ZodString, z.ZodBoolean, z.ZodNull]>;
|
|
25
|
+
}, z.core.$strict>>;
|
|
26
|
+
children: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
27
|
+
}, z.core.$strict>;
|
|
28
|
+
export type BTreeNode = z.infer<typeof BTreeNode>;
|
|
29
|
+
/** Canonical declaration. */
|
|
30
|
+
export declare const BTreeDecl: z.ZodObject<{
|
|
31
|
+
kind: z.ZodLiteral<"btree">;
|
|
32
|
+
label: z.ZodOptional<z.ZodString>;
|
|
33
|
+
place: z.ZodOptional<z.ZodEnum<{
|
|
34
|
+
main: "main";
|
|
35
|
+
side: "side";
|
|
36
|
+
}>>;
|
|
37
|
+
nodes: z.ZodArray<z.ZodObject<{
|
|
38
|
+
id: z.ZodString;
|
|
39
|
+
keys: z.ZodArray<z.ZodObject<{
|
|
40
|
+
id: z.ZodString;
|
|
41
|
+
value: z.ZodUnion<readonly [z.ZodNumber, z.ZodString, z.ZodBoolean, z.ZodNull]>;
|
|
42
|
+
}, z.core.$strict>>;
|
|
43
|
+
children: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
44
|
+
}, z.core.$strict>>;
|
|
45
|
+
root: z.ZodString;
|
|
46
|
+
}, z.core.$strict>;
|
|
47
|
+
export type BTreeDecl = z.infer<typeof BTreeDecl>;
|
|
48
|
+
export declare const BTreeDeclInput: z.ZodObject<{
|
|
49
|
+
kind: z.ZodLiteral<"btree">;
|
|
50
|
+
label: z.ZodOptional<z.ZodString>;
|
|
51
|
+
place: z.ZodOptional<z.ZodEnum<{
|
|
52
|
+
main: "main";
|
|
53
|
+
side: "side";
|
|
54
|
+
}>>;
|
|
55
|
+
nodes: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
56
|
+
id: z.ZodString;
|
|
57
|
+
keys: z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
|
|
58
|
+
id: z.ZodString;
|
|
59
|
+
value: z.ZodUnion<readonly [z.ZodNumber, z.ZodString, z.ZodBoolean, z.ZodNull]>;
|
|
60
|
+
}, z.core.$strict>, z.ZodUnion<readonly [z.ZodNumber, z.ZodString, z.ZodBoolean, z.ZodNull]>]>>;
|
|
61
|
+
children: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
62
|
+
}, z.core.$strict>>>;
|
|
63
|
+
root: z.ZodOptional<z.ZodString>;
|
|
64
|
+
}, z.core.$strict>;
|
|
65
|
+
export type BTreeDeclInput = z.infer<typeof BTreeDeclInput>;
|
|
66
|
+
/** Shape rules: size, child counts, one parent each, one root, no cycles. */
|
|
67
|
+
export declare function validateBTreeDecl(decl: BTreeDecl): DeclIssue[];
|
|
68
|
+
export declare const BTreeAction: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
69
|
+
type: z.ZodLiteral<"insertKey">;
|
|
70
|
+
node: z.ZodString;
|
|
71
|
+
index: z.ZodInt;
|
|
72
|
+
key: z.ZodObject<{
|
|
73
|
+
id: z.ZodString;
|
|
74
|
+
value: z.ZodUnion<readonly [z.ZodNumber, z.ZodString, z.ZodBoolean, z.ZodNull]>;
|
|
75
|
+
}, z.core.$strict>;
|
|
76
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
77
|
+
type: z.ZodLiteral<"removeKey">;
|
|
78
|
+
key: z.ZodString;
|
|
79
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
80
|
+
type: z.ZodLiteral<"setKey">;
|
|
81
|
+
key: z.ZodString;
|
|
82
|
+
value: z.ZodUnion<readonly [z.ZodNumber, z.ZodString, z.ZodBoolean, z.ZodNull]>;
|
|
83
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
84
|
+
type: z.ZodLiteral<"lift">;
|
|
85
|
+
key: z.ZodString;
|
|
86
|
+
over: z.ZodString;
|
|
87
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
88
|
+
type: z.ZodLiteral<"split">;
|
|
89
|
+
node: z.ZodString;
|
|
90
|
+
index: z.ZodInt;
|
|
91
|
+
newNode: z.ZodString;
|
|
92
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
93
|
+
type: z.ZodLiteral<"grow">;
|
|
94
|
+
newRoot: z.ZodString;
|
|
95
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
96
|
+
type: z.ZodLiteral<"merge">;
|
|
97
|
+
node: z.ZodString;
|
|
98
|
+
index: z.ZodInt;
|
|
99
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
100
|
+
type: z.ZodLiteral<"shrink">;
|
|
101
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
102
|
+
type: z.ZodLiteral<"borrow">;
|
|
103
|
+
node: z.ZodString;
|
|
104
|
+
child: z.ZodInt;
|
|
105
|
+
from: z.ZodEnum<{
|
|
106
|
+
left: "left";
|
|
107
|
+
right: "right";
|
|
108
|
+
}>;
|
|
109
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
110
|
+
type: z.ZodLiteral<"highlight">;
|
|
111
|
+
keys: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
112
|
+
nodes: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
113
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
114
|
+
type: z.ZodLiteral<"settle">;
|
|
115
|
+
key: z.ZodString;
|
|
116
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
117
|
+
type: z.ZodLiteral<"pointer">;
|
|
118
|
+
name: z.ZodString;
|
|
119
|
+
node: z.ZodNullable<z.ZodString>;
|
|
120
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
121
|
+
type: z.ZodLiteral<"annotate">;
|
|
122
|
+
node: z.ZodString;
|
|
123
|
+
text: z.ZodNullable<z.ZodString>;
|
|
124
|
+
}, z.core.$strict>], "type">;
|
|
125
|
+
export type BTreeAction = z.infer<typeof BTreeAction>;
|
|
126
|
+
export declare const BTreeActionInput: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
127
|
+
type: z.ZodLiteral<"insertKey">;
|
|
128
|
+
node: z.ZodString;
|
|
129
|
+
index: z.ZodInt;
|
|
130
|
+
key: z.ZodUnion<readonly [z.ZodObject<{
|
|
131
|
+
id: z.ZodString;
|
|
132
|
+
value: z.ZodUnion<readonly [z.ZodNumber, z.ZodString, z.ZodBoolean, z.ZodNull]>;
|
|
133
|
+
}, z.core.$strict>, z.ZodUnion<readonly [z.ZodNumber, z.ZodString, z.ZodBoolean, z.ZodNull]>]>;
|
|
134
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
135
|
+
type: z.ZodLiteral<"removeKey">;
|
|
136
|
+
key: z.ZodString;
|
|
137
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
138
|
+
type: z.ZodLiteral<"setKey">;
|
|
139
|
+
key: z.ZodString;
|
|
140
|
+
value: z.ZodUnion<readonly [z.ZodNumber, z.ZodString, z.ZodBoolean, z.ZodNull]>;
|
|
141
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
142
|
+
type: z.ZodLiteral<"lift">;
|
|
143
|
+
key: z.ZodString;
|
|
144
|
+
over: z.ZodString;
|
|
145
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
146
|
+
type: z.ZodLiteral<"split">;
|
|
147
|
+
node: z.ZodString;
|
|
148
|
+
index: z.ZodInt;
|
|
149
|
+
newNode: z.ZodString;
|
|
150
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
151
|
+
type: z.ZodLiteral<"grow">;
|
|
152
|
+
newRoot: z.ZodString;
|
|
153
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
154
|
+
type: z.ZodLiteral<"merge">;
|
|
155
|
+
node: z.ZodString;
|
|
156
|
+
index: z.ZodInt;
|
|
157
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
158
|
+
type: z.ZodLiteral<"shrink">;
|
|
159
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
160
|
+
type: z.ZodLiteral<"borrow">;
|
|
161
|
+
node: z.ZodString;
|
|
162
|
+
child: z.ZodInt;
|
|
163
|
+
from: z.ZodEnum<{
|
|
164
|
+
left: "left";
|
|
165
|
+
right: "right";
|
|
166
|
+
}>;
|
|
167
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
168
|
+
type: z.ZodLiteral<"highlight">;
|
|
169
|
+
keys: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
170
|
+
nodes: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
171
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
172
|
+
type: z.ZodLiteral<"settle">;
|
|
173
|
+
key: z.ZodString;
|
|
174
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
175
|
+
type: z.ZodLiteral<"pointer">;
|
|
176
|
+
name: z.ZodString;
|
|
177
|
+
node: z.ZodNullable<z.ZodString>;
|
|
178
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
179
|
+
type: z.ZodLiteral<"annotate">;
|
|
180
|
+
node: z.ZodString;
|
|
181
|
+
text: z.ZodNullable<z.ZodString>;
|
|
182
|
+
}, z.core.$strict>], "type">;
|
|
183
|
+
export type BTreeActionInput = z.infer<typeof BTreeActionInput>;
|
|
184
|
+
export declare const btreeSpec: KindSpec<{
|
|
185
|
+
decl: BTreeDecl;
|
|
186
|
+
declInput: BTreeDeclInput;
|
|
187
|
+
action: BTreeAction;
|
|
188
|
+
actionInput: BTreeActionInput;
|
|
189
|
+
}>;
|
|
190
|
+
//# sourceMappingURL=btree.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"btree.d.ts","sourceRoot":"","sources":["../../src/kinds/btree.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAYxB,OAAO,EAAW,KAAK,SAAS,EAAc,KAAK,QAAQ,EAAE,MAAM,WAAW,CAAC;AAE/E,gCAAgC;AAChC,eAAO,MAAM,aAAa,KAAK,CAAC;AAOhC,eAAO,MAAM,SAAS;;;;;;;kBAMoC,CAAC;AAC3D,MAAM,MAAM,SAAS,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,SAAS,CAAC,CAAC;AAiBlD,6BAA6B;AAC7B,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;kBAQkC,CAAC;AACzD,MAAM,MAAM,SAAS,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,SAAS,CAAC,CAAC;AAElD,eAAO,MAAM,cAAc;;;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