@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,229 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `graph` kind: directed or undirected graphs with optional edge
|
|
3
|
+
* weights, for traversals, shortest paths, spanning trees, topological
|
|
4
|
+
* sorting and flows.
|
|
5
|
+
*
|
|
6
|
+
* Node ids double as names: the shorthand `"nodes": ["A", "B"]` declares
|
|
7
|
+
* nodes A and B, and the edge `["A", "B", 4]` gets the id `A-B`.
|
|
8
|
+
*
|
|
9
|
+
* Marks: `highlight` lasts one step; `visit`, `settle`, `group`, `pointer`,
|
|
10
|
+
* `annotate` and `markEdge` persist until changed or `resetMarks`.
|
|
11
|
+
*/
|
|
12
|
+
import { z } from 'zod';
|
|
13
|
+
import { ElementId, Group, LIMITS, Place, PointerName, Scalar, } from "../common.js";
|
|
14
|
+
import { typesOf } from "./kind.js";
|
|
15
|
+
const Coordinate = z.number().min(-1e5).max(1e5);
|
|
16
|
+
export const GraphNode = z
|
|
17
|
+
.strictObject({
|
|
18
|
+
id: ElementId,
|
|
19
|
+
value: Scalar,
|
|
20
|
+
x: Coordinate.optional(),
|
|
21
|
+
y: Coordinate.optional(),
|
|
22
|
+
})
|
|
23
|
+
.describe('A node. `x` and `y` place it by hand (units are pixels at 1×; used by the "manual" layout).');
|
|
24
|
+
const NodeInput = z
|
|
25
|
+
.union([
|
|
26
|
+
GraphNode.extend({ value: Scalar.optional() }),
|
|
27
|
+
z.string(),
|
|
28
|
+
z.number(),
|
|
29
|
+
])
|
|
30
|
+
.describe('A node, or a bare name such as "A" or 3 that serves as both id and value. Without `value`, a node shows its id.');
|
|
31
|
+
const NodeRef = ElementId.describe('A node id.');
|
|
32
|
+
const EdgeRef = ElementId.describe('An edge id, by default "from-to".');
|
|
33
|
+
const Weight = Scalar.describe('Shown beside the edge: a weight, a capacity, or text such as "3/5".');
|
|
34
|
+
export const GraphEdge = z
|
|
35
|
+
.strictObject({
|
|
36
|
+
id: ElementId,
|
|
37
|
+
from: NodeRef,
|
|
38
|
+
to: NodeRef,
|
|
39
|
+
weight: Weight.optional(),
|
|
40
|
+
})
|
|
41
|
+
.describe('An edge; in undirected graphs `from` and `to` are interchangeable.');
|
|
42
|
+
const EdgeInput = z
|
|
43
|
+
.union([
|
|
44
|
+
GraphEdge.extend({ id: ElementId.optional() }),
|
|
45
|
+
z.tuple([NodeRef, NodeRef]),
|
|
46
|
+
z.tuple([NodeRef, NodeRef, Weight]),
|
|
47
|
+
])
|
|
48
|
+
.describe('An edge, or `[from, to]` / `[from, to, weight]`. The id defaults to "from-to".');
|
|
49
|
+
export const GraphLayout = z
|
|
50
|
+
.enum(['auto', 'circle', 'layered', 'grid', 'manual'])
|
|
51
|
+
.describe('"layered" ranks nodes top to bottom along edges (good for DAGs and trees); "circle" places them on a circle; "grid" in rows; "manual" uses each node’s x and y. "auto" (default) is manual when every node has x and y, else layered for acyclic directed graphs, else circle.');
|
|
52
|
+
export const GraphDecl = z
|
|
53
|
+
.strictObject({
|
|
54
|
+
kind: z.literal('graph'),
|
|
55
|
+
label: z.string().max(LIMITS.textLength).optional(),
|
|
56
|
+
place: Place.optional(),
|
|
57
|
+
directed: z.boolean(),
|
|
58
|
+
layout: GraphLayout,
|
|
59
|
+
nodes: z.array(GraphNode).max(LIMITS.elementsPerStructure),
|
|
60
|
+
edges: z.array(GraphEdge).max(LIMITS.edgesPerStructure),
|
|
61
|
+
})
|
|
62
|
+
.describe('A graph.');
|
|
63
|
+
export const GraphDeclInput = z.strictObject({
|
|
64
|
+
kind: z.literal('graph'),
|
|
65
|
+
label: z.string().max(LIMITS.textLength).optional(),
|
|
66
|
+
place: Place.optional(),
|
|
67
|
+
directed: z.boolean().optional().describe('Default false.'),
|
|
68
|
+
layout: GraphLayout.optional(),
|
|
69
|
+
nodes: z.array(NodeInput).max(LIMITS.elementsPerStructure).optional(),
|
|
70
|
+
edges: z.array(EdgeInput).max(LIMITS.edgesPerStructure).optional(),
|
|
71
|
+
});
|
|
72
|
+
const normalizeNode = (input) => typeof input === 'object'
|
|
73
|
+
? { ...input, value: input.value === undefined ? input.id : input.value }
|
|
74
|
+
: { id: String(input), value: input };
|
|
75
|
+
const normalizeEdge = (input) => {
|
|
76
|
+
if (Array.isArray(input)) {
|
|
77
|
+
const [from, to, weight] = input;
|
|
78
|
+
return {
|
|
79
|
+
id: `${from}-${to}`,
|
|
80
|
+
from,
|
|
81
|
+
to,
|
|
82
|
+
...(weight === undefined ? {} : { weight }),
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
return { ...input, id: input.id ?? `${input.from}-${input.to}` };
|
|
86
|
+
};
|
|
87
|
+
function normalizeGraphDecl(input) {
|
|
88
|
+
const { nodes, edges, directed, layout, ...rest } = input;
|
|
89
|
+
return {
|
|
90
|
+
...rest,
|
|
91
|
+
directed: directed ?? false,
|
|
92
|
+
layout: layout ?? 'auto',
|
|
93
|
+
nodes: (nodes ?? []).map(normalizeNode),
|
|
94
|
+
edges: (edges ?? []).map(normalizeEdge),
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
/** Ids generated from names must still be valid ids. */
|
|
98
|
+
function idIssues(id, path) {
|
|
99
|
+
return ElementId.safeParse(id).success
|
|
100
|
+
? []
|
|
101
|
+
: [
|
|
102
|
+
{
|
|
103
|
+
path,
|
|
104
|
+
message: `"${id}" is not a valid id`,
|
|
105
|
+
hint: 'Ids use letters, digits and _ . : - (at most 64). Give the node as { "id", "value" } to show other text.',
|
|
106
|
+
},
|
|
107
|
+
];
|
|
108
|
+
}
|
|
109
|
+
export function validateGraphDecl(decl) {
|
|
110
|
+
const nodes = new Set(decl.nodes.map((n) => n.id));
|
|
111
|
+
const issues = decl.nodes.flatMap((n, k) => idIssues(n.id, ['nodes', k]));
|
|
112
|
+
decl.edges.forEach((edge, k) => {
|
|
113
|
+
issues.push(...idIssues(edge.id, ['edges', k]));
|
|
114
|
+
for (const end of ['from', 'to'])
|
|
115
|
+
if (!nodes.has(edge[end]))
|
|
116
|
+
issues.push({
|
|
117
|
+
path: ['edges', k, end],
|
|
118
|
+
message: `Edge "${edge.id}" ends at "${edge[end]}", which is not a node`,
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
if (decl.layout === 'manual')
|
|
122
|
+
decl.nodes.forEach((n, k) => {
|
|
123
|
+
if (n.x === undefined || n.y === undefined)
|
|
124
|
+
issues.push({
|
|
125
|
+
path: ['nodes', k],
|
|
126
|
+
message: `Node "${n.id}" needs x and y for the manual layout`,
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
return issues;
|
|
130
|
+
}
|
|
131
|
+
const nodes = z.array(NodeRef).max(LIMITS.elementsPerStructure);
|
|
132
|
+
const edges = z.array(EdgeRef).max(LIMITS.edgesPerStructure);
|
|
133
|
+
const actions = (newNode, newEdge) => z.discriminatedUnion('type', [
|
|
134
|
+
z
|
|
135
|
+
.strictObject({ type: z.literal('addNode'), node: newNode })
|
|
136
|
+
.describe('Add a node.'),
|
|
137
|
+
z
|
|
138
|
+
.strictObject({ type: z.literal('removeNode'), node: NodeRef })
|
|
139
|
+
.describe('Remove a node and every edge at it.'),
|
|
140
|
+
z
|
|
141
|
+
.strictObject({
|
|
142
|
+
type: z.literal('setValue'),
|
|
143
|
+
node: NodeRef,
|
|
144
|
+
value: Scalar,
|
|
145
|
+
})
|
|
146
|
+
.describe('Change the text shown in a node.'),
|
|
147
|
+
z
|
|
148
|
+
.strictObject({ type: z.literal('addEdge'), edge: newEdge })
|
|
149
|
+
.describe('Add an edge between existing nodes.'),
|
|
150
|
+
z
|
|
151
|
+
.strictObject({ type: z.literal('removeEdge'), edge: EdgeRef })
|
|
152
|
+
.describe('Remove an edge.'),
|
|
153
|
+
z
|
|
154
|
+
.strictObject({
|
|
155
|
+
type: z.literal('setWeight'),
|
|
156
|
+
edge: EdgeRef,
|
|
157
|
+
weight: Weight.nullable(),
|
|
158
|
+
})
|
|
159
|
+
.describe('Change an edge’s weight or label; null removes it.'),
|
|
160
|
+
z
|
|
161
|
+
.strictObject({
|
|
162
|
+
type: z.literal('highlight'),
|
|
163
|
+
nodes: nodes.optional(),
|
|
164
|
+
edges: edges.optional(),
|
|
165
|
+
})
|
|
166
|
+
.describe('Highlight nodes and edges (this step only), e.g. an edge being relaxed.'),
|
|
167
|
+
z
|
|
168
|
+
.strictObject({ type: z.literal('visit'), node: NodeRef })
|
|
169
|
+
.describe('Mark a node as visited, e.g. discovered by a search.'),
|
|
170
|
+
z
|
|
171
|
+
.strictObject({ type: z.literal('settle'), node: NodeRef })
|
|
172
|
+
.describe('Mark a node as finished, e.g. its distance is final.'),
|
|
173
|
+
z
|
|
174
|
+
.strictObject({ type: z.literal('group'), node: NodeRef, group: Group })
|
|
175
|
+
.describe('Put a node in a categorical group 0–5 (e.g. a component or a colour); null removes it.'),
|
|
176
|
+
z
|
|
177
|
+
.strictObject({
|
|
178
|
+
type: z.literal('pointer'),
|
|
179
|
+
name: PointerName,
|
|
180
|
+
node: NodeRef.nullable(),
|
|
181
|
+
})
|
|
182
|
+
.describe('Point a named pointer at a node; null removes it.'),
|
|
183
|
+
z
|
|
184
|
+
.strictObject({
|
|
185
|
+
type: z.literal('annotate'),
|
|
186
|
+
node: NodeRef,
|
|
187
|
+
text: z.string().max(32).nullable(),
|
|
188
|
+
})
|
|
189
|
+
.describe('Show a short note above a node, e.g. a distance "d=4" or "∞"; null removes it.'),
|
|
190
|
+
z
|
|
191
|
+
.strictObject({
|
|
192
|
+
type: z.literal('markEdge'),
|
|
193
|
+
edge: EdgeRef,
|
|
194
|
+
mark: z.enum(['selected', 'rejected']).nullable(),
|
|
195
|
+
})
|
|
196
|
+
.describe('Mark an edge as selected (e.g. in the spanning tree or shortest-path tree) or rejected (e.g. it would close a cycle); null clears it.'),
|
|
197
|
+
z
|
|
198
|
+
.strictObject({ type: z.literal('resetMarks') })
|
|
199
|
+
.describe('Clear every mark: visits, settled nodes, groups, pointers, notes and edge marks.'),
|
|
200
|
+
]);
|
|
201
|
+
export const GraphAction = actions(GraphNode, GraphEdge);
|
|
202
|
+
export const GraphActionInput = actions(NodeInput, EdgeInput);
|
|
203
|
+
export const graphSpec = {
|
|
204
|
+
kind: 'graph',
|
|
205
|
+
decl: GraphDecl,
|
|
206
|
+
declInput: GraphDeclInput,
|
|
207
|
+
action: GraphAction,
|
|
208
|
+
actionInput: GraphActionInput,
|
|
209
|
+
actionTypes: typesOf(GraphAction),
|
|
210
|
+
normalizeDecl: normalizeGraphDecl,
|
|
211
|
+
declIds: (decl) => [
|
|
212
|
+
...decl.nodes.map((n, k) => ({ id: n.id, path: ['nodes', k] })),
|
|
213
|
+
...decl.edges.map((e, k) => ({ id: e.id, path: ['edges', k] })),
|
|
214
|
+
],
|
|
215
|
+
validateDecl: validateGraphDecl,
|
|
216
|
+
normalizeAction: (input) => {
|
|
217
|
+
if (input.type === 'addNode')
|
|
218
|
+
return { ...input, node: normalizeNode(input.node) };
|
|
219
|
+
if (input.type === 'addEdge')
|
|
220
|
+
return { ...input, edge: normalizeEdge(input.edge) };
|
|
221
|
+
return input;
|
|
222
|
+
},
|
|
223
|
+
introducedIds: (action) => action.type === 'addNode'
|
|
224
|
+
? [{ id: action.node.id, path: ['node'] }]
|
|
225
|
+
: action.type === 'addEdge'
|
|
226
|
+
? [{ id: action.edge.id, path: ['edge'] }]
|
|
227
|
+
: [],
|
|
228
|
+
};
|
|
229
|
+
//# sourceMappingURL=graph.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graph.js","sourceRoot":"","sources":["../../src/kinds/graph.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EACL,SAAS,EACT,KAAK,EACL,MAAM,EACN,KAAK,EACL,WAAW,EACX,MAAM,GACP,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,OAAO,EAA6C,MAAM,WAAW,CAAC;AAE/E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,EAAE,MAAM,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC;QAC1C,CAAC,CAAC,MAAM,CAAC,IAAI,KAAK,SAAS;YACzB,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC;YAC1C,CAAC,CAAC,EAAE;CACX,CAAC"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `hashTable` kind: a hash table with separate chaining. Each bucket
|
|
3
|
+
* holds a chain of elements, addressed as `bucket` and `index` in the
|
|
4
|
+
* chain. (Open addressing needs no kind of its own: it is an array.)
|
|
5
|
+
*
|
|
6
|
+
* The hash function is the author's: actions name the bucket, and step
|
|
7
|
+
* narration can show the computation.
|
|
8
|
+
*
|
|
9
|
+
* Marks: `highlight` lasts one step; `settle` persists until `resetMarks`.
|
|
10
|
+
*/
|
|
11
|
+
import { z } from 'zod';
|
|
12
|
+
import { type KindSpec } from './kind.ts';
|
|
13
|
+
export declare const HashTableDecl: z.ZodObject<{
|
|
14
|
+
kind: z.ZodLiteral<"hashTable">;
|
|
15
|
+
label: z.ZodOptional<z.ZodString>;
|
|
16
|
+
place: z.ZodOptional<z.ZodEnum<{
|
|
17
|
+
main: "main";
|
|
18
|
+
side: "side";
|
|
19
|
+
}>>;
|
|
20
|
+
buckets: z.ZodArray<z.ZodArray<z.ZodObject<{
|
|
21
|
+
id: z.ZodString;
|
|
22
|
+
value: z.ZodUnion<readonly [z.ZodNumber, z.ZodString, z.ZodBoolean, z.ZodNull]>;
|
|
23
|
+
}, z.core.$strict>>>;
|
|
24
|
+
}, z.core.$strict>;
|
|
25
|
+
export type HashTableDecl = z.infer<typeof HashTableDecl>;
|
|
26
|
+
export declare const HashTableDeclInput: z.ZodObject<{
|
|
27
|
+
kind: z.ZodLiteral<"hashTable">;
|
|
28
|
+
label: z.ZodOptional<z.ZodString>;
|
|
29
|
+
place: z.ZodOptional<z.ZodEnum<{
|
|
30
|
+
main: "main";
|
|
31
|
+
side: "side";
|
|
32
|
+
}>>;
|
|
33
|
+
size: z.ZodOptional<z.ZodInt>;
|
|
34
|
+
initial: z.ZodOptional<z.ZodArray<z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
|
|
35
|
+
id: z.ZodString;
|
|
36
|
+
value: z.ZodUnion<readonly [z.ZodNumber, z.ZodString, z.ZodBoolean, z.ZodNull]>;
|
|
37
|
+
}, z.core.$strict>, z.ZodUnion<readonly [z.ZodNumber, z.ZodString, z.ZodBoolean, z.ZodNull]>]>>>>;
|
|
38
|
+
buckets: z.ZodOptional<z.ZodArray<z.ZodArray<z.ZodObject<{
|
|
39
|
+
id: z.ZodString;
|
|
40
|
+
value: z.ZodUnion<readonly [z.ZodNumber, z.ZodString, z.ZodBoolean, z.ZodNull]>;
|
|
41
|
+
}, z.core.$strict>>>>;
|
|
42
|
+
}, z.core.$strict>;
|
|
43
|
+
export type HashTableDeclInput = z.infer<typeof HashTableDeclInput>;
|
|
44
|
+
export declare const HashTableAction: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
45
|
+
type: z.ZodLiteral<"insert">;
|
|
46
|
+
bucket: z.ZodInt;
|
|
47
|
+
element: z.ZodObject<{
|
|
48
|
+
id: z.ZodString;
|
|
49
|
+
value: z.ZodUnion<readonly [z.ZodNumber, z.ZodString, z.ZodBoolean, z.ZodNull]>;
|
|
50
|
+
}, z.core.$strict>;
|
|
51
|
+
index: z.ZodOptional<z.ZodInt>;
|
|
52
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
53
|
+
type: z.ZodLiteral<"remove">;
|
|
54
|
+
bucket: z.ZodInt;
|
|
55
|
+
index: z.ZodInt;
|
|
56
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
57
|
+
type: z.ZodLiteral<"set">;
|
|
58
|
+
bucket: z.ZodInt;
|
|
59
|
+
index: z.ZodInt;
|
|
60
|
+
value: z.ZodUnion<readonly [z.ZodNumber, z.ZodString, z.ZodBoolean, z.ZodNull]>;
|
|
61
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
62
|
+
type: z.ZodLiteral<"highlight">;
|
|
63
|
+
bucket: z.ZodInt;
|
|
64
|
+
indices: z.ZodOptional<z.ZodArray<z.ZodInt>>;
|
|
65
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
66
|
+
type: z.ZodLiteral<"settle">;
|
|
67
|
+
bucket: z.ZodInt;
|
|
68
|
+
index: z.ZodInt;
|
|
69
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
70
|
+
type: z.ZodLiteral<"resetMarks">;
|
|
71
|
+
}, z.core.$strict>], "type">;
|
|
72
|
+
export type HashTableAction = z.infer<typeof HashTableAction>;
|
|
73
|
+
export declare const HashTableActionInput: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
74
|
+
type: z.ZodLiteral<"insert">;
|
|
75
|
+
bucket: z.ZodInt;
|
|
76
|
+
element: z.ZodUnion<readonly [z.ZodObject<{
|
|
77
|
+
id: z.ZodString;
|
|
78
|
+
value: z.ZodUnion<readonly [z.ZodNumber, z.ZodString, z.ZodBoolean, z.ZodNull]>;
|
|
79
|
+
}, z.core.$strict>, z.ZodUnion<readonly [z.ZodNumber, z.ZodString, z.ZodBoolean, z.ZodNull]>]>;
|
|
80
|
+
index: z.ZodOptional<z.ZodInt>;
|
|
81
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
82
|
+
type: z.ZodLiteral<"remove">;
|
|
83
|
+
bucket: z.ZodInt;
|
|
84
|
+
index: z.ZodInt;
|
|
85
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
86
|
+
type: z.ZodLiteral<"set">;
|
|
87
|
+
bucket: z.ZodInt;
|
|
88
|
+
index: z.ZodInt;
|
|
89
|
+
value: z.ZodUnion<readonly [z.ZodNumber, z.ZodString, z.ZodBoolean, z.ZodNull]>;
|
|
90
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
91
|
+
type: z.ZodLiteral<"highlight">;
|
|
92
|
+
bucket: z.ZodInt;
|
|
93
|
+
indices: z.ZodOptional<z.ZodArray<z.ZodInt>>;
|
|
94
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
95
|
+
type: z.ZodLiteral<"settle">;
|
|
96
|
+
bucket: z.ZodInt;
|
|
97
|
+
index: z.ZodInt;
|
|
98
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
99
|
+
type: z.ZodLiteral<"resetMarks">;
|
|
100
|
+
}, z.core.$strict>], "type">;
|
|
101
|
+
export type HashTableActionInput = z.infer<typeof HashTableActionInput>;
|
|
102
|
+
export declare const hashTableSpec: KindSpec<{
|
|
103
|
+
decl: HashTableDecl;
|
|
104
|
+
declInput: HashTableDeclInput;
|
|
105
|
+
action: HashTableAction;
|
|
106
|
+
actionInput: HashTableActionInput;
|
|
107
|
+
}>;
|
|
108
|
+
//# sourceMappingURL=hash-table.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hash-table.d.ts","sourceRoot":"","sources":["../../src/kinds/hash-table.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAWxB,OAAO,EAAuC,KAAK,QAAQ,EAAE,MAAM,WAAW,CAAC;AAU/E,eAAO,MAAM,aAAa;;;;;;;;;;;kBAUyB,CAAC;AACpD,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,CAAC;AAE1D,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;kBAgCuB,CAAC;AACvD,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAuDpE,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;4BAAmB,CAAC;AAChD,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,eAAe,CAAC,CAAC;AAC9D,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;4BAAwB,CAAC;AAC1D,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAExE,eAAO,MAAM,aAAa,EAAE,QAAQ,CAAC;IACnC,IAAI,EAAE,aAAa,CAAC;IACpB,SAAS,EAAE,kBAAkB,CAAC;IAC9B,MAAM,EAAE,eAAe,CAAC;IACxB,WAAW,EAAE,oBAAoB,CAAC;CACnC,CAgCA,CAAC"}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `hashTable` kind: a hash table with separate chaining. Each bucket
|
|
3
|
+
* holds a chain of elements, addressed as `bucket` and `index` in the
|
|
4
|
+
* chain. (Open addressing needs no kind of its own: it is an array.)
|
|
5
|
+
*
|
|
6
|
+
* The hash function is the author's: actions name the bucket, and step
|
|
7
|
+
* narration can show the computation.
|
|
8
|
+
*
|
|
9
|
+
* Marks: `highlight` lasts one step; `settle` persists until `resetMarks`.
|
|
10
|
+
*/
|
|
11
|
+
import { z } from 'zod';
|
|
12
|
+
import { Element, ElementInput, Index, isElement, LIMITS, Place, Scalar, } from "../common.js";
|
|
13
|
+
import { typesOf } from "./kind.js";
|
|
14
|
+
const MAX_BUCKETS = 100;
|
|
15
|
+
const Bucket = z
|
|
16
|
+
.int()
|
|
17
|
+
.min(0)
|
|
18
|
+
.max(MAX_BUCKETS - 1)
|
|
19
|
+
.describe('Bucket number.');
|
|
20
|
+
export const HashTableDecl = z
|
|
21
|
+
.strictObject({
|
|
22
|
+
kind: z.literal('hashTable'),
|
|
23
|
+
label: z.string().max(LIMITS.textLength).optional(),
|
|
24
|
+
place: Place.optional(),
|
|
25
|
+
buckets: z
|
|
26
|
+
.array(z.array(Element).max(LIMITS.elementsPerStructure))
|
|
27
|
+
.min(1)
|
|
28
|
+
.max(MAX_BUCKETS),
|
|
29
|
+
})
|
|
30
|
+
.describe('A hash table with separate chaining.');
|
|
31
|
+
export const HashTableDeclInput = z
|
|
32
|
+
.strictObject({
|
|
33
|
+
kind: z.literal('hashTable'),
|
|
34
|
+
label: z.string().max(LIMITS.textLength).optional(),
|
|
35
|
+
place: Place.optional(),
|
|
36
|
+
size: z
|
|
37
|
+
.int()
|
|
38
|
+
.min(1)
|
|
39
|
+
.max(MAX_BUCKETS)
|
|
40
|
+
.optional()
|
|
41
|
+
.describe('Number of buckets; at least the length of `initial`.'),
|
|
42
|
+
initial: z
|
|
43
|
+
.array(z.array(ElementInput).max(LIMITS.elementsPerStructure))
|
|
44
|
+
.max(MAX_BUCKETS)
|
|
45
|
+
.optional()
|
|
46
|
+
.describe('Chains per bucket, e.g. [[10, 20], [], [7]]; bare values get ids e0, e1, … in reading order.'),
|
|
47
|
+
buckets: z
|
|
48
|
+
.array(z.array(Element).max(LIMITS.elementsPerStructure))
|
|
49
|
+
.min(1)
|
|
50
|
+
.max(MAX_BUCKETS)
|
|
51
|
+
.optional()
|
|
52
|
+
.describe('The canonical form: every bucket with explicit elements. Accepted so that parsed documents can be read again.'),
|
|
53
|
+
})
|
|
54
|
+
.refine((d) => d.buckets === undefined || d.initial === undefined, {
|
|
55
|
+
message: 'Give either `initial` or `buckets`, not both',
|
|
56
|
+
path: ['buckets'],
|
|
57
|
+
})
|
|
58
|
+
// The same rule for JSON Schema validators, which cannot run the refinement.
|
|
59
|
+
.meta({ not: { required: ['initial', 'buckets'] } });
|
|
60
|
+
function normalizeHashTableDecl(input) {
|
|
61
|
+
const { size, buckets: given, ...others } = input;
|
|
62
|
+
const { initial = given ?? [], ...rest } = others;
|
|
63
|
+
let next = 0;
|
|
64
|
+
const count = Math.max(size ?? 0, initial.length, 1);
|
|
65
|
+
const buckets = Array.from({ length: count }, (_, b) => (initial[b] ?? []).map((x) => isElement(x) ? x : { id: `e${next++}`, value: x }));
|
|
66
|
+
return { ...rest, buckets };
|
|
67
|
+
}
|
|
68
|
+
const actions = (element) => z.discriminatedUnion('type', [
|
|
69
|
+
z
|
|
70
|
+
.strictObject({
|
|
71
|
+
type: z.literal('insert'),
|
|
72
|
+
bucket: Bucket,
|
|
73
|
+
element,
|
|
74
|
+
index: Index.optional().describe('Position in the chain; default the end.'),
|
|
75
|
+
})
|
|
76
|
+
.describe('Insert an element into a bucket’s chain.'),
|
|
77
|
+
z
|
|
78
|
+
.strictObject({ type: z.literal('remove'), bucket: Bucket, index: Index })
|
|
79
|
+
.describe('Remove an element from a chain.'),
|
|
80
|
+
z
|
|
81
|
+
.strictObject({
|
|
82
|
+
type: z.literal('set'),
|
|
83
|
+
bucket: Bucket,
|
|
84
|
+
index: Index,
|
|
85
|
+
value: Scalar,
|
|
86
|
+
})
|
|
87
|
+
.describe('Change an element’s value, e.g. update the value for a key.'),
|
|
88
|
+
z
|
|
89
|
+
.strictObject({
|
|
90
|
+
type: z.literal('highlight'),
|
|
91
|
+
bucket: Bucket,
|
|
92
|
+
indices: z.array(Index).max(LIMITS.elementsPerStructure).optional(),
|
|
93
|
+
})
|
|
94
|
+
.describe('Highlight a bucket and, optionally, elements of its chain (this step only), e.g. while probing.'),
|
|
95
|
+
z
|
|
96
|
+
.strictObject({ type: z.literal('settle'), bucket: Bucket, index: Index })
|
|
97
|
+
.describe('Mark an element as found (persists).'),
|
|
98
|
+
z
|
|
99
|
+
.strictObject({ type: z.literal('resetMarks') })
|
|
100
|
+
.describe('Clear every mark.'),
|
|
101
|
+
]);
|
|
102
|
+
export const HashTableAction = actions(Element);
|
|
103
|
+
export const HashTableActionInput = actions(ElementInput);
|
|
104
|
+
export const hashTableSpec = {
|
|
105
|
+
kind: 'hashTable',
|
|
106
|
+
decl: HashTableDecl,
|
|
107
|
+
declInput: HashTableDeclInput,
|
|
108
|
+
action: HashTableAction,
|
|
109
|
+
actionInput: HashTableActionInput,
|
|
110
|
+
actionTypes: typesOf(HashTableAction),
|
|
111
|
+
normalizeDecl: normalizeHashTableDecl,
|
|
112
|
+
declIds: (decl) => decl.buckets.flatMap((chain, b) =>
|
|
113
|
+
// Reported against the authoring field, `initial`.
|
|
114
|
+
chain.map((e, k) => ({ id: e.id, path: ['initial', b, k, 'id'] }))),
|
|
115
|
+
validateDecl: (decl) => {
|
|
116
|
+
const total = decl.buckets.reduce((n, chain) => n + chain.length, 0);
|
|
117
|
+
return total <= LIMITS.elementsPerStructure
|
|
118
|
+
? []
|
|
119
|
+
: [
|
|
120
|
+
{
|
|
121
|
+
path: ['initial'],
|
|
122
|
+
message: `The table holds ${total} elements; at most ${LIMITS.elementsPerStructure} are allowed`,
|
|
123
|
+
},
|
|
124
|
+
];
|
|
125
|
+
},
|
|
126
|
+
normalizeAction: (input, ctx) => input.type === 'insert' && !isElement(input.element)
|
|
127
|
+
? { ...input, element: { id: ctx.allocateId('e'), value: input.element } }
|
|
128
|
+
: input,
|
|
129
|
+
introducedIds: (action) => action.type === 'insert'
|
|
130
|
+
? [{ id: action.element.id, path: ['element', 'id'] }]
|
|
131
|
+
: [],
|
|
132
|
+
};
|
|
133
|
+
//# sourceMappingURL=hash-table.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hash-table.js","sourceRoot":"","sources":["../../src/kinds/hash-table.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EACL,OAAO,EACP,YAAY,EACZ,KAAK,EACL,SAAS,EACT,MAAM,EACN,KAAK,EACL,MAAM,GACP,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,OAAO,EAA6C,MAAM,WAAW,CAAC;AAE/E,MAAM,WAAW,GAAG,GAAG,CAAC;AAExB,MAAM,MAAM,GAAG,CAAC;KACb,GAAG,EAAE;KACL,GAAG,CAAC,CAAC,CAAC;KACN,GAAG,CAAC,WAAW,GAAG,CAAC,CAAC;KACpB,QAAQ,CAAC,gBAAgB,CAAC,CAAC;AAE9B,MAAM,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,CAAC;IACD,eAAe,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,CAC9B,KAAK,CAAC,IAAI,KAAK,QAAQ,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,OAAO,CAAC;QAClD,CAAC,CAAC,EAAE,GAAG,KAAK,EAAE,OAAO,EAAE,EAAE,EAAE,EAAE,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,OAAO,EAAE,EAAE;QAC1E,CAAC,CAAE,KAAyB;IAChC,aAAa,EAAE,CAAC,MAAM,EAAE,EAAE,CACxB,MAAM,CAAC,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,98 @@
|
|
|
1
|
+
import type { KindSpec } from './kind.ts';
|
|
2
|
+
export * from './array.ts';
|
|
3
|
+
export * from './btree.ts';
|
|
4
|
+
export * from './graph.ts';
|
|
5
|
+
export * from './hash-table.ts';
|
|
6
|
+
export * from './kind.ts';
|
|
7
|
+
export * from './linked-list.ts';
|
|
8
|
+
export * from './plane.ts';
|
|
9
|
+
export * from './priority-queue.ts';
|
|
10
|
+
export * from './queue.ts';
|
|
11
|
+
export * from './stack.ts';
|
|
12
|
+
export * from './table.ts';
|
|
13
|
+
export * from './tree.ts';
|
|
14
|
+
declare const registry: {
|
|
15
|
+
array: KindSpec<{
|
|
16
|
+
decl: import("./array.ts").ArrayDecl;
|
|
17
|
+
declInput: import("./array.ts").ArrayDeclInput;
|
|
18
|
+
action: import("./array.ts").ArrayAction;
|
|
19
|
+
actionInput: import("./array.ts").ArrayActionInput;
|
|
20
|
+
}>;
|
|
21
|
+
stack: KindSpec<{
|
|
22
|
+
decl: import("./stack.ts").StackDecl;
|
|
23
|
+
declInput: import("./stack.ts").StackDeclInput;
|
|
24
|
+
action: import("./stack.ts").StackAction;
|
|
25
|
+
actionInput: import("./stack.ts").StackActionInput;
|
|
26
|
+
}>;
|
|
27
|
+
queue: KindSpec<{
|
|
28
|
+
decl: import("./queue.ts").QueueDecl;
|
|
29
|
+
declInput: import("./queue.ts").QueueDeclInput;
|
|
30
|
+
action: import("./queue.ts").QueueAction;
|
|
31
|
+
actionInput: import("./queue.ts").QueueActionInput;
|
|
32
|
+
}>;
|
|
33
|
+
linkedList: KindSpec<{
|
|
34
|
+
decl: import("./linked-list.ts").LinkedListDecl;
|
|
35
|
+
declInput: import("./linked-list.ts").LinkedListDeclInput;
|
|
36
|
+
action: import("./linked-list.ts").LinkedListAction;
|
|
37
|
+
actionInput: import("./linked-list.ts").LinkedListActionInput;
|
|
38
|
+
}>;
|
|
39
|
+
tree: KindSpec<{
|
|
40
|
+
decl: import("./tree.ts").TreeDecl;
|
|
41
|
+
declInput: import("./tree.ts").TreeDeclInput;
|
|
42
|
+
action: import("./tree.ts").TreeAction;
|
|
43
|
+
actionInput: import("./tree.ts").TreeActionInput;
|
|
44
|
+
}>;
|
|
45
|
+
graph: KindSpec<{
|
|
46
|
+
decl: import("./graph.ts").GraphDecl;
|
|
47
|
+
declInput: import("./graph.ts").GraphDeclInput;
|
|
48
|
+
action: import("./graph.ts").GraphAction;
|
|
49
|
+
actionInput: import("./graph.ts").GraphActionInput;
|
|
50
|
+
}>;
|
|
51
|
+
table: KindSpec<{
|
|
52
|
+
decl: import("./table.ts").TableDecl;
|
|
53
|
+
declInput: import("./table.ts").TableDeclInput;
|
|
54
|
+
action: import("./table.ts").TableAction;
|
|
55
|
+
actionInput: import("./table.ts").TableAction;
|
|
56
|
+
}>;
|
|
57
|
+
hashTable: KindSpec<{
|
|
58
|
+
decl: import("./hash-table.ts").HashTableDecl;
|
|
59
|
+
declInput: import("./hash-table.ts").HashTableDeclInput;
|
|
60
|
+
action: import("./hash-table.ts").HashTableAction;
|
|
61
|
+
actionInput: import("./hash-table.ts").HashTableActionInput;
|
|
62
|
+
}>;
|
|
63
|
+
priorityQueue: KindSpec<{
|
|
64
|
+
decl: import("./priority-queue.ts").PriorityQueueDecl;
|
|
65
|
+
declInput: import("./priority-queue.ts").PriorityQueueDeclInput;
|
|
66
|
+
action: import("./priority-queue.ts").PriorityQueueAction;
|
|
67
|
+
actionInput: import("./priority-queue.ts").PriorityQueueActionInput;
|
|
68
|
+
}>;
|
|
69
|
+
btree: KindSpec<{
|
|
70
|
+
decl: import("./btree.ts").BTreeDecl;
|
|
71
|
+
declInput: import("./btree.ts").BTreeDeclInput;
|
|
72
|
+
action: import("./btree.ts").BTreeAction;
|
|
73
|
+
actionInput: import("./btree.ts").BTreeActionInput;
|
|
74
|
+
}>;
|
|
75
|
+
plane: KindSpec<{
|
|
76
|
+
decl: import("./plane.ts").PlaneDecl;
|
|
77
|
+
declInput: import("./plane.ts").PlaneDeclInput;
|
|
78
|
+
action: import("./plane.ts").PlaneAction;
|
|
79
|
+
actionInput: import("./plane.ts").PlaneActionInput;
|
|
80
|
+
}>;
|
|
81
|
+
};
|
|
82
|
+
export type StructureKindName = keyof typeof registry;
|
|
83
|
+
/** The types of each kind, keyed by kind name. */
|
|
84
|
+
export type KindTypeMap = {
|
|
85
|
+
[K in StructureKindName]: (typeof registry)[K] extends KindSpec<infer T> ? T : never;
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* The registry, typed so that `kinds[k]` for a generic `K` is
|
|
89
|
+
* `KindSpec<KindTypeMap[K]>`; that lets callers dispatch on a kind name
|
|
90
|
+
* without a switch (TypeScript's "correlated union" pattern).
|
|
91
|
+
*/
|
|
92
|
+
export declare const kinds: {
|
|
93
|
+
readonly [K in StructureKindName]: KindSpec<KindTypeMap[K]>;
|
|
94
|
+
};
|
|
95
|
+
export declare const kindNames: StructureKindName[];
|
|
96
|
+
/** The action `type` values defined for a kind, e.g. `['set', 'swap', …]`. */
|
|
97
|
+
export declare const actionTypesOf: (kind: StructureKindName) => readonly string[];
|
|
98
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/kinds/index.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,QAAQ,EAAa,MAAM,WAAW,CAAC;AASrD,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC;AAChC,cAAc,WAAW,CAAC;AAC1B,cAAc,kBAAkB,CAAC;AACjC,cAAc,YAAY,CAAC;AAC3B,cAAc,qBAAqB,CAAC;AACpC,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAE1B,QAAA,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAYb,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG,MAAM,OAAO,QAAQ,CAAC;AAEtD,kDAAkD;AAClD,MAAM,MAAM,WAAW,GAAG;KACvB,CAAC,IAAI,iBAAiB,GAAG,CAAC,OAAO,QAAQ,CAAC,CAAC,CAAC,CAAC,SAAS,QAAQ,CAAC,MAAM,CAAC,CAAC,GACpE,CAAC,GACD,KAAK;CACV,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,KAAK,EAAE;IAClB,QAAQ,EAAE,CAAC,IAAI,iBAAiB,GAAG,QAAQ,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;CACjD,CAAC;AAEb,eAAO,MAAM,SAAS,EAA4B,iBAAiB,EAAE,CAAC;AAEtE,8EAA8E;AAC9E,eAAO,MAAM,aAAa,GAAI,MAAM,iBAAiB,KAAG,SAAS,MAAM,EAC9C,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Registry of built-in structure kinds (ADR 0012). Adding a kind means
|
|
3
|
+
* writing its module and adding one entry here and in `visualization.ts`.
|
|
4
|
+
*/
|
|
5
|
+
import { arraySpec } from "./array.js";
|
|
6
|
+
import { btreeSpec } from "./btree.js";
|
|
7
|
+
import { graphSpec } from "./graph.js";
|
|
8
|
+
import { hashTableSpec } from "./hash-table.js";
|
|
9
|
+
import { linkedListSpec } from "./linked-list.js";
|
|
10
|
+
import { planeSpec } from "./plane.js";
|
|
11
|
+
import { priorityQueueSpec } from "./priority-queue.js";
|
|
12
|
+
import { queueSpec } from "./queue.js";
|
|
13
|
+
import { stackSpec } from "./stack.js";
|
|
14
|
+
import { tableSpec } from "./table.js";
|
|
15
|
+
import { treeSpec } from "./tree.js";
|
|
16
|
+
export * from "./array.js";
|
|
17
|
+
export * from "./btree.js";
|
|
18
|
+
export * from "./graph.js";
|
|
19
|
+
export * from "./hash-table.js";
|
|
20
|
+
export * from "./kind.js";
|
|
21
|
+
export * from "./linked-list.js";
|
|
22
|
+
export * from "./plane.js";
|
|
23
|
+
export * from "./priority-queue.js";
|
|
24
|
+
export * from "./queue.js";
|
|
25
|
+
export * from "./stack.js";
|
|
26
|
+
export * from "./table.js";
|
|
27
|
+
export * from "./tree.js";
|
|
28
|
+
const registry = {
|
|
29
|
+
array: arraySpec,
|
|
30
|
+
stack: stackSpec,
|
|
31
|
+
queue: queueSpec,
|
|
32
|
+
linkedList: linkedListSpec,
|
|
33
|
+
tree: treeSpec,
|
|
34
|
+
graph: graphSpec,
|
|
35
|
+
table: tableSpec,
|
|
36
|
+
hashTable: hashTableSpec,
|
|
37
|
+
priorityQueue: priorityQueueSpec,
|
|
38
|
+
btree: btreeSpec,
|
|
39
|
+
plane: planeSpec,
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* The registry, typed so that `kinds[k]` for a generic `K` is
|
|
43
|
+
* `KindSpec<KindTypeMap[K]>`; that lets callers dispatch on a kind name
|
|
44
|
+
* without a switch (TypeScript's "correlated union" pattern).
|
|
45
|
+
*/
|
|
46
|
+
export const kinds = registry;
|
|
47
|
+
export const kindNames = Object.keys(registry);
|
|
48
|
+
/** The action `type` values defined for a kind, e.g. `['set', 'swap', …]`. */
|
|
49
|
+
export const actionTypesOf = (kind) => kinds[kind].actionTypes;
|
|
50
|
+
// Every entry must satisfy the generic contract.
|
|
51
|
+
const _check = registry;
|
|
52
|
+
void _check;
|
|
53
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/kinds/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAErC,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC;AAChC,cAAc,WAAW,CAAC;AAC1B,cAAc,kBAAkB,CAAC;AACjC,cAAc,YAAY,CAAC;AAC3B,cAAc,qBAAqB,CAAC;AACpC,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;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