{"draft":null,"from":130,"to":131,"files":[{"path":"src/engine/graph.ts","added":58,"removed":0,"diff":"--- a/src/engine/graph.ts\n+++ b/src/engine/graph.ts\n@@ -15,6 +15,7 @@\n \tseqOf,\n \tstartNode,\n } from \"./keys.ts\";\n+import { OrderedIndex, orderedChildKey } from \"./ordered-index.ts\";\n import {\n \ttype GraphStateStorage,\n \ttype StateMap,\n@@ -631,6 +632,46 @@\n \t\telse yield* listOf(this.#runStarts.get(code));\n \t}\n \n+\tget hasOrderedChildren(): boolean {\n+\t\treturn this.#storage !== undefined;\n+\t}\n+\t#childPriority(n: number): string {\n+\t\tconst seq = this.writerSeqOf(n);\n+\t\treturn orderedChildKey({\n+\t\t\tn,\n+\t\t\treplaces: this.replacesN(n) ? 1 : 0,\n+\t\t\tlamport: this.lamportOfSeq(seq),\n+\t\t\tseq,\n+\t\t\tk: this.kOf(n),\n+\t\t});\n+\t}\n+\t/** Persistent layout order with a strict successor cursor; moves are separate. */\n+\t*orderedChildrenN(code: number, after?: number): IterableIterator<number> {\n+\t\tif (!this.#storage) throw new Error(\"ordered children require indexed storage\");\n+\t\tconst index = new OrderedIndex(this.#storage, \"ordered-children\", String(code));\n+\t\tif (this.#storage.read(\"ordered-children\", \"format\") !== 1)\n+\t\t\tthrow new Error(\"ordered children require fresh adoption\");\n+\t\tif (index.size !== this.#runStartPages!.length(String(code))) throw new Error(\"ordered child index count mismatch\");\n+\t\tconst cursor = after === undefined ? undefined : this.#childPriority(after);\n+\t\tlet implicit: number | undefined;\n+\t\tif (\n+\t\t\tcode >= 0 &&\n+\t\t\tcode + 1 < this.#lineTotal &&\n+\t\t\tthis.#lineAtom.at(code + 1) === this.#lineAtom.at(code) &&\n+\t\t\tthis.#lineParent.at(code + 1) === code\n+\t\t)\n+\t\t\timplicit = code + 1;\n+\t\tif (implicit !== undefined && cursor !== undefined && this.#childPriority(implicit) <= cursor) implicit = undefined;\n+\t\tfor (const n of index.values(cursor)) {\n+\t\t\tif (implicit !== undefined && this.#childPriority(implicit) < this.#childPriority(n)) {\n+\t\t\t\tyield implicit;\n+\t\t\t\timplicit = undefined;\n+\t\t\t}\n+\t\t\tyield n;\n+\t\t}\n+\t\tif (implicit !== undefined) yield implicit;\n+\t}\n+\n \treplacesN(n: number): boolean {\n \t\treturn this.#replacing.at(n) === 1;\n \t}\n@@ -904,6 +945,11 @@\n \t}\n \n \t#add(atom: Atom): void {\n+\t\tif (this.#storage && this.#storage.read(\"ordered-children\", \"format\") !== 1) {\n+\t\t\tif (this.#atoms.length !== 0) throw new Error(\"ordered children require fresh adoption\");\n+\t\t\tthis.#storage.write(\"ordered-children\", \"format\", 1);\n+\t\t}\n+\n \t\tvalidateShape(atom);\n \t\tconst seq = this.#atoms.length;\n \t\tconst bad = (why: string): never => {\n@@ -1001,6 +1047,18 @@\n \t\t\tconst file = this.#pathOf(run.file);\n \t\t\tlet parent = isStartNode(run.parent) ? -1 - file : this.#lineN(run.parent);\n \t\t\tconst first = this.#lineTotal;\n+\t\t\tif (this.#storage)\n+\t\t\t\tnew OrderedIndex(this.#storage, \"ordered-children\", String(parent)).insert(\n+\t\t\t\t\torderedChildKey({\n+\t\t\t\t\t\tn: first,\n+\t\t\t\t\t\treplaces: deletes?.has(run.parent) ? 1 : 0,\n+\t\t\t\t\t\tlamport: lam,\n+\t\t\t\t\t\tseq,\n+\t\t\t\t\t\tk: first - this.#lineBase[seq]!,\n+\t\t\t\t\t}),\n+\t\t\t\t\tfirst,\n+\t\t\t\t);\n+\n \t\t\tif (this.#runStartPages) this.#runStartPages.append(String(parent), first);\n \t\t\telse pushOne(this.#runStarts, parent, first);\n \t\t\tfor (let i = 0; i < run.lines.length; i++) {"}],"unmatched":[]}