{"file":"src/engine/view.ts","version":227,"total":1060,"from":1,"to":1060,"lines":[{"n":1,"text":"// Projection: the files a closed set of atoms produces. A pure function of the","atom":"a0","author":"init","version":0},{"n":2,"text":"// set. Each file is a tree of lines hanging off its start node; linearizing it","atom":"a0","author":"init","version":0},{"n":3,"text":"// depth-first, children in descending priority, gives the file's sequence. A","atom":"a0","author":"init","version":0},{"n":4,"text":"// line hangs off the node it was written after, unless a move in the set gave","atom":"a0","author":"init","version":0},{"n":5,"text":"// it another parent (#28): then the newest such move decides.","atom":"a0","author":"init","version":0},{"n":6,"text":"//","atom":"a0","author":"init","version":0},{"n":7,"text":"// A laid-out file is kept as arrays of line numbers (the graph's n), not as a","atom":"a0","author":"init","version":0},{"n":8,"text":"// record per line (#46): a record, its id and two index entries cost about","atom":"a0","author":"init","version":0},{"n":9,"text":"// 370 bytes a line, and the view cache holds up to 200,000 lines. Records are","atom":"a0","author":"init","version":0},{"n":10,"text":"// made when a caller asks for them, and the latest asked for is kept.","atom":"a0","author":"init","version":0},{"n":11,"text":"","atom":"a0","author":"init","version":0},{"n":12,"text":"import type { Graph, RelocationInfo } from \"./graph.ts\";","atom":"a0","author":"init","version":0},{"n":13,"text":"import { isStartNode, seqOf } from \"./keys.ts\";","atom":"a2350","author":"capacity","version":212},{"n":14,"text":"import { resolveScratchMoves, scratchLayoutNodes } from \"./relocation-scratch.ts\";","atom":"a1112","author":"codex-capacity-chair","version":132},{"n":15,"text":"import { isClosedSet, StableSet } from \"./state-source.ts\";","atom":"a2302","author":"capacity","version":205},{"n":16,"text":"import { joinLines } from \"./text.ts\";","atom":"a0","author":"init","version":0},{"n":17,"text":"import { type AtomId, type AtomSet, EngineError, type LineId, type NodeId } from \"./types.ts\";","atom":"a0","author":"init","version":0},{"n":18,"text":"","atom":"a0","author":"init","version":0},{"n":19,"text":"/** A line in a file's full sequence, tombstones included. */","atom":"a0","author":"init","version":0},{"n":20,"text":"export interface SeqLine {","atom":"a0","author":"init","version":0},{"n":21,"text":"\treadonly id: LineId;","atom":"a0","author":"init","version":0},{"n":22,"text":"\treadonly text: string;","atom":"a0","author":"init","version":0},{"n":23,"text":"\t/** The atom that wrote it. */","atom":"a0","author":"init","version":0},{"n":24,"text":"\treadonly atom: AtomId;","atom":"a0","author":"init","version":0},{"n":25,"text":"\t/** Atoms in the set that delete it, by seq. Empty when it is visible. */","atom":"a0","author":"init","version":0},{"n":26,"text":"\treadonly deletedBy: readonly AtomId[];","atom":"a0","author":"init","version":0},{"n":27,"text":"\treadonly visible: boolean;","atom":"a0","author":"init","version":0},{"n":28,"text":"}","atom":"a0","author":"init","version":0},{"n":29,"text":"","atom":"a0","author":"init","version":0},{"n":30,"text":"/** A visible line of a projected file. */","atom":"a0","author":"init","version":0},{"n":31,"text":"export interface VisibleLine {","atom":"a0","author":"init","version":0},{"n":32,"text":"\treadonly textChunks?: () => Iterable<string>;","atom":"a1890","author":"codex-capacity-chair","version":175},{"n":33,"text":"\treadonly id: LineId;","atom":"a0","author":"init","version":0},{"n":34,"text":"\treadonly text: string;","atom":"a0","author":"init","version":0},{"n":35,"text":"\treadonly atom: AtomId;","atom":"a0","author":"init","version":0},{"n":36,"text":"}","atom":"a0","author":"init","version":0},{"n":37,"text":"","atom":"a0","author":"init","version":0},{"n":38,"text":"/** A file's attributes in a view. */","atom":"a0","author":"init","version":0},{"n":39,"text":"export interface FileAttrs {","atom":"a0","author":"init","version":0},{"n":40,"text":"\t/** Kept with no lines (an empty file). */","atom":"a0","author":"init","version":0},{"n":41,"text":"\treadonly exists: boolean;","atom":"a0","author":"init","version":0},{"n":42,"text":"\treadonly exec: boolean;","atom":"a0","author":"init","version":0},{"n":43,"text":"\t/** The target, when the file is a symbolic link. */","atom":"a0","author":"init","version":0},{"n":44,"text":"\treadonly link: string | null;","atom":"a0","author":"init","version":0},{"n":45,"text":"\t/** The SHA-256 of its bytes, when the file is binary. */","atom":"a0","author":"init","version":0},{"n":46,"text":"\treadonly blob: string | null;","atom":"a0","author":"init","version":0},{"n":47,"text":"}","atom":"a0","author":"init","version":0},{"n":48,"text":"","atom":"a0","author":"init","version":0},{"n":49,"text":"/** Structural read boundary shared by historical and transaction-bound projections. */","atom":"a1327","author":"codex-capacity-chair","version":143},{"n":50,"text":"export type ReadView = Omit<","atom":"a2350","author":"capacity","version":212},{"n":51,"text":"\tPick<View, keyof View>,","atom":"a2350","author":"capacity","version":212},{"n":52,"text":"\t\"sameText\" | \"visibleCount\" | \"shareMoves\" | \"fileOfNumber\" | \"lineNumberOf\" | \"visibleWriters\"","atom":"a2350","author":"capacity","version":212},{"n":53,"text":"> & {","atom":"a2350","author":"capacity","version":212},{"n":54,"text":"\tsameText(path: string, other: ReadView): boolean;","atom":"a1327","author":"codex-capacity-chair","version":143},{"n":55,"text":"};","atom":"a1327","author":"codex-capacity-chair","version":143},{"n":56,"text":"","atom":"a1327","author":"codex-capacity-chair","version":143},{"n":57,"text":"const NO_ATTRS: FileAttrs = { exists: false, exec: false, link: null, blob: null };","atom":"a0","author":"init","version":0},{"n":58,"text":"const NONE: readonly never[] = Object.freeze([]);","atom":"a0","author":"init","version":0},{"n":59,"text":"","atom":"a0","author":"init","version":0},{"n":60,"text":"interface FileState {","atom":"a0","author":"init","version":0},{"n":61,"text":"\treadonly attrs: FileAttrs;","atom":"a0","author":"init","version":0},{"n":62,"text":"\t/** Full history is retained only when a sequence caller explicitly requests it. */","atom":"a1006","author":"codex-capacity-chair","version":110},{"n":63,"text":"\treadonly complete: boolean;","atom":"a1006","author":"codex-capacity-chair","version":110},{"n":64,"text":"\t/** The file's sequence, tombstones included: each line's n. */","atom":"a0","author":"init","version":0},{"n":65,"text":"\treadonly seq: Int32Array;","atom":"a0","author":"init","version":0},{"n":66,"text":"\t/** Its visible lines' n, in order. */","atom":"a0","author":"init","version":0},{"n":67,"text":"\treadonly vis: Int32Array;","atom":"a0","author":"init","version":0},{"n":68,"text":"\t/** For each deleted position in seq: the seqs of the atoms in the set that delete it, by priority. */","atom":"a0","author":"init","version":0},{"n":69,"text":"\treadonly deletedBy: ReadonlyMap<number, readonly number[]>;","atom":"a0","author":"init","version":0},{"n":70,"text":"\t/** Its visible lines' text, when laid out from the file's packed history: null for a line too long to pack. */","atom":"a2312","author":"capacity","version":206},{"n":71,"text":"\treadonly visText?: readonly (string | null)[];","atom":"a2312","author":"capacity","version":206},{"n":72,"text":"\t/** Positions by n, built the first time they're asked for. */","atom":"a0","author":"init","version":0},{"n":73,"text":"\tseqIndex?: Map<number, number>;","atom":"a0","author":"init","version":0},{"n":74,"text":"\tvisIndex?: Map<number, number>;","atom":"a0","author":"init","version":0},{"n":75,"text":"}","atom":"a0","author":"init","version":0},{"n":76,"text":"","atom":"a0","author":"init","version":0},{"n":77,"text":"interface Child {","atom":"a0","author":"init","version":0},{"n":78,"text":"\treadonly n: number;","atom":"a0","author":"init","version":0},{"n":79,"text":"\t/** 1 when the child's atom deleted the parent (the child replaces it), else 0. A moved line is 0. */","atom":"a0","author":"init","version":0},{"n":80,"text":"\treadonly replaces: number;","atom":"a0","author":"init","version":0},{"n":81,"text":"\treadonly lamport: number;","atom":"a0","author":"init","version":0},{"n":82,"text":"\treadonly seq: number;","atom":"a0","author":"init","version":0},{"n":83,"text":"\treadonly k: number;","atom":"a0","author":"init","version":0},{"n":84,"text":"}","atom":"a0","author":"init","version":0},{"n":85,"text":"","atom":"a0","author":"init","version":0},{"n":86,"text":"const EMPTY_INTS = new Int32Array(0);","atom":"a0","author":"init","version":0},{"n":87,"text":"const NO_FILE: FileState = { attrs: NO_ATTRS, complete: true, seq: EMPTY_INTS, vis: EMPTY_INTS, deletedBy: new Map() };","atom":"a1006","author":"codex-capacity-chair","version":110},{"n":88,"text":"","atom":"a0","author":"init","version":0},{"n":89,"text":"// Approximate retained-container costs for View.weight(): reference slots,","atom":"a934","author":"codex-capacity-policy","version":103},{"n":90,"text":"// object headers, and map/set entries. These are cache-budget units, not V8","atom":"a934","author":"codex-capacity-policy","version":103},{"n":91,"text":"// heap measurements. Referenced Graph strings and records are not charged.","atom":"a934","author":"codex-capacity-policy","version":103},{"n":92,"text":"const ARRAY_HEADER_BYTES = 24;","atom":"a934","author":"codex-capacity-policy","version":103},{"n":93,"text":"const OBJECT_BYTES = 32;","atom":"a934","author":"codex-capacity-policy","version":103},{"n":94,"text":"const MAP_HEADER_BYTES = 32;","atom":"a934","author":"codex-capacity-policy","version":103},{"n":95,"text":"const MAP_ENTRY_BYTES = 40;","atom":"a934","author":"codex-capacity-policy","version":103},{"n":96,"text":"const SET_ENTRY_BYTES = 32;","atom":"a934","author":"codex-capacity-policy","version":103},{"n":97,"text":"const REFERENCE_BYTES = 8;","atom":"a934","author":"codex-capacity-policy","version":103},{"n":98,"text":"/**","atom":"a2302","author":"capacity","version":205},{"n":99,"text":" * Moved lines a view resolves once and keeps (abso Capacity): a stored graph otherwise resolved every move again on","atom":"a2302","author":"capacity","version":205},{"n":100,"text":" * disk for each file it laid out. Game's whole history has 290; past this many, the view goes back to that.","atom":"a2302","author":"capacity","version":205},{"n":101,"text":" */","atom":"a2302","author":"capacity","version":205},{"n":102,"text":"export const MOVED_LINES_KEPT = 20_000;","atom":"a2302","author":"capacity","version":205},{"n":103,"text":"class TooManyMoves extends Error {}","atom":"a2302","author":"capacity","version":205},{"n":104,"text":"const NO_LINES: readonly number[] = Object.freeze([]);","atom":"a2302","author":"capacity","version":205},{"n":105,"text":"/** Nodes whose nearest moved line above a graph remembers, at most: about 40 bytes each. */","atom":"a2368","author":"capacity","version":215},{"n":106,"text":"const CLIMB_MEMO = 200_000;","atom":"a2368","author":"capacity","version":215},{"n":107,"text":"","atom":"a934","author":"codex-capacity-policy","version":103},{"n":108,"text":"/** One relocation of a moved line, with its line's number and its new parent's code. */","atom":"a2368","author":"capacity","version":215},{"n":109,"text":"interface MoveEntry {","atom":"a2368","author":"capacity","version":215},{"n":110,"text":"\treadonly n: number;","atom":"a2368","author":"capacity","version":215},{"n":111,"text":"\treadonly r: RelocationInfo;","atom":"a2368","author":"capacity","version":215},{"n":112,"text":"\treadonly parent: number;","atom":"a2368","author":"capacity","version":215},{"n":113,"text":"}","atom":"a2368","author":"capacity","version":215},{"n":114,"text":"","atom":"a2368","author":"capacity","version":215},{"n":115,"text":"/**","atom":"a0","author":"init","version":0},{"n":116,"text":" * A graph's moves, whatever the set (abso Capacity): each mover's moved lines, each moved line's relocations in seq","atom":"a2368","author":"capacity","version":215},{"n":117,"text":" * order, and for any node the nearest node at or above it, by where lines were written, that a move ever relocated,","atom":"a2368","author":"capacity","version":215},{"n":118,"text":" * or its file's start. Worked out once per graph and extended as it grows. A view's moves then resolve over the moved","atom":"a2368","author":"capacity","version":215},{"n":119,"text":" * lines alone: before, every view walked each moved line's file up to its start, a read per line.","atom":"a2368","author":"capacity","version":215},{"n":120,"text":" */","atom":"a2368","author":"capacity","version":215},{"n":121,"text":"class MoveSkeleton {","atom":"a2368","author":"capacity","version":215},{"n":122,"text":"\treadonly #graph: Graph;","atom":"a2368","author":"capacity","version":215},{"n":123,"text":"\t#seen = 0;","atom":"a2368","author":"capacity","version":215},{"n":124,"text":"\t/** Movers in seq order, with the numbers of the lines each moves, in its moves' order. */","atom":"a2368","author":"capacity","version":215},{"n":125,"text":"\treadonly movers: { readonly seq: number; readonly lines: readonly number[] }[] = [];","atom":"a2368","author":"capacity","version":215},{"n":126,"text":"\t/** Every relocation of each moved line, by the line's number, in seq order. */","atom":"a2368","author":"capacity","version":215},{"n":127,"text":"\treadonly byLine = new Map<number, MoveEntry[]>();","atom":"a2368","author":"capacity","version":215},{"n":128,"text":"\treadonly #climbed = new Map<number, number>();","atom":"a2368","author":"capacity","version":215},{"n":129,"text":"","atom":"a2368","author":"capacity","version":215},{"n":130,"text":"\tconstructor(graph: Graph) {","atom":"a2368","author":"capacity","version":215},{"n":131,"text":"\t\tthis.#graph = graph;","atom":"a2368","author":"capacity","version":215},{"n":132,"text":"\t}","atom":"a2368","author":"capacity","version":215},{"n":133,"text":"","atom":"a2368","author":"capacity","version":215},{"n":134,"text":"\t/** Take in movers the graph gained since. */","atom":"a2368","author":"capacity","version":215},{"n":135,"text":"\tupdate(): this {","atom":"a2368","author":"capacity","version":215},{"n":136,"text":"\t\tconst graph = this.#graph;","atom":"a2368","author":"capacity","version":215},{"n":137,"text":"\t\tconst all = graph.movers();","atom":"a2368","author":"capacity","version":215},{"n":138,"text":"\t\tif (this.#seen === all.length) return this;","atom":"a2368","author":"capacity","version":215},{"n":139,"text":"\t\tfor (; this.#seen < all.length; this.#seen++) {","atom":"a2368","author":"capacity","version":215},{"n":140,"text":"\t\t\tconst id = all[this.#seen]!;","atom":"a2368","author":"capacity","version":215},{"n":141,"text":"\t\t\tconst lines: number[] = [];","atom":"a2368","author":"capacity","version":215},{"n":142,"text":"\t\t\tgraph.atom(id).moves!.forEach((m, k) => {","atom":"a2368","author":"capacity","version":215},{"n":143,"text":"\t\t\t\tconst n = graph.lineN(m.line);","atom":"a2368","author":"capacity","version":215},{"n":144,"text":"\t\t\t\tconst r: RelocationInfo = Object.freeze({ atom: id, line: m.line, parent: m.parent, k });","atom":"a2368","author":"capacity","version":215},{"n":145,"text":"\t\t\t\tconst entry: MoveEntry = { n, r, parent: graph.codeOf(m.parent)! };","atom":"a2368","author":"capacity","version":215},{"n":146,"text":"\t\t\t\tconst list = this.byLine.get(n);","atom":"a2368","author":"capacity","version":215},{"n":147,"text":"\t\t\t\tif (list) list.push(entry);","atom":"a2368","author":"capacity","version":215},{"n":148,"text":"\t\t\t\telse this.byLine.set(n, [entry]);","atom":"a2368","author":"capacity","version":215},{"n":149,"text":"\t\t\t\tlines.push(n);","atom":"a2368","author":"capacity","version":215},{"n":150,"text":"\t\t\t});","atom":"a2368","author":"capacity","version":215},{"n":151,"text":"\t\t\tthis.movers.push({ seq: seqOf(id), lines });","atom":"a2368","author":"capacity","version":215},{"n":152,"text":"\t\t}","atom":"a2368","author":"capacity","version":215},{"n":153,"text":"\t\t// A new moved line can sit between a node and the one it climbed to.","atom":"a2368","author":"capacity","version":215},{"n":154,"text":"\t\tthis.#climbed.clear();","atom":"a2368","author":"capacity","version":215},{"n":155,"text":"\t\treturn this;","atom":"a2368","author":"capacity","version":215},{"n":156,"text":"\t}","atom":"a2368","author":"capacity","version":215},{"n":157,"text":"","atom":"a2368","author":"capacity","version":215},{"n":158,"text":"\t/** The nearest node at or above this one, by where lines were written, that a move ever relocated; or its file's start. */","atom":"a2368","author":"capacity","version":215},{"n":159,"text":"\tclimb(code: number): number {","atom":"a2368","author":"capacity","version":215},{"n":160,"text":"\t\tconst walked: number[] = [];","atom":"a2368","author":"capacity","version":215},{"n":161,"text":"\t\tlet c = code;","atom":"a2368","author":"capacity","version":215},{"n":162,"text":"\t\twhile (c >= 0 && !this.byLine.has(c)) {","atom":"a2368","author":"capacity","version":215},{"n":163,"text":"\t\t\tconst known = this.#climbed.get(c);","atom":"a2368","author":"capacity","version":215},{"n":164,"text":"\t\t\tif (known !== undefined) {","atom":"a2368","author":"capacity","version":215},{"n":165,"text":"\t\t\t\tc = known;","atom":"a2368","author":"capacity","version":215},{"n":166,"text":"\t\t\t\tbreak;","atom":"a2368","author":"capacity","version":215},{"n":167,"text":"\t\t\t}","atom":"a2368","author":"capacity","version":215},{"n":168,"text":"\t\t\twalked.push(c);","atom":"a2368","author":"capacity","version":215},{"n":169,"text":"\t\t\tc = this.#graph.parentCodeOf(c);","atom":"a2368","author":"capacity","version":215},{"n":170,"text":"\t\t}","atom":"a2368","author":"capacity","version":215},{"n":171,"text":"\t\tif (this.#climbed.size + walked.length > CLIMB_MEMO) this.#climbed.clear();","atom":"a2368","author":"capacity","version":215},{"n":172,"text":"\t\tfor (const w of walked) this.#climbed.set(w, c);","atom":"a2368","author":"capacity","version":215},{"n":173,"text":"\t\treturn c;","atom":"a2368","author":"capacity","version":215},{"n":174,"text":"\t}","atom":"a2368","author":"capacity","version":215},{"n":175,"text":"}","atom":"a2368","author":"capacity","version":215},{"n":176,"text":"","atom":"a2368","author":"capacity","version":215},{"n":177,"text":"const skeletons = new WeakMap<Graph, MoveSkeleton>();","atom":"a2368","author":"capacity","version":215},{"n":178,"text":"function skeletonOf(graph: Graph): MoveSkeleton {","atom":"a2368","author":"capacity","version":215},{"n":179,"text":"\tlet skeleton = skeletons.get(graph);","atom":"a2368","author":"capacity","version":215},{"n":180,"text":"\tif (!skeleton) skeletons.set(graph, (skeleton = new MoveSkeleton(graph)));","atom":"a2368","author":"capacity","version":215},{"n":181,"text":"\treturn skeleton.update();","atom":"a2368","author":"capacity","version":215},{"n":182,"text":"}","atom":"a2368","author":"capacity","version":215},{"n":183,"text":"","atom":"a2368","author":"capacity","version":215},{"n":184,"text":"/**","atom":"a2368","author":"capacity","version":215},{"n":185,"text":" * The projection of a closed set. Construct once, then ask for files, lines","atom":"a0","author":"init","version":0},{"n":186,"text":" * and sequences. Throws `not-closed` if some atom's dependency is missing.","atom":"a0","author":"init","version":0},{"n":187,"text":" * Each file is laid out the first time it is asked for, so a view of a large","atom":"a0","author":"init","version":0},{"n":188,"text":" * set costs little until files are read.","atom":"a0","author":"init","version":0},{"n":189,"text":" */","atom":"a0","author":"init","version":0},{"n":190,"text":"export class View {","atom":"a0","author":"init","version":0},{"n":191,"text":"\treadonly graph: Graph;","atom":"a0","author":"init","version":0},{"n":192,"text":"\t/** The set, made from #in the first time it's asked for: a view keeps a byte per atom, not a copy of the set (#46). */","atom":"a0","author":"init","version":0},{"n":193,"text":"\t#set: AtomSet | undefined;","atom":"a998","author":"codex-capacity-chair","version":109},{"n":194,"text":"\treadonly #stable: StableSet<AtomId> | undefined;","atom":"a998","author":"codex-capacity-chair","version":109},{"n":195,"text":"\t/** Fixed-size memo for immutable indexed membership, independent of history size. */","atom":"a1030","author":"codex-capacity-chair","version":116},{"n":196,"text":"\t#membershipSeq = new Float64Array(256).fill(-1);","atom":"a1030","author":"codex-capacity-chair","version":116},{"n":197,"text":"\t#membershipValue = new Uint8Array(256);","atom":"a1030","author":"codex-capacity-chair","version":116},{"n":198,"text":"\t#files = new Map<string, FileState>();","atom":"a0","author":"init","version":0},{"n":199,"text":"\t/** Every file the set wrote in, sorted; worked out the first time it's asked for. */","atom":"a0","author":"init","version":0},{"n":200,"text":"\t#knownList: string[] | undefined;","atom":"a0","author":"init","version":0},{"n":201,"text":"\t/** 1 for each atom (by seq) in the set. */","atom":"a0","author":"init","version":0},{"n":202,"text":"\t#in: Uint8Array;","atom":"a0","author":"init","version":0},{"n":203,"text":"\t/** Atoms in the set that move lines. */","atom":"a0","author":"init","version":0},{"n":204,"text":"\t#movers: AtomId[] | undefined;","atom":"a1061","author":"codex-capacity-chair","version":123},{"n":205,"text":"\t#hasMoves = false;","atom":"a1061","author":"codex-capacity-chair","version":123},{"n":206,"text":"\t/** Each moved line's relocation that counts in this set; built on first use. */","atom":"a0","author":"init","version":0},{"n":207,"text":"\t#relocs: Map<LineId, RelocationInfo> | undefined;","atom":"a0","author":"init","version":0},{"n":208,"text":"\t/** The same, by n, with the new parent's code. */","atom":"a0","author":"init","version":0},{"n":209,"text":"\t#relocsN: Map<number, { readonly r: RelocationInfo; readonly parent: number }> | undefined;","atom":"a0","author":"init","version":0},{"n":210,"text":"\t/** The moved lines under each node, by its code, made from the relocations on first use. */","atom":"a2302","author":"capacity","version":205},{"n":211,"text":"\t#movedInto: Map<number, number[]> | undefined;","atom":"a2302","author":"capacity","version":205},{"n":212,"text":"\t/** Whether this view's moves are too many to keep, so they're resolved on disk per layout; undefined until asked. */","atom":"a2302","author":"capacity","version":205},{"n":213,"text":"\t#movesOnDisk: boolean | undefined;","atom":"a2302","author":"capacity","version":205},{"n":214,"text":"\t/** The latest records asked for: one file's lines, one file's sequence, one file's text. */","atom":"a0","author":"init","version":0},{"n":215,"text":"\t#linesCache: { path: string; lines: readonly VisibleLine[] } | undefined;","atom":"a0","author":"init","version":0},{"n":216,"text":"\t#seqCache: { path: string; seq: readonly SeqLine[] } | undefined;","atom":"a0","author":"init","version":0},{"n":217,"text":"\t#textCache: { path: string; text: string } | undefined;","atom":"a0","author":"init","version":0},{"n":218,"text":"","atom":"a0","author":"init","version":0},{"n":219,"text":"\tconstructor(graph: Graph, set: Iterable<AtomId>) {","atom":"a0","author":"init","version":0},{"n":220,"text":"\t\tthis.graph = graph;","atom":"a998","author":"codex-capacity-chair","version":109},{"n":221,"text":"\t\tif (set instanceof StableSet) {","atom":"a998","author":"codex-capacity-chair","version":109},{"n":222,"text":"\t\t\tthis.#stable = set;","atom":"a998","author":"codex-capacity-chair","version":109},{"n":223,"text":"\t\t\tthis.#set = set;","atom":"a998","author":"codex-capacity-chair","version":109},{"n":224,"text":"\t\t\tthis.#in = new Uint8Array(0);","atom":"a998","author":"codex-capacity-chair","version":109},{"n":225,"text":"\t\t\t// A set kept closed when it was written needs no proof here (abso Capacity).","atom":"a2302","author":"capacity","version":205},{"n":226,"text":"\t\t\tfor (const id of isClosedSet(set) ? [] : set) {","atom":"a2302","author":"capacity","version":205},{"n":227,"text":"\t\t\t\tconst atom = graph.atom(id);","atom":"a998","author":"codex-capacity-chair","version":109},{"n":228,"text":"\t\t\t\tfor (const dependency of atom.deps) {","atom":"a998","author":"codex-capacity-chair","version":109},{"n":229,"text":"\t\t\t\t\tgraph.atom(dependency);","atom":"a998","author":"codex-capacity-chair","version":109},{"n":230,"text":"\t\t\t\t\tif (!set.has(dependency))","atom":"a998","author":"codex-capacity-chair","version":109},{"n":231,"text":"\t\t\t\t\t\tthrow new EngineError(\"not-closed\", `set is not closed: ${id} depends on ${dependency}`);","atom":"a998","author":"codex-capacity-chair","version":109},{"n":232,"text":"\t\t\t\t}","atom":"a998","author":"codex-capacity-chair","version":109},{"n":233,"text":"\t\t\t}","atom":"a998","author":"codex-capacity-chair","version":109},{"n":234,"text":"\t\t\tfor (const id of graph.movers()) {","atom":"a1061","author":"codex-capacity-chair","version":123},{"n":235,"text":"\t\t\t\tif (set.has(id)) {","atom":"a1061","author":"codex-capacity-chair","version":123},{"n":236,"text":"\t\t\t\t\tthis.#hasMoves = true;","atom":"a1061","author":"codex-capacity-chair","version":123},{"n":237,"text":"\t\t\t\t\tbreak;","atom":"a1061","author":"codex-capacity-chair","version":123},{"n":238,"text":"\t\t\t\t}","atom":"a1061","author":"codex-capacity-chair","version":123},{"n":239,"text":"\t\t\t}","atom":"a1061","author":"codex-capacity-chair","version":123},{"n":240,"text":"\t\t\tthis.#relocs = this.#hasMoves ? undefined : new Map();","atom":"a1061","author":"codex-capacity-chair","version":123},{"n":241,"text":"\t\t\tthis.#relocsN = this.#hasMoves ? undefined : new Map();","atom":"a1061","author":"codex-capacity-chair","version":123},{"n":242,"text":"\t\t\treturn;","atom":"a998","author":"codex-capacity-chair","version":109},{"n":243,"text":"\t\t}","atom":"a998","author":"codex-capacity-chair","version":109},{"n":244,"text":"\t\tconst inSet = new Uint8Array(graph.size);","atom":"a0","author":"init","version":0},{"n":245,"text":"\t\t// An atom's number is in its id (abso Capacity): reading the atom for it read the whole history on a stored graph.","atom":"a2383","author":"capacity","version":218},{"n":246,"text":"\t\tconst seqIn = (id: AtomId): number => {","atom":"a2383","author":"capacity","version":218},{"n":247,"text":"\t\t\tconst seq = seqOf(id);","atom":"a2383","author":"capacity","version":218},{"n":248,"text":"\t\t\treturn seq >= 0 && seq < inSet.length && graph.idOfSeq(seq) === id ? seq : graph.atom(id).seq;","atom":"a2383","author":"capacity","version":218},{"n":249,"text":"\t\t};","atom":"a2383","author":"capacity","version":218},{"n":250,"text":"\t\tfor (const id of set) inSet[seqIn(id)] = 1;","atom":"a2383","author":"capacity","version":218},{"n":251,"text":"\t\t// Validate one atom at a time. Keeping all decoded atoms here defeats","atom":"a979","author":"codex-capacity-chair","version":109},{"n":252,"text":"\t\t// storage-backed Graph reads even though the view only needs membership.","atom":"a979","author":"codex-capacity-chair","version":109},{"n":253,"text":"\t\tfor (let seq = 0; seq < inSet.length; seq++) {","atom":"a979","author":"codex-capacity-chair","version":109},{"n":254,"text":"\t\t\tif (inSet[seq] !== 1) continue;","atom":"a979","author":"codex-capacity-chair","version":109},{"n":255,"text":"\t\t\tconst atom = graph.atom(graph.idOfSeq(seq));","atom":"a979","author":"codex-capacity-chair","version":109},{"n":256,"text":"\t\t\tfor (const d of atom.deps) {","atom":"a0","author":"init","version":0},{"n":257,"text":"\t\t\t\tif (inSet[seqIn(d)] !== 1) throw new EngineError(\"not-closed\", `set is not closed: ${atom.id} depends on ${d}`);","atom":"a2383","author":"capacity","version":218},{"n":258,"text":"\t\t\t}","atom":"a0","author":"init","version":0},{"n":259,"text":"\t\t}","atom":"a0","author":"init","version":0},{"n":260,"text":"\t\tthis.graph = graph;","atom":"a0","author":"init","version":0},{"n":261,"text":"\t\tthis.#in = inSet;","atom":"a0","author":"init","version":0},{"n":262,"text":"\t\tthis.#movers = graph.movers().filter((id) => inSet[seqOf(id)] === 1);","atom":"a2383","author":"capacity","version":218},{"n":263,"text":"\t\tthis.#hasMoves = this.#movers.length > 0;","atom":"a1061","author":"codex-capacity-chair","version":123},{"n":264,"text":"\t\tthis.#relocs = this.#movers.length === 0 ? new Map() : undefined;","atom":"a0","author":"init","version":0},{"n":265,"text":"\t\tthis.#relocsN = this.#movers.length === 0 ? new Map() : undefined;","atom":"a0","author":"init","version":0},{"n":266,"text":"\t}","atom":"a0","author":"init","version":0},{"n":267,"text":"","atom":"a0","author":"init","version":0},{"n":268,"text":"\t/** The set of atoms this view projects. */","atom":"a0","author":"init","version":0},{"n":269,"text":"\tget set(): AtomSet {","atom":"a0","author":"init","version":0},{"n":270,"text":"\t\tif (!this.#set) {","atom":"a0","author":"init","version":0},{"n":271,"text":"\t\t\tconst out = new Set<AtomId>();","atom":"a0","author":"init","version":0},{"n":272,"text":"\t\t\tfor (let seq = 0; seq < this.#in.length; seq++) if (this.#in[seq] === 1) out.add(this.graph.idOfSeq(seq));","atom":"a0","author":"init","version":0},{"n":273,"text":"\t\t\tthis.#set = out;","atom":"a0","author":"init","version":0},{"n":274,"text":"\t\t}","atom":"a0","author":"init","version":0},{"n":275,"text":"\t\treturn this.#set;","atom":"a0","author":"init","version":0},{"n":276,"text":"\t}","atom":"a0","author":"init","version":0},{"n":277,"text":"","atom":"a0","author":"init","version":0},{"n":278,"text":"\t/** Whether the atom with this seq is in the set. */","atom":"a0","author":"init","version":0},{"n":279,"text":"\t#has(seq: number): boolean {","atom":"a0","author":"init","version":0},{"n":280,"text":"\t\tif (this.#stable) {","atom":"a1030","author":"codex-capacity-chair","version":116},{"n":281,"text":"\t\t\tconst slot = seq % this.#membershipSeq.length;","atom":"a1030","author":"codex-capacity-chair","version":116},{"n":282,"text":"\t\t\tif (this.#membershipSeq[slot] === seq) return this.#membershipValue[slot] === 1;","atom":"a1030","author":"codex-capacity-chair","version":116},{"n":283,"text":"\t\t\tconst present = this.#stable.has(this.graph.idOfSeq(seq));","atom":"a1030","author":"codex-capacity-chair","version":116},{"n":284,"text":"\t\t\tthis.#membershipSeq[slot] = seq;","atom":"a1030","author":"codex-capacity-chair","version":116},{"n":285,"text":"\t\t\tthis.#membershipValue[slot] = present ? 1 : 0;","atom":"a1030","author":"codex-capacity-chair","version":116},{"n":286,"text":"\t\t\treturn present;","atom":"a1030","author":"codex-capacity-chair","version":116},{"n":287,"text":"\t\t}","atom":"a1030","author":"codex-capacity-chair","version":116},{"n":288,"text":"\t\treturn seq < this.#in.length && this.#in[seq] === 1;","atom":"a0","author":"init","version":0},{"n":289,"text":"\t}","atom":"a0","author":"init","version":0},{"n":290,"text":"","atom":"a0","author":"init","version":0},{"n":291,"text":"\t/**","atom":"a0","author":"init","version":0},{"n":292,"text":"\t * The relocation that counts for each moved line: the newest (by priority)","atom":"a0","author":"init","version":0},{"n":293,"text":"\t * in the set. Two moves made apart can loop lines into each other, so no","atom":"a0","author":"init","version":0},{"n":294,"text":"\t * start node reaches them; then the oldest relocation on the loop is","atom":"a0","author":"init","version":0},{"n":295,"text":"\t * ignored, and the next newest of that line counts, until none loop.","atom":"a0","author":"init","version":0},{"n":296,"text":"\t */","atom":"a0","author":"init","version":0},{"n":297,"text":"\t#relocations(): Map<LineId, RelocationInfo> {","atom":"a0","author":"init","version":0},{"n":298,"text":"\t\tif (this.#relocs) return this.#relocs;","atom":"a0","author":"init","version":0},{"n":299,"text":"\t\tthis.#takeShared();","atom":"a2377","author":"capacity","version":216},{"n":300,"text":"\t\tif (this.#relocs) return this.#relocs;","atom":"a2377","author":"capacity","version":216},{"n":301,"text":"\t\tconst graph = this.graph;","atom":"a0","author":"init","version":0},{"n":302,"text":"\t\tconst skeleton = skeletonOf(graph);","atom":"a2368","author":"capacity","version":215},{"n":303,"text":"\t\tconst stronger = (a: RelocationInfo, b: RelocationInfo): boolean => graph.comparePriority(a.atom, b.atom) > 0;","atom":"a0","author":"init","version":0},{"n":304,"text":"\t\tconst identity = (r: RelocationInfo): string => JSON.stringify([r.atom, r.k]);","atom":"a1075","author":"codex-capacity-chair","version":126},{"n":305,"text":"\t\tconst ignored = new Set<string>();","atom":"a1075","author":"codex-capacity-chair","version":126},{"n":306,"text":"\t\tconst pick = (n: number): MoveEntry | undefined => {","atom":"a2368","author":"capacity","version":215},{"n":307,"text":"\t\t\tlet best: MoveEntry | undefined;","atom":"a2368","author":"capacity","version":215},{"n":308,"text":"\t\t\tfor (const e of skeleton.byLine.get(n) ?? []) {","atom":"a2368","author":"capacity","version":215},{"n":309,"text":"\t\t\t\tif (this.#has(seqOf(e.r.atom)) && !ignored.has(identity(e.r)) && (!best || stronger(e.r, best.r))) best = e;","atom":"a2368","author":"capacity","version":215},{"n":310,"text":"\t\t\t}","atom":"a0","author":"init","version":0},{"n":311,"text":"\t\t\treturn best;","atom":"a0","author":"init","version":0},{"n":312,"text":"\t\t};","atom":"a0","author":"init","version":0},{"n":313,"text":"\t\t// By the moved line's number, in the order its movers come (seq order, then each mover's moves).","atom":"a2368","author":"capacity","version":215},{"n":314,"text":"\t\tconst relocs = new Map<number, MoveEntry>();","atom":"a2368","author":"capacity","version":215},{"n":315,"text":"\t\tfor (const mover of skeleton.movers) {","atom":"a2368","author":"capacity","version":215},{"n":316,"text":"\t\t\tif (!this.#has(mover.seq)) continue;","atom":"a2368","author":"capacity","version":215},{"n":317,"text":"\t\t\tfor (const n of mover.lines) {","atom":"a2368","author":"capacity","version":215},{"n":318,"text":"\t\t\t\tif (!relocs.has(n)) relocs.set(n, pick(n)!);","atom":"a2368","author":"capacity","version":215},{"n":319,"text":"\t\t\t\tif (graph.hasOrderedChildren && relocs.size > MOVED_LINES_KEPT) throw new TooManyMoves();","atom":"a2302","author":"capacity","version":205},{"n":320,"text":"\t\t\t}","atom":"a0","author":"init","version":0},{"n":321,"text":"\t\t}","atom":"a0","author":"init","version":0},{"n":322,"text":"\t\t// From a node, the next node that matters for loops: a line moved in this set, or a file's start.","atom":"a2368","author":"capacity","version":215},{"n":323,"text":"\t\tconst hop = (code: number): number => {","atom":"a2368","author":"capacity","version":215},{"n":324,"text":"\t\t\tlet c = skeleton.climb(code);","atom":"a2368","author":"capacity","version":215},{"n":325,"text":"\t\t\twhile (c >= 0 && !relocs.has(c)) c = skeleton.climb(graph.parentCodeOf(c));","atom":"a2368","author":"capacity","version":215},{"n":326,"text":"\t\t\treturn c;","atom":"a2368","author":"capacity","version":215},{"n":327,"text":"\t\t};","atom":"a2368","author":"capacity","version":215},{"n":328,"text":"\t\tconst step = (n: number): number => {","atom":"a2368","author":"capacity","version":215},{"n":329,"text":"\t\t\tconst e = relocs.get(n);","atom":"a2368","author":"capacity","version":215},{"n":330,"text":"\t\t\treturn hop(e ? e.parent : graph.parentCodeOf(n));","atom":"a2368","author":"capacity","version":215},{"n":331,"text":"\t\t};","atom":"a2368","author":"capacity","version":215},{"n":332,"text":"\t\t// Two moves made apart can loop lines into each other, so no start node reaches them; then the oldest","atom":"a2368","author":"capacity","version":215},{"n":333,"text":"\t\t// relocation on the loop is ignored, and the next newest of that line counts, until none loop.","atom":"a2368","author":"capacity","version":215},{"n":334,"text":"\t\tconst reaches = new Set<number>();","atom":"a2368","author":"capacity","version":215},{"n":335,"text":"\t\tfor (const line of [...relocs.keys()]) {","atom":"a0","author":"init","version":0},{"n":336,"text":"\t\t\tfor (;;) {","atom":"a0","author":"init","version":0},{"n":337,"text":"\t\t\t\tconst path: number[] = [];","atom":"a2368","author":"capacity","version":215},{"n":338,"text":"\t\t\t\tconst onPath = new Map<number, number>();","atom":"a2368","author":"capacity","version":215},{"n":339,"text":"\t\t\t\tlet cur = line;","atom":"a2368","author":"capacity","version":215},{"n":340,"text":"\t\t\t\tlet loopAt = -1;","atom":"a0","author":"init","version":0},{"n":341,"text":"\t\t\t\twhile (cur >= 0 && !reaches.has(cur)) {","atom":"a2368","author":"capacity","version":215},{"n":342,"text":"\t\t\t\t\tconst at = onPath.get(cur);","atom":"a0","author":"init","version":0},{"n":343,"text":"\t\t\t\t\tif (at !== undefined) {","atom":"a0","author":"init","version":0},{"n":344,"text":"\t\t\t\t\t\tloopAt = at;","atom":"a0","author":"init","version":0},{"n":345,"text":"\t\t\t\t\t\tbreak;","atom":"a0","author":"init","version":0},{"n":346,"text":"\t\t\t\t\t}","atom":"a0","author":"init","version":0},{"n":347,"text":"\t\t\t\t\tonPath.set(cur, path.length);","atom":"a0","author":"init","version":0},{"n":348,"text":"\t\t\t\t\tpath.push(cur);","atom":"a0","author":"init","version":0},{"n":349,"text":"\t\t\t\t\tcur = step(cur);","atom":"a2368","author":"capacity","version":215},{"n":350,"text":"\t\t\t\t}","atom":"a0","author":"init","version":0},{"n":351,"text":"\t\t\t\tif (loopAt < 0) {","atom":"a0","author":"init","version":0},{"n":352,"text":"\t\t\t\t\tfor (const l of path) reaches.add(l);","atom":"a0","author":"init","version":0},{"n":353,"text":"\t\t\t\t\tbreak;","atom":"a0","author":"init","version":0},{"n":354,"text":"\t\t\t\t}","atom":"a0","author":"init","version":0},{"n":355,"text":"\t\t\t\tlet weakest: MoveEntry | undefined;","atom":"a2368","author":"capacity","version":215},{"n":356,"text":"\t\t\t\tfor (const l of path.slice(loopAt)) {","atom":"a0","author":"init","version":0},{"n":357,"text":"\t\t\t\t\tconst e = relocs.get(l);","atom":"a2368","author":"capacity","version":215},{"n":358,"text":"\t\t\t\t\tif (e && (!weakest || stronger(weakest.r, e.r))) weakest = e;","atom":"a2368","author":"capacity","version":215},{"n":359,"text":"\t\t\t\t}","atom":"a0","author":"init","version":0},{"n":360,"text":"\t\t\t\tignored.add(identity(weakest!.r));","atom":"a2368","author":"capacity","version":215},{"n":361,"text":"\t\t\t\tconst next = pick(weakest!.n);","atom":"a2368","author":"capacity","version":215},{"n":362,"text":"\t\t\t\tif (next) relocs.set(weakest!.n, next);","atom":"a2368","author":"capacity","version":215},{"n":363,"text":"\t\t\t\telse relocs.delete(weakest!.n);","atom":"a2368","author":"capacity","version":215},{"n":364,"text":"\t\t\t}","atom":"a0","author":"init","version":0},{"n":365,"text":"\t\t}","atom":"a0","author":"init","version":0},{"n":366,"text":"\t\tthis.#relocsN = new Map([...relocs].map(([n, e]) => [n, { r: e.r, parent: e.parent }]));","atom":"a2368","author":"capacity","version":215},{"n":367,"text":"\t\tthis.#relocs = new Map([...relocs.values()].map((e) => [e.r.line, e.r]));","atom":"a2368","author":"capacity","version":215},{"n":368,"text":"\t\treturn this.#relocs;","atom":"a2368","author":"capacity","version":215},{"n":369,"text":"\t}","atom":"a0","author":"init","version":0},{"n":370,"text":"","atom":"a2319","author":"capacity","version":207},{"n":371,"text":"\t/** The view whose moves this one may take, until it needs them all; then the view it took them from. */","atom":"a2377","author":"capacity","version":216},{"n":372,"text":"\t#movesFrom: View | undefined;","atom":"a2377","author":"capacity","version":216},{"n":373,"text":"\t#movesTaken: View | undefined;","atom":"a2377","author":"capacity","version":216},{"n":374,"text":"","atom":"a2377","author":"capacity","version":216},{"n":375,"text":"\t/**","atom":"a2319","author":"capacity","version":207},{"n":376,"text":"\t * Take another view's resolved moves (abso Capacity), when both sets hold the very same atoms that move lines: the","atom":"a2350","author":"capacity","version":212},{"n":377,"text":"\t * moves then resolve the same, and every line sits where it sits there. Checked when this view first needs all its","atom":"a2377","author":"capacity","version":216},{"n":378,"text":"\t * moves, so any caller may ask, and a view that only finds a few lines' files never resolves them.","atom":"a2377","author":"capacity","version":216},{"n":379,"text":"\t */","atom":"a2319","author":"capacity","version":207},{"n":380,"text":"\tshareMoves(from: View): void {","atom":"a2319","author":"capacity","version":207},{"n":381,"text":"\t\tif (from.graph !== this.graph || from.#hasMoves !== this.#hasMoves || !this.#hasMoves || this.#relocs) return;","atom":"a2377","author":"capacity","version":216},{"n":382,"text":"\t\tthis.#movesFrom = from;","atom":"a2377","author":"capacity","version":216},{"n":383,"text":"\t}","atom":"a2377","author":"capacity","version":216},{"n":384,"text":"","atom":"a2377","author":"capacity","version":216},{"n":385,"text":"\t#takeShared(): void {","atom":"a2377","author":"capacity","version":216},{"n":386,"text":"\t\tconst from = this.#movesFrom;","atom":"a2377","author":"capacity","version":216},{"n":387,"text":"\t\tif (!from) return;","atom":"a2377","author":"capacity","version":216},{"n":388,"text":"\t\tthis.#movesFrom = undefined;","atom":"a2377","author":"capacity","version":216},{"n":389,"text":"\t\tif (from.#scratchMoves()) return;","atom":"a2377","author":"capacity","version":216},{"n":390,"text":"\t\tfor (const id of this.graph.movers()) {","atom":"a2350","author":"capacity","version":212},{"n":391,"text":"\t\t\tconst seq = seqOf(id);","atom":"a2350","author":"capacity","version":212},{"n":392,"text":"\t\t\tif (this.#has(seq) !== from.#has(seq)) return;","atom":"a2350","author":"capacity","version":212},{"n":393,"text":"\t\t}","atom":"a2350","author":"capacity","version":212},{"n":394,"text":"\t\tthis.#relocs = from.#relocations();","atom":"a2319","author":"capacity","version":207},{"n":395,"text":"\t\tthis.#relocsN = from.#relocationsN();","atom":"a2319","author":"capacity","version":207},{"n":396,"text":"\t\tthis.#movesOnDisk = false;","atom":"a2319","author":"capacity","version":207},{"n":397,"text":"\t\tthis.#movesTaken = from;","atom":"a2377","author":"capacity","version":216},{"n":398,"text":"\t}","atom":"a2319","author":"capacity","version":207},{"n":399,"text":"","atom":"a2377","author":"capacity","version":216},{"n":400,"text":"\t/** Moved lines' relocations picked one at a time, before the view resolves them all (null: not moved here). */","atom":"a2377","author":"capacity","version":216},{"n":401,"text":"\treadonly #picked = new Map<number, MoveEntry | null>();","atom":"a2377","author":"capacity","version":216},{"n":402,"text":"","atom":"a2319","author":"capacity","version":207},{"n":403,"text":"\t/**","atom":"a2377","author":"capacity","version":216},{"n":404,"text":"\t * The relocation of moved line n that counts here, as #relocations picks it before any loop: right whenever the","atom":"a2377","author":"capacity","version":216},{"n":405,"text":"\t * walk that reached n goes on to a file's start, since only lines on a loop have their relocation set aside.","atom":"a2377","author":"capacity","version":216},{"n":406,"text":"\t */","atom":"a2377","author":"capacity","version":216},{"n":407,"text":"\t#pickOne(n: number): MoveEntry | undefined {","atom":"a2377","author":"capacity","version":216},{"n":408,"text":"\t\tlet picked = this.#picked.get(n);","atom":"a2377","author":"capacity","version":216},{"n":409,"text":"\t\tif (picked === undefined) {","atom":"a2377","author":"capacity","version":216},{"n":410,"text":"\t\t\tconst graph = this.graph;","atom":"a2377","author":"capacity","version":216},{"n":411,"text":"\t\t\tlet best: MoveEntry | undefined;","atom":"a2377","author":"capacity","version":216},{"n":412,"text":"\t\t\tfor (const e of skeletonOf(graph).byLine.get(n) ?? []) {","atom":"a2377","author":"capacity","version":216},{"n":413,"text":"\t\t\t\tif (this.#has(seqOf(e.r.atom)) && (!best || graph.comparePriority(e.r.atom, best.r.atom) > 0)) best = e;","atom":"a2377","author":"capacity","version":216},{"n":414,"text":"\t\t\t}","atom":"a2377","author":"capacity","version":216},{"n":415,"text":"\t\t\tthis.#picked.set(n, (picked = best ?? null));","atom":"a2377","author":"capacity","version":216},{"n":416,"text":"\t\t}","atom":"a2377","author":"capacity","version":216},{"n":417,"text":"\t\treturn picked ?? undefined;","atom":"a2377","author":"capacity","version":216},{"n":418,"text":"\t}","atom":"a2377","author":"capacity","version":216},{"n":419,"text":"","atom":"a2377","author":"capacity","version":216},{"n":420,"text":"\t/** Whether moves are resolved on disk for each layout: only a stored graph's view with more than MOVED_LINES_KEPT. */","atom":"a2302","author":"capacity","version":205},{"n":421,"text":"\t#scratchMoves(): boolean {","atom":"a2302","author":"capacity","version":205},{"n":422,"text":"\t\tif (!this.#hasMoves || !this.graph.hasOrderedChildren) return false;","atom":"a2302","author":"capacity","version":205},{"n":423,"text":"\t\tif (this.#movesOnDisk === undefined) {","atom":"a2302","author":"capacity","version":205},{"n":424,"text":"\t\t\ttry {","atom":"a2302","author":"capacity","version":205},{"n":425,"text":"\t\t\t\tthis.#relocations();","atom":"a2302","author":"capacity","version":205},{"n":426,"text":"\t\t\t\tthis.#movesOnDisk = false;","atom":"a2302","author":"capacity","version":205},{"n":427,"text":"\t\t\t} catch (error) {","atom":"a2302","author":"capacity","version":205},{"n":428,"text":"\t\t\t\tif (!(error instanceof TooManyMoves)) throw error;","atom":"a2302","author":"capacity","version":205},{"n":429,"text":"\t\t\t\tthis.#movesOnDisk = true;","atom":"a2302","author":"capacity","version":205},{"n":430,"text":"\t\t\t}","atom":"a2302","author":"capacity","version":205},{"n":431,"text":"\t\t}","atom":"a2302","author":"capacity","version":205},{"n":432,"text":"\t\treturn this.#movesOnDisk;","atom":"a2302","author":"capacity","version":205},{"n":433,"text":"\t}","atom":"a2302","author":"capacity","version":205},{"n":434,"text":"","atom":"a2302","author":"capacity","version":205},{"n":435,"text":"\t/** The relocations by n, with each new parent's code. */","atom":"a0","author":"init","version":0},{"n":436,"text":"\t#relocationsN(): Map<number, { readonly r: RelocationInfo; readonly parent: number }> {","atom":"a0","author":"init","version":0},{"n":437,"text":"\t\tif (this.#relocsN) return this.#relocsN;","atom":"a0","author":"init","version":0},{"n":438,"text":"\t\tconst out = new Map<number, { readonly r: RelocationInfo; readonly parent: number }>();","atom":"a0","author":"init","version":0},{"n":439,"text":"\t\tfor (const [line, r] of this.#relocations())","atom":"a0","author":"init","version":0},{"n":440,"text":"\t\t\tout.set(this.graph.lineN(line), { r, parent: this.graph.codeOf(r.parent)! });","atom":"a0","author":"init","version":0},{"n":441,"text":"\t\tthis.#relocsN = out;","atom":"a0","author":"init","version":0},{"n":442,"text":"\t\treturn out;","atom":"a0","author":"init","version":0},{"n":443,"text":"\t}","atom":"a0","author":"init","version":0},{"n":444,"text":"","atom":"a0","author":"init","version":0},{"n":445,"text":"\t/** The node a line hangs off in this set: where it was written, or where a move put it. */","atom":"a0","author":"init","version":0},{"n":446,"text":"\tparentOf(line: LineId): NodeId {","atom":"a0","author":"init","version":0},{"n":447,"text":"\t\tif (this.graph.lineParent(line) === undefined) throw new EngineError(\"unknown-line\", `no line ${line}`);","atom":"a1114","author":"codex-capacity-chair","version":132},{"n":448,"text":"\t\tif (this.#scratchMoves())","atom":"a2302","author":"capacity","version":205},{"n":449,"text":"\t\t\treturn this.graph.withProjectionScratch((scratch) =>","atom":"a1112","author":"codex-capacity-chair","version":132},{"n":450,"text":"\t\t\t\tresolveScratchMoves(this.graph, (id) => this.#has(this.graph.atom(id).seq), scratch).parent(line),","atom":"a1112","author":"codex-capacity-chair","version":132},{"n":451,"text":"\t\t\t);","atom":"a1112","author":"codex-capacity-chair","version":132},{"n":452,"text":"\t\tconst r = this.#hasMoves ? this.#relocations().get(line) : undefined;","atom":"a1061","author":"codex-capacity-chair","version":123},{"n":453,"text":"\t\tif (r) return r.parent;","atom":"a0","author":"init","version":0},{"n":454,"text":"\t\tconst parent = this.graph.lineParent(line);","atom":"a0","author":"init","version":0},{"n":455,"text":"\t\tif (parent === undefined) throw new EngineError(\"unknown-line\", `no line ${line}`);","atom":"a0","author":"init","version":0},{"n":456,"text":"\t\treturn parent;","atom":"a0","author":"init","version":0},{"n":457,"text":"\t}","atom":"a0","author":"init","version":0},{"n":458,"text":"","atom":"a0","author":"init","version":0},{"n":459,"text":"\t/** Whether any atom in the set moves lines. */","atom":"a0","author":"init","version":0},{"n":460,"text":"\thasMoves(): boolean {","atom":"a0","author":"init","version":0},{"n":461,"text":"\t\treturn this.#hasMoves;","atom":"a1061","author":"codex-capacity-chair","version":123},{"n":462,"text":"\t}","atom":"a0","author":"init","version":0},{"n":463,"text":"","atom":"a0","author":"init","version":0},{"n":464,"text":"\t/** The file a line is in, in this set: the one its chain of parents reaches. */","atom":"a0","author":"init","version":0},{"n":465,"text":"\tfileOf(line: LineId): string {","atom":"a0","author":"init","version":0},{"n":466,"text":"\t\tconst n = this.graph.lineN(line);","atom":"a0","author":"init","version":0},{"n":467,"text":"\t\tif (n < 0) throw new EngineError(\"unknown-line\", `no line ${line}`);","atom":"a0","author":"init","version":0},{"n":468,"text":"\t\treturn this.#fileOfN(n);","atom":"a0","author":"init","version":0},{"n":469,"text":"\t}","atom":"a0","author":"init","version":0},{"n":470,"text":"","atom":"a0","author":"init","version":0},{"n":471,"text":"\t#fileOfN(n: number): string {","atom":"a0","author":"init","version":0},{"n":472,"text":"\t\tconst graph = this.graph;","atom":"a0","author":"init","version":0},{"n":473,"text":"\t\tif (!this.#hasMoves) return graph.writtenIn(n);","atom":"a1061","author":"codex-capacity-chair","version":123},{"n":474,"text":"\t\tif (this.#scratchMoves())","atom":"a2302","author":"capacity","version":205},{"n":475,"text":"\t\t\treturn graph.withProjectionScratch((scratch) => {","atom":"a1112","author":"codex-capacity-chair","version":132},{"n":476,"text":"\t\t\t\tconst moves = resolveScratchMoves(graph, (id) => this.#has(graph.atom(id).seq), scratch);","atom":"a1112","author":"codex-capacity-chair","version":132},{"n":477,"text":"\t\t\t\tlet current = graph.nodeOf(n);","atom":"a1112","author":"codex-capacity-chair","version":132},{"n":478,"text":"\t\t\t\twhile (!isStartNode(current)) current = moves.parent(current);","atom":"a1112","author":"codex-capacity-chair","version":132},{"n":479,"text":"\t\t\t\treturn current.slice(1);","atom":"a1112","author":"codex-capacity-chair","version":132},{"n":480,"text":"\t\t\t});","atom":"a1112","author":"codex-capacity-chair","version":132},{"n":481,"text":"\t\treturn this.#fileOfCode(n);","atom":"a2368","author":"capacity","version":215},{"n":482,"text":"\t}","atom":"a2368","author":"capacity","version":215},{"n":483,"text":"","atom":"a2368","author":"capacity","version":215},{"n":484,"text":"\t/** The file a node sits in, in this set: up by where lines were written, through the moves that count here. */","atom":"a2368","author":"capacity","version":215},{"n":485,"text":"\t#fileOfCode(code: number): string {","atom":"a2368","author":"capacity","version":215},{"n":486,"text":"\t\tconst graph = this.graph;","atom":"a2368","author":"capacity","version":215},{"n":487,"text":"\t\tconst skeleton = skeletonOf(graph);","atom":"a2368","author":"capacity","version":215},{"n":488,"text":"\t\tif (!this.#relocsN) {","atom":"a2377","author":"capacity","version":216},{"n":489,"text":"\t\t\t// One moved line at a time, until a walk comes back to a line it passed: then moves loop, and are resolved whole.","atom":"a2377","author":"capacity","version":216},{"n":490,"text":"\t\t\tconst passed = new Set<number>();","atom":"a2377","author":"capacity","version":216},{"n":491,"text":"\t\t\tlet c = code;","atom":"a2377","author":"capacity","version":216},{"n":492,"text":"\t\t\tfor (;;) {","atom":"a2377","author":"capacity","version":216},{"n":493,"text":"\t\t\t\tc = skeleton.climb(c);","atom":"a2377","author":"capacity","version":216},{"n":494,"text":"\t\t\t\tif (c < 0) return graph.nodeOf(c).slice(1);","atom":"a2377","author":"capacity","version":216},{"n":495,"text":"\t\t\t\tif (passed.has(c)) break;","atom":"a2377","author":"capacity","version":216},{"n":496,"text":"\t\t\t\tpassed.add(c);","atom":"a2377","author":"capacity","version":216},{"n":497,"text":"\t\t\t\tconst e = this.#pickOne(c);","atom":"a2377","author":"capacity","version":216},{"n":498,"text":"\t\t\t\tc = e ? e.parent : graph.parentCodeOf(c);","atom":"a2377","author":"capacity","version":216},{"n":499,"text":"\t\t\t}","atom":"a2377","author":"capacity","version":216},{"n":500,"text":"\t\t}","atom":"a2377","author":"capacity","version":216},{"n":501,"text":"\t\tconst relocs = this.#relocationsN();","atom":"a0","author":"init","version":0},{"n":502,"text":"\t\tlet c = code;","atom":"a2368","author":"capacity","version":215},{"n":503,"text":"\t\tfor (;;) {","atom":"a2368","author":"capacity","version":215},{"n":504,"text":"\t\t\tc = skeleton.climb(c);","atom":"a2368","author":"capacity","version":215},{"n":505,"text":"\t\t\tif (c < 0) return graph.nodeOf(c).slice(1);","atom":"a2368","author":"capacity","version":215},{"n":506,"text":"\t\t\tconst e = relocs.get(c);","atom":"a2368","author":"capacity","version":215},{"n":507,"text":"\t\t\tc = e ? e.parent : graph.parentCodeOf(c);","atom":"a2368","author":"capacity","version":215},{"n":508,"text":"\t\t}","atom":"a0","author":"init","version":0},{"n":509,"text":"\t}","atom":"a0","author":"init","version":0},{"n":510,"text":"","atom":"a0","author":"init","version":0},{"n":511,"text":"\t/** The lines hanging off a node in this set, in layout order. */","atom":"a0","author":"init","version":0},{"n":512,"text":"\t#children(code: number): Child[] {","atom":"a0","author":"init","version":0},{"n":513,"text":"\t\tconst graph = this.graph;","atom":"a0","author":"init","version":0},{"n":514,"text":"\t\tconst relocs = this.#hasMoves ? this.#relocationsN() : undefined;","atom":"a1061","author":"codex-capacity-chair","version":123},{"n":515,"text":"\t\tconst out: Child[] = [];","atom":"a0","author":"init","version":0},{"n":516,"text":"\t\tfor (const n of graph.eachChildN(code)) {","atom":"a1091","author":"codex-capacity-chair","version":130},{"n":517,"text":"\t\t\tconst seq = graph.writerSeqOf(n);","atom":"a0","author":"init","version":0},{"n":518,"text":"\t\t\tif (!this.#has(seq) || relocs?.has(n)) continue;","atom":"a0","author":"init","version":0},{"n":519,"text":"\t\t\tout.push({ n, replaces: graph.replacesN(n) ? 1 : 0, lamport: graph.lamportOfSeq(seq), seq, k: graph.kOf(n) });","atom":"a0","author":"init","version":0},{"n":520,"text":"\t\t}","atom":"a0","author":"init","version":0},{"n":521,"text":"\t\tif (relocs) {","atom":"a0","author":"init","version":0},{"n":522,"text":"\t\t\t// The lines this set's moves put under each node, from the moves it already resolved: no row read per node","atom":"a2302","author":"capacity","version":205},{"n":523,"text":"\t\t\t// (abso Capacity).","atom":"a2302","author":"capacity","version":205},{"n":524,"text":"\t\t\tif (!this.#movedInto) {","atom":"a2302","author":"capacity","version":205},{"n":525,"text":"\t\t\t\tthis.#movedInto = new Map();","atom":"a2302","author":"capacity","version":205},{"n":526,"text":"\t\t\t\tfor (const [n, { parent }] of relocs) {","atom":"a2302","author":"capacity","version":205},{"n":527,"text":"\t\t\t\t\tconst into = this.#movedInto.get(parent);","atom":"a2302","author":"capacity","version":205},{"n":528,"text":"\t\t\t\t\tif (into) into.push(n);","atom":"a2302","author":"capacity","version":205},{"n":529,"text":"\t\t\t\t\telse this.#movedInto.set(parent, [n]);","atom":"a2302","author":"capacity","version":205},{"n":530,"text":"\t\t\t\t}","atom":"a2302","author":"capacity","version":205},{"n":531,"text":"\t\t\t}","atom":"a2302","author":"capacity","version":205},{"n":532,"text":"\t\t\tfor (const n of this.#movedInto.get(code) ?? NO_LINES) {","atom":"a2302","author":"capacity","version":205},{"n":533,"text":"\t\t\t\tconst r = relocs.get(n)!.r;","atom":"a2302","author":"capacity","version":205},{"n":534,"text":"\t\t\t\tconst seq = graph.atom(r.atom).seq;","atom":"a0","author":"init","version":0},{"n":535,"text":"\t\t\t\tout.push({ n, replaces: 0, lamport: graph.lamportOfSeq(seq), seq, k: r.k });","atom":"a0","author":"init","version":0},{"n":536,"text":"\t\t\t}","atom":"a0","author":"init","version":0},{"n":537,"text":"\t\t}","atom":"a0","author":"init","version":0},{"n":538,"text":"\t\t// A line's replacements (runs of atoms that deleted it) first, then the","atom":"a0","author":"init","version":0},{"n":539,"text":"\t\t// rest; each group in descending priority (lamport, then seq); lines of","atom":"a0","author":"init","version":0},{"n":540,"text":"\t\t// one atom keep k order. A replacement already outranks every insertion","atom":"a0","author":"init","version":0},{"n":541,"text":"\t\t// after the line that reads it (it depends on them, or conflicts with","atom":"a0","author":"init","version":0},{"n":542,"text":"\t\t// them); the grouping also puts it above a `before` insertion, which","atom":"a0","author":"init","version":0},{"n":543,"text":"\t\t// doesn't read the line above, so the new text lands in the replaced","atom":"a0","author":"init","version":0},{"n":544,"text":"\t\t// line's place. A moved line ranks like an insertion by the moving atom.","atom":"a0","author":"init","version":0},{"n":545,"text":"\t\tif (out.length > 1)","atom":"a0","author":"init","version":0},{"n":546,"text":"\t\t\tout.sort((a, b) => b.replaces - a.replaces || b.lamport - a.lamport || b.seq - a.seq || a.k - b.k);","atom":"a0","author":"init","version":0},{"n":547,"text":"\t\treturn out;","atom":"a0","author":"init","version":0},{"n":548,"text":"\t}","atom":"a0","author":"init","version":0},{"n":549,"text":"","atom":"a0","author":"init","version":0},{"n":550,"text":"\t/** Parent/successor traversal keeps no history-sized ancestry or sibling frontier. */","atom":"a1105","author":"codex-capacity-chair","version":131},{"n":551,"text":"\t*#layoutNodes(start: number): IterableIterator<number> {","atom":"a1105","author":"codex-capacity-chair","version":131},{"n":552,"text":"\t\tconst graph = this.graph;","atom":"a1105","author":"codex-capacity-chair","version":131},{"n":553,"text":"\t\tif (graph.hasOrderedChildren && !this.#hasMoves) {","atom":"a1105","author":"codex-capacity-chair","version":131},{"n":554,"text":"\t\t\tconst first = (parent: number, after?: number): number | undefined => {","atom":"a1105","author":"codex-capacity-chair","version":131},{"n":555,"text":"\t\t\t\tfor (const n of graph.orderedChildrenN(parent, after)) if (this.#has(graph.writerSeqOf(n))) return n;","atom":"a1105","author":"codex-capacity-chair","version":131},{"n":556,"text":"\t\t\t\treturn undefined;","atom":"a1105","author":"codex-capacity-chair","version":131},{"n":557,"text":"\t\t\t};","atom":"a1105","author":"codex-capacity-chair","version":131},{"n":558,"text":"\t\t\tlet n = first(start);","atom":"a1105","author":"codex-capacity-chair","version":131},{"n":559,"text":"\t\t\twhile (n !== undefined) {","atom":"a1105","author":"codex-capacity-chair","version":131},{"n":560,"text":"\t\t\t\tyield n;","atom":"a1105","author":"codex-capacity-chair","version":131},{"n":561,"text":"\t\t\t\tconst child = first(n);","atom":"a1105","author":"codex-capacity-chair","version":131},{"n":562,"text":"\t\t\t\tif (child !== undefined) {","atom":"a1105","author":"codex-capacity-chair","version":131},{"n":563,"text":"\t\t\t\t\tn = child;","atom":"a1105","author":"codex-capacity-chair","version":131},{"n":564,"text":"\t\t\t\t\tcontinue;","atom":"a1105","author":"codex-capacity-chair","version":131},{"n":565,"text":"\t\t\t\t}","atom":"a1105","author":"codex-capacity-chair","version":131},{"n":566,"text":"\t\t\t\tlet previous = n;","atom":"a1105","author":"codex-capacity-chair","version":131},{"n":567,"text":"\t\t\t\tfor (;;) {","atom":"a1105","author":"codex-capacity-chair","version":131},{"n":568,"text":"\t\t\t\t\tconst parent = graph.parentCodeOf(previous);","atom":"a1105","author":"codex-capacity-chair","version":131},{"n":569,"text":"\t\t\t\t\tconst sibling = first(parent, previous);","atom":"a1105","author":"codex-capacity-chair","version":131},{"n":570,"text":"\t\t\t\t\tif (sibling !== undefined) {","atom":"a1105","author":"codex-capacity-chair","version":131},{"n":571,"text":"\t\t\t\t\t\tn = sibling;","atom":"a1105","author":"codex-capacity-chair","version":131},{"n":572,"text":"\t\t\t\t\t\tbreak;","atom":"a1105","author":"codex-capacity-chair","version":131},{"n":573,"text":"\t\t\t\t\t}","atom":"a1105","author":"codex-capacity-chair","version":131},{"n":574,"text":"\t\t\t\t\tif (parent === start) {","atom":"a1105","author":"codex-capacity-chair","version":131},{"n":575,"text":"\t\t\t\t\t\tn = undefined;","atom":"a1105","author":"codex-capacity-chair","version":131},{"n":576,"text":"\t\t\t\t\t\tbreak;","atom":"a1105","author":"codex-capacity-chair","version":131},{"n":577,"text":"\t\t\t\t\t}","atom":"a1105","author":"codex-capacity-chair","version":131},{"n":578,"text":"\t\t\t\t\tif (parent < 0 || parent >= previous) throw new Error(\"invalid persistent layout ancestry\");","atom":"a1105","author":"codex-capacity-chair","version":131},{"n":579,"text":"\t\t\t\t\tprevious = parent;","atom":"a1105","author":"codex-capacity-chair","version":131},{"n":580,"text":"\t\t\t\t}","atom":"a1105","author":"codex-capacity-chair","version":131},{"n":581,"text":"\t\t\t}","atom":"a1105","author":"codex-capacity-chair","version":131},{"n":582,"text":"\t\t\treturn;","atom":"a1105","author":"codex-capacity-chair","version":131},{"n":583,"text":"\t\t}","atom":"a1105","author":"codex-capacity-chair","version":131},{"n":584,"text":"\t\tconst stack: number[] = [];","atom":"a0","author":"init","version":0},{"n":585,"text":"\t\tconst push = (parent: number): void => {","atom":"a1105","author":"codex-capacity-chair","version":131},{"n":586,"text":"\t\t\tconst children = this.#children(parent);","atom":"a1105","author":"codex-capacity-chair","version":131},{"n":587,"text":"\t\t\tfor (let i = children.length - 1; i >= 0; i--) stack.push(children[i]!.n);","atom":"a1105","author":"codex-capacity-chair","version":131},{"n":588,"text":"\t\t};","atom":"a1105","author":"codex-capacity-chair","version":131},{"n":589,"text":"\t\tpush(start);","atom":"a1105","author":"codex-capacity-chair","version":131},{"n":590,"text":"\t\twhile (stack.length) {","atom":"a1105","author":"codex-capacity-chair","version":131},{"n":591,"text":"\t\t\tconst n = stack.pop()!;","atom":"a1105","author":"codex-capacity-chair","version":131},{"n":592,"text":"\t\t\tyield n;","atom":"a1105","author":"codex-capacity-chair","version":131},{"n":593,"text":"\t\t\tpush(n);","atom":"a1105","author":"codex-capacity-chair","version":131},{"n":594,"text":"\t\t}","atom":"a1105","author":"codex-capacity-chair","version":131},{"n":595,"text":"\t}","atom":"a1105","author":"codex-capacity-chair","version":131},{"n":596,"text":"","atom":"a1105","author":"codex-capacity-chair","version":131},{"n":597,"text":"\t/** Lay out one file: its line tree from the set's atoms, linearized. */","atom":"a0","author":"init","version":0},{"n":598,"text":"\t#layout(path: string, complete: boolean): FileState {","atom":"a1006","author":"codex-capacity-chair","version":110},{"n":599,"text":"\t\tconst graph = this.graph;","atom":"a0","author":"init","version":0},{"n":600,"text":"\t\tif (graph.packedLayout && !this.#scratchMoves()) return this.#layoutPacked(path, complete);","atom":"a2399","author":"capacity","version":221},{"n":601,"text":"\t\tif (this.#scratchMoves())","atom":"a2302","author":"capacity","version":205},{"n":602,"text":"\t\t\treturn graph.withProjectionScratch((scratch) =>","atom":"a1112","author":"codex-capacity-chair","version":132},{"n":603,"text":"\t\t\t\tthis.#layoutResolved(","atom":"a1112","author":"codex-capacity-chair","version":132},{"n":604,"text":"\t\t\t\t\tpath,","atom":"a1112","author":"codex-capacity-chair","version":132},{"n":605,"text":"\t\t\t\t\tcomplete,","atom":"a1112","author":"codex-capacity-chair","version":132},{"n":606,"text":"\t\t\t\t\tscratchLayoutNodes(graph, (id) => this.#has(graph.atom(id).seq), scratch, `^${path}`),","atom":"a1112","author":"codex-capacity-chair","version":132},{"n":607,"text":"\t\t\t\t),","atom":"a1112","author":"codex-capacity-chair","version":132},{"n":608,"text":"\t\t\t);","atom":"a1112","author":"codex-capacity-chair","version":132},{"n":609,"text":"\t\treturn this.#layoutResolved(path, complete);","atom":"a1112","author":"codex-capacity-chair","version":132},{"n":610,"text":"\t}","atom":"a1112","author":"codex-capacity-chair","version":132},{"n":611,"text":"","atom":"a1112","author":"codex-capacity-chair","version":132},{"n":612,"text":"\t/** For each path, the files that lines moved into it were written in: worked out once per view. */","atom":"a2312","author":"capacity","version":206},{"n":613,"text":"\t#movedFrom: Map<string, Set<number>> | undefined;","atom":"a2312","author":"capacity","version":206},{"n":614,"text":"\t#movedInFrom(): Map<string, Set<number>> {","atom":"a2312","author":"capacity","version":206},{"n":615,"text":"\t\tif (this.#movedFrom) return this.#movedFrom;","atom":"a2312","author":"capacity","version":206},{"n":616,"text":"\t\tthis.#relocations();","atom":"a2377","author":"capacity","version":216},{"n":617,"text":"\t\tif (this.#movesTaken) return (this.#movedFrom = this.#movesTaken.#movedInFrom());","atom":"a2377","author":"capacity","version":216},{"n":618,"text":"\t\tconst graph = this.graph;","atom":"a2312","author":"capacity","version":206},{"n":619,"text":"\t\tconst out = new Map<string, Set<number>>();","atom":"a2312","author":"capacity","version":206},{"n":620,"text":"\t\tif (this.#hasMoves) {","atom":"a2312","author":"capacity","version":206},{"n":621,"text":"\t\t\tconst relocs = this.#relocationsN();","atom":"a2312","author":"capacity","version":206},{"n":622,"text":"\t\t\tconst fileOf = (code: number): string => this.#fileOfCode(code);","atom":"a2368","author":"capacity","version":215},{"n":623,"text":"\t\t\tfor (const [n, { parent }] of relocs) {","atom":"a2312","author":"capacity","version":206},{"n":624,"text":"\t\t\t\tconst into = fileOf(parent);","atom":"a2312","author":"capacity","version":206},{"n":625,"text":"\t\t\t\tlet from = out.get(into);","atom":"a2312","author":"capacity","version":206},{"n":626,"text":"\t\t\t\tif (!from) out.set(into, (from = new Set()));","atom":"a2312","author":"capacity","version":206},{"n":627,"text":"\t\t\t\tfrom.add(graph.writtenInIndex(n));","atom":"a2312","author":"capacity","version":206},{"n":628,"text":"\t\t\t}","atom":"a2312","author":"capacity","version":206},{"n":629,"text":"\t\t}","atom":"a2312","author":"capacity","version":206},{"n":630,"text":"\t\tthis.#movedFrom = out;","atom":"a2312","author":"capacity","version":206},{"n":631,"text":"\t\treturn out;","atom":"a2312","author":"capacity","version":206},{"n":632,"text":"\t}","atom":"a2312","author":"capacity","version":206},{"n":633,"text":"","atom":"a2312","author":"capacity","version":206},{"n":634,"text":"\t/**","atom":"a2312","author":"capacity","version":206},{"n":635,"text":"\t * Lay one file out from its packed history (abso Capacity, Graph.packedLines): the lines written in it, in the files","atom":"a2399","author":"capacity","version":221},{"n":636,"text":"\t * its moved-in lines came from, and in the files runs under any of those lines were written in, read a page at a","atom":"a2399","author":"capacity","version":221},{"n":637,"text":"\t * time; the same tree and order as #layoutResolved, built in memory with no read per line.","atom":"a2399","author":"capacity","version":221},{"n":638,"text":"\t */","atom":"a2312","author":"capacity","version":206},{"n":639,"text":"\t#layoutPacked(path: string, complete: boolean): FileState {","atom":"a2312","author":"capacity","version":206},{"n":640,"text":"\t\tconst graph = this.graph;","atom":"a2312","author":"capacity","version":206},{"n":641,"text":"\t\tconst attrs = this.#attributes(path);","atom":"a2312","author":"capacity","version":206},{"n":642,"text":"\t\tconst start = graph.startCodeOf(path);","atom":"a2312","author":"capacity","version":206},{"n":643,"text":"\t\tif (start === undefined) return { attrs, complete, seq: EMPTY_INTS, vis: EMPTY_INTS, deletedBy: new Map() };","atom":"a2312","author":"capacity","version":206},{"n":644,"text":"\t\tconst relocs = this.#hasMoves ? this.#relocationsN() : undefined;","atom":"a2312","author":"capacity","version":206},{"n":645,"text":"\t\tconst files = new Set<number>([-1 - start, ...(this.#movedInFrom().get(path) ?? [])]);","atom":"a2312","author":"capacity","version":206},{"n":646,"text":"\t\tconst children = new Map<number, Child[]>();","atom":"a2312","author":"capacity","version":206},{"n":647,"text":"\t\tconst texts = new Map<number, string | null>();","atom":"a2312","author":"capacity","version":206},{"n":648,"text":"\t\tconst deleters = new Map<number, number[]>();","atom":"a2312","author":"capacity","version":206},{"n":649,"text":"\t\tfor (const file of files) {","atom":"a2312","author":"capacity","version":206},{"n":650,"text":"\t\t\tconst lineTexts = graph.packedTexts(file);","atom":"a2312","author":"capacity","version":206},{"n":651,"text":"\t\t\tfor (const [n, parent, seq, k, replaces] of graph.packedLines(file)) {","atom":"a2312","author":"capacity","version":206},{"n":652,"text":"\t\t\t\tconst text = lineTexts.next().value as string | null;","atom":"a2312","author":"capacity","version":206},{"n":653,"text":"\t\t\t\tif (!this.#has(seq)) continue;","atom":"a2312","author":"capacity","version":206},{"n":654,"text":"\t\t\t\tconst moved = relocs?.get(n);","atom":"a2312","author":"capacity","version":206},{"n":655,"text":"\t\t\t\tlet at = parent;","atom":"a2312","author":"capacity","version":206},{"n":656,"text":"\t\t\t\tlet child: Child = { n, replaces, lamport: graph.lamportOfSeq(seq), seq, k };","atom":"a2312","author":"capacity","version":206},{"n":657,"text":"\t\t\t\tif (moved) {","atom":"a2312","author":"capacity","version":206},{"n":658,"text":"\t\t\t\t\tconst mover = graph.atom(moved.r.atom).seq;","atom":"a2312","author":"capacity","version":206},{"n":659,"text":"\t\t\t\t\tchild = { n, replaces: 0, lamport: graph.lamportOfSeq(mover), seq: mover, k: moved.r.k };","atom":"a2312","author":"capacity","version":206},{"n":660,"text":"\t\t\t\t\tat = moved.parent;","atom":"a2312","author":"capacity","version":206},{"n":661,"text":"\t\t\t\t}","atom":"a2312","author":"capacity","version":206},{"n":662,"text":"\t\t\t\tconst list = children.get(at);","atom":"a2312","author":"capacity","version":206},{"n":663,"text":"\t\t\t\tif (list) list.push(child);","atom":"a2312","author":"capacity","version":206},{"n":664,"text":"\t\t\t\telse children.set(at, [child]);","atom":"a2312","author":"capacity","version":206},{"n":665,"text":"\t\t\t\ttexts.set(n, text);","atom":"a2312","author":"capacity","version":206},{"n":666,"text":"\t\t\t}","atom":"a2312","author":"capacity","version":206},{"n":667,"text":"\t\t\tfor (const [n, deleter] of graph.packedDeletes(file)) {","atom":"a2312","author":"capacity","version":206},{"n":668,"text":"\t\t\t\tif (!this.#has(deleter)) continue;","atom":"a2312","author":"capacity","version":206},{"n":669,"text":"\t\t\t\tconst by = deleters.get(n);","atom":"a2312","author":"capacity","version":206},{"n":670,"text":"\t\t\t\tif (by) by.push(deleter);","atom":"a2312","author":"capacity","version":206},{"n":671,"text":"\t\t\t\telse deleters.set(n, [deleter]);","atom":"a2312","author":"capacity","version":206},{"n":672,"text":"\t\t\t}","atom":"a2312","author":"capacity","version":206},{"n":673,"text":"\t\t\t// Runs written elsewhere under this file's lines follow them; the loop reads their files too.","atom":"a2399","author":"capacity","version":221},{"n":674,"text":"\t\t\tfor (const [parent, into] of graph.packedCrossings(file)) if (texts.has(parent)) files.add(into);","atom":"a2399","author":"capacity","version":221},{"n":675,"text":"\t\t}","atom":"a2312","author":"capacity","version":206},{"n":676,"text":"\t\tconst order = (a: Child, b: Child) =>","atom":"a2312","author":"capacity","version":206},{"n":677,"text":"\t\t\tb.replaces - a.replaces || b.lamport - a.lamport || b.seq - a.seq || a.k - b.k;","atom":"a2312","author":"capacity","version":206},{"n":678,"text":"\t\tconst priority = (a: number, b: number) => graph.lamportOfSeq(a) - graph.lamportOfSeq(b) || a - b;","atom":"a2312","author":"capacity","version":206},{"n":679,"text":"\t\tconst seq: number[] = [];","atom":"a2312","author":"capacity","version":206},{"n":680,"text":"\t\tconst vis: number[] = [];","atom":"a2312","author":"capacity","version":206},{"n":681,"text":"\t\tconst visText: (string | null)[] = [];","atom":"a2312","author":"capacity","version":206},{"n":682,"text":"\t\tconst deletedBy = new Map<number, readonly number[]>();","atom":"a2312","author":"capacity","version":206},{"n":683,"text":"\t\tconst stack: number[] = [];","atom":"a2312","author":"capacity","version":206},{"n":684,"text":"\t\tconst push = (code: number) => {","atom":"a2312","author":"capacity","version":206},{"n":685,"text":"\t\t\tconst list = children.get(code);","atom":"a2312","author":"capacity","version":206},{"n":686,"text":"\t\t\tif (!list) return;","atom":"a2312","author":"capacity","version":206},{"n":687,"text":"\t\t\tif (list.length > 1) list.sort(order);","atom":"a2312","author":"capacity","version":206},{"n":688,"text":"\t\t\tfor (let i = list.length - 1; i >= 0; i--) stack.push(list[i]!.n);","atom":"a2312","author":"capacity","version":206},{"n":689,"text":"\t\t};","atom":"a2312","author":"capacity","version":206},{"n":690,"text":"\t\tpush(start);","atom":"a2312","author":"capacity","version":206},{"n":691,"text":"\t\twhile (stack.length) {","atom":"a2312","author":"capacity","version":206},{"n":692,"text":"\t\t\tconst n = stack.pop()!;","atom":"a2312","author":"capacity","version":206},{"n":693,"text":"\t\t\tconst by = deleters.get(n);","atom":"a2312","author":"capacity","version":206},{"n":694,"text":"\t\t\tif (by) {","atom":"a2312","author":"capacity","version":206},{"n":695,"text":"\t\t\t\tif (complete) deletedBy.set(seq.length, by.length > 1 ? by.sort(priority) : by);","atom":"a2312","author":"capacity","version":206},{"n":696,"text":"\t\t\t} else {","atom":"a2312","author":"capacity","version":206},{"n":697,"text":"\t\t\t\tvis.push(n);","atom":"a2312","author":"capacity","version":206},{"n":698,"text":"\t\t\t\tvisText.push(texts.get(n) ?? null);","atom":"a2312","author":"capacity","version":206},{"n":699,"text":"\t\t\t}","atom":"a2312","author":"capacity","version":206},{"n":700,"text":"\t\t\tif (complete) seq.push(n);","atom":"a2312","author":"capacity","version":206},{"n":701,"text":"\t\t\tpush(n);","atom":"a2312","author":"capacity","version":206},{"n":702,"text":"\t\t}","atom":"a2312","author":"capacity","version":206},{"n":703,"text":"\t\treturn { attrs, complete, seq: Int32Array.from(seq), vis: Int32Array.from(vis), deletedBy, visText };","atom":"a2312","author":"capacity","version":206},{"n":704,"text":"\t}","atom":"a2312","author":"capacity","version":206},{"n":705,"text":"","atom":"a2312","author":"capacity","version":206},{"n":706,"text":"\t#attributes(path: string): FileAttrs {","atom":"a1152","author":"codex-capacity-chair","version":140},{"n":707,"text":"\t\tconst graph = this.graph;","atom":"a1112","author":"codex-capacity-chair","version":132},{"n":708,"text":"\t\t// For each attribute, the highest-priority setter in the set wins.","atom":"a0","author":"init","version":0},{"n":709,"text":"\t\tconst setters = new Map<string, { id: AtomId; value: string | null }>();","atom":"a0","author":"init","version":0},{"n":710,"text":"\t\tconst file = graph.packedFiles ? graph.pathIndexOf(path) : undefined;","atom":"a2312","author":"capacity","version":206},{"n":711,"text":"\t\tif (graph.packedFiles) {","atom":"a2312","author":"capacity","version":206},{"n":712,"text":"\t\t\tfor (const [seq, name, value] of file === undefined ? [] : graph.packedAttrs(file)) {","atom":"a2312","author":"capacity","version":206},{"n":713,"text":"\t\t\t\tif (!this.#has(seq)) continue;","atom":"a2312","author":"capacity","version":206},{"n":714,"text":"\t\t\t\tconst id = graph.idOfSeq(seq);","atom":"a2312","author":"capacity","version":206},{"n":715,"text":"\t\t\t\tconst best = setters.get(name);","atom":"a2312","author":"capacity","version":206},{"n":716,"text":"\t\t\t\tif (!best || graph.comparePriority(best.id, id) < 0) setters.set(name, { id, value });","atom":"a2312","author":"capacity","version":206},{"n":717,"text":"\t\t\t}","atom":"a2312","author":"capacity","version":206},{"n":718,"text":"\t\t\treturn {","atom":"a2312","author":"capacity","version":206},{"n":719,"text":"\t\t\t\texists: setters.get(\"exists\")?.value === \"1\",","atom":"a2312","author":"capacity","version":206},{"n":720,"text":"\t\t\t\texec: setters.get(\"exec\")?.value === \"1\",","atom":"a2312","author":"capacity","version":206},{"n":721,"text":"\t\t\t\tlink: setters.get(\"link\")?.value ?? null,","atom":"a2312","author":"capacity","version":206},{"n":722,"text":"\t\t\t\tblob: setters.get(\"blob\")?.value ?? null,","atom":"a2312","author":"capacity","version":206},{"n":723,"text":"\t\t\t};","atom":"a2312","author":"capacity","version":206},{"n":724,"text":"\t\t}","atom":"a2312","author":"capacity","version":206},{"n":725,"text":"\t\tfor (const id of graph.eachAtomIn(path)) {","atom":"a1045","author":"codex-capacity-chair","version":119},{"n":726,"text":"\t\t\tif (!this.#has(graph.atom(id).seq)) continue;","atom":"a0","author":"init","version":0},{"n":727,"text":"\t\t\tfor (const a of graph.atom(id).attrs ?? []) {","atom":"a0","author":"init","version":0},{"n":728,"text":"\t\t\t\tif (a.file !== path) continue;","atom":"a0","author":"init","version":0},{"n":729,"text":"\t\t\t\tconst best = setters.get(a.name);","atom":"a0","author":"init","version":0},{"n":730,"text":"\t\t\t\tif (!best || graph.comparePriority(best.id, id) < 0) setters.set(a.name, { id, value: a.value });","atom":"a0","author":"init","version":0},{"n":731,"text":"\t\t\t}","atom":"a0","author":"init","version":0},{"n":732,"text":"\t\t}","atom":"a0","author":"init","version":0},{"n":733,"text":"","atom":"a1152","author":"codex-capacity-chair","version":140},{"n":734,"text":"\t\treturn {","atom":"a1152","author":"codex-capacity-chair","version":140},{"n":735,"text":"\t\t\texists: setters.get(\"exists\")?.value === \"1\",","atom":"a0","author":"init","version":0},{"n":736,"text":"\t\t\texec: setters.get(\"exec\")?.value === \"1\",","atom":"a0","author":"init","version":0},{"n":737,"text":"\t\t\tlink: setters.get(\"link\")?.value ?? null,","atom":"a0","author":"init","version":0},{"n":738,"text":"\t\t\tblob: setters.get(\"blob\")?.value ?? null,","atom":"a0","author":"init","version":0},{"n":739,"text":"\t\t};","atom":"a0","author":"init","version":0},{"n":740,"text":"\t}","atom":"a1152","author":"codex-capacity-chair","version":140},{"n":741,"text":"","atom":"a0","author":"init","version":0},{"n":742,"text":"\t#layoutResolved(path: string, complete: boolean, nodes?: Iterable<number>): FileState {","atom":"a1112","author":"codex-capacity-chair","version":132},{"n":743,"text":"\t\tconst graph = this.graph;","atom":"a1152","author":"codex-capacity-chair","version":140},{"n":744,"text":"\t\tconst attrs = this.#attributes(path);","atom":"a1152","author":"codex-capacity-chair","version":140},{"n":745,"text":"\t\tconst seq: number[] = [];","atom":"a0","author":"init","version":0},{"n":746,"text":"\t\tconst vis: number[] = [];","atom":"a0","author":"init","version":0},{"n":747,"text":"\t\tconst deletedBy = new Map<number, readonly number[]>();","atom":"a0","author":"init","version":0},{"n":748,"text":"","atom":"a1105","author":"codex-capacity-chair","version":131},{"n":749,"text":"\t\tconst start = graph.startCodeOf(path);","atom":"a0","author":"init","version":0},{"n":750,"text":"\t\tconst priority = (a: number, b: number) => graph.lamportOfSeq(a) - graph.lamportOfSeq(b) || a - b;","atom":"a0","author":"init","version":0},{"n":751,"text":"\t\tfor (const n of nodes ?? (start === undefined ? [] : this.#layoutNodes(start))) {","atom":"a1112","author":"codex-capacity-chair","version":132},{"n":752,"text":"\t\t\tlet deleted = false;","atom":"a1083","author":"codex-capacity-chair","version":128},{"n":753,"text":"\t\t\tconst by: number[] = [];","atom":"a1083","author":"codex-capacity-chair","version":128},{"n":754,"text":"\t\t\tfor (const deleter of graph.eachDeleterSeqOf(n)) {","atom":"a1083","author":"codex-capacity-chair","version":128},{"n":755,"text":"\t\t\t\tif (!this.#has(deleter)) continue;","atom":"a1083","author":"codex-capacity-chair","version":128},{"n":756,"text":"\t\t\t\tdeleted = true;","atom":"a1083","author":"codex-capacity-chair","version":128},{"n":757,"text":"\t\t\t\tif (!complete) break;","atom":"a1083","author":"codex-capacity-chair","version":128},{"n":758,"text":"\t\t\t\tby.push(deleter);","atom":"a1083","author":"codex-capacity-chair","version":128},{"n":759,"text":"\t\t\t}","atom":"a1083","author":"codex-capacity-chair","version":128},{"n":760,"text":"\t\t\tif (deleted) {","atom":"a1083","author":"codex-capacity-chair","version":128},{"n":761,"text":"\t\t\t\tif (complete) deletedBy.set(seq.length, by.length > 1 ? by.sort(priority) : by);","atom":"a1083","author":"codex-capacity-chair","version":128},{"n":762,"text":"\t\t\t} else vis.push(n);","atom":"a1006","author":"codex-capacity-chair","version":110},{"n":763,"text":"\t\t\tif (complete) seq.push(n);","atom":"a1006","author":"codex-capacity-chair","version":110},{"n":764,"text":"\t\t}","atom":"a0","author":"init","version":0},{"n":765,"text":"","atom":"a1152","author":"codex-capacity-chair","version":140},{"n":766,"text":"\t\treturn { attrs, complete, seq: Int32Array.from(seq), vis: Int32Array.from(vis), deletedBy };","atom":"a1006","author":"codex-capacity-chair","version":110},{"n":767,"text":"\t}","atom":"a0","author":"init","version":0},{"n":768,"text":"","atom":"a0","author":"init","version":0},{"n":769,"text":"\tget #known(): string[] {","atom":"a0","author":"init","version":0},{"n":770,"text":"\t\tif (!this.#knownList) {","atom":"a0","author":"init","version":0},{"n":771,"text":"\t\t\tconst known = new Set<string>();","atom":"a0","author":"init","version":0},{"n":772,"text":"\t\t\tif (this.#stable) {","atom":"a998","author":"codex-capacity-chair","version":109},{"n":773,"text":"\t\t\t\tfor (const id of this.#stable) for (const file of this.graph.filesOf(id)) known.add(file);","atom":"a998","author":"codex-capacity-chair","version":109},{"n":774,"text":"\t\t\t} else {","atom":"a998","author":"codex-capacity-chair","version":109},{"n":775,"text":"\t\t\t\tfor (let seq = 0; seq < this.#in.length; seq++)","atom":"a998","author":"codex-capacity-chair","version":109},{"n":776,"text":"\t\t\t\t\tif (this.#in[seq] === 1) for (const file of this.graph.filesOf(this.graph.idOfSeq(seq))) known.add(file);","atom":"a998","author":"codex-capacity-chair","version":109},{"n":777,"text":"\t\t\t}","atom":"a998","author":"codex-capacity-chair","version":109},{"n":778,"text":"\t\t\tthis.#knownList = [...known].sort();","atom":"a0","author":"init","version":0},{"n":779,"text":"\t\t}","atom":"a0","author":"init","version":0},{"n":780,"text":"\t\treturn this.#knownList;","atom":"a0","author":"init","version":0},{"n":781,"text":"\t}","atom":"a0","author":"init","version":0},{"n":782,"text":"","atom":"a0","author":"init","version":0},{"n":783,"text":"\t/** Files with at least one visible line, sorted. */","atom":"a0","author":"init","version":0},{"n":784,"text":"\tpaths(): string[] {","atom":"a0","author":"init","version":0},{"n":785,"text":"\t\tif (this.#stable) {","atom":"a1039","author":"codex-capacity-chair","version":118},{"n":786,"text":"\t\t\tconst paths: string[] = [];","atom":"a1039","author":"codex-capacity-chair","version":118},{"n":787,"text":"\t\t\tfor (const path of this.graph.knownFiles()) {","atom":"a1039","author":"codex-capacity-chair","version":118},{"n":788,"text":"\t\t\t\tif (this.hasFile(path)) paths.push(path);","atom":"a1039","author":"codex-capacity-chair","version":118},{"n":789,"text":"\t\t\t\telse this.#files.delete(path);","atom":"a1039","author":"codex-capacity-chair","version":118},{"n":790,"text":"\t\t\t}","atom":"a1039","author":"codex-capacity-chair","version":118},{"n":791,"text":"\t\t\treturn paths.sort();","atom":"a1039","author":"codex-capacity-chair","version":118},{"n":792,"text":"\t\t}","atom":"a1039","author":"codex-capacity-chair","version":118},{"n":793,"text":"\t\treturn this.#known.filter((p) => this.hasFile(p));","atom":"a0","author":"init","version":0},{"n":794,"text":"\t}","atom":"a0","author":"init","version":0},{"n":795,"text":"","atom":"a0","author":"init","version":0},{"n":796,"text":"\t/** Every file the set has ever written a line in, including fully deleted ones. */","atom":"a0","author":"init","version":0},{"n":797,"text":"\tknownPaths(): string[] {","atom":"a0","author":"init","version":0},{"n":798,"text":"\t\treturn [...this.#known];","atom":"a0","author":"init","version":0},{"n":799,"text":"\t}","atom":"a2319","author":"capacity","version":207},{"n":800,"text":"","atom":"a2319","author":"capacity","version":207},{"n":801,"text":"\t/** The file line n sits in, in this set: fileOf by the line's number, with no lookup of its id. */","atom":"a2350","author":"capacity","version":212},{"n":802,"text":"\tfileOfNumber(n: number): string {","atom":"a2350","author":"capacity","version":212},{"n":803,"text":"\t\treturn this.#fileOfN(n);","atom":"a2350","author":"capacity","version":212},{"n":804,"text":"\t}","atom":"a2350","author":"capacity","version":212},{"n":805,"text":"","atom":"a2350","author":"capacity","version":212},{"n":806,"text":"\t/** How many visible lines a file has. */","atom":"a2319","author":"capacity","version":207},{"n":807,"text":"\tvisibleCount(path: string): number {","atom":"a2319","author":"capacity","version":207},{"n":808,"text":"\t\treturn this.#file(path).vis.length;","atom":"a2319","author":"capacity","version":207},{"n":809,"text":"\t}","atom":"a0","author":"init","version":0},{"n":810,"text":"","atom":"a0","author":"init","version":0},{"n":811,"text":"\t/** Whether the file exists in this projection (has a visible line). */","atom":"a0","author":"init","version":0},{"n":812,"text":"\thasFile(path: string): boolean {","atom":"a0","author":"init","version":0},{"n":813,"text":"\t\tconst attrs = this.attrs(path);","atom":"a1152","author":"codex-capacity-chair","version":140},{"n":814,"text":"\t\treturn attrs.exists || attrs.link !== null || attrs.blob !== null || this.#file(path).vis.length > 0;","atom":"a1152","author":"codex-capacity-chair","version":140},{"n":815,"text":"\t}","atom":"a0","author":"init","version":0},{"n":816,"text":"","atom":"a0","author":"init","version":0},{"n":817,"text":"\t/** A file's attributes: kept while empty, executable, a link's target. */","atom":"a0","author":"init","version":0},{"n":818,"text":"\tattrs(path: string): FileAttrs {","atom":"a0","author":"init","version":0},{"n":819,"text":"\t\treturn this.#files.get(path)?.attrs ?? this.#attributes(path);","atom":"a1152","author":"codex-capacity-chair","version":140},{"n":820,"text":"\t}","atom":"a0","author":"init","version":0},{"n":821,"text":"","atom":"a0","author":"init","version":0},{"n":822,"text":"\t/** The projected text of a file (\"\" if it has no visible lines). */","atom":"a0","author":"init","version":0},{"n":823,"text":"\ttext(path: string): string {","atom":"a0","author":"init","version":0},{"n":824,"text":"\t\tif (this.#textCache?.path === path) return this.#textCache.text;","atom":"a0","author":"init","version":0},{"n":825,"text":"\t\tconst { vis, visText } = this.#file(path);","atom":"a2312","author":"capacity","version":206},{"n":826,"text":"\t\tconst lines: string[] = new Array(vis.length);","atom":"a0","author":"init","version":0},{"n":827,"text":"\t\tfor (let i = 0; i < vis.length; i++) lines[i] = visText?.[i] ?? this.graph.textOf(vis[i]!);","atom":"a2312","author":"capacity","version":206},{"n":828,"text":"\t\tconst text = joinLines(lines);","atom":"a0","author":"init","version":0},{"n":829,"text":"\t\tthis.#textCache = { path, text };","atom":"a0","author":"init","version":0},{"n":830,"text":"\t\treturn text;","atom":"a0","author":"init","version":0},{"n":831,"text":"\t}","atom":"a0","author":"init","version":0},{"n":832,"text":"","atom":"a0","author":"init","version":0},{"n":833,"text":"\t/** Whether a file reads the same here and in `other` (of the same graph), compared line by line without joining either (#46). */","atom":"a0","author":"init","version":0},{"n":834,"text":"\tsameText(path: string, other: ReadView): boolean {","atom":"a1327","author":"codex-capacity-chair","version":143},{"n":835,"text":"\t\tif (!(other instanceof View)) {","atom":"a1327","author":"codex-capacity-chair","version":143},{"n":836,"text":"\t\t\tconst a = this.lines(path),","atom":"a1327","author":"codex-capacity-chair","version":143},{"n":837,"text":"\t\t\t\tb = other.lines(path);","atom":"a1327","author":"codex-capacity-chair","version":143},{"n":838,"text":"\t\t\treturn a.length === b.length && a.every((line, i) => line.text === b[i]!.text);","atom":"a1327","author":"codex-capacity-chair","version":143},{"n":839,"text":"\t\t}","atom":"a1327","author":"codex-capacity-chair","version":143},{"n":840,"text":"\t\tconst a = this.#file(path).vis;","atom":"a0","author":"init","version":0},{"n":841,"text":"\t\tconst b = other.#file(path).vis;","atom":"a0","author":"init","version":0},{"n":842,"text":"\t\tif (a.length !== b.length) return false;","atom":"a0","author":"init","version":0},{"n":843,"text":"\t\tfor (let i = 0; i < a.length; i++)","atom":"a0","author":"init","version":0},{"n":844,"text":"\t\t\tif (a[i] !== b[i] && this.graph.textOf(a[i]!) !== this.graph.textOf(b[i]!)) return false;","atom":"a0","author":"init","version":0},{"n":845,"text":"\t\treturn true;","atom":"a0","author":"init","version":0},{"n":846,"text":"\t}","atom":"a1890","author":"codex-capacity-chair","version":175},{"n":847,"text":"","atom":"a1890","author":"codex-capacity-chair","version":175},{"n":848,"text":"\t*lineChunks(path: string): IterableIterator<() => Iterable<string>> {","atom":"a1890","author":"codex-capacity-chair","version":175},{"n":849,"text":"\t\tfor (const n of this.#file(path).vis) yield () => this.graph.textChunks(n);","atom":"a1890","author":"codex-capacity-chair","version":175},{"n":850,"text":"\t}","atom":"a1890","author":"codex-capacity-chair","version":175},{"n":851,"text":"","atom":"a1890","author":"codex-capacity-chair","version":175},{"n":852,"text":"\t/** Visible lines without retaining their text in the view cache. */","atom":"a1890","author":"codex-capacity-chair","version":175},{"n":853,"text":"\t*visibleLines(path: string): IterableIterator<VisibleLine> {","atom":"a1890","author":"codex-capacity-chair","version":175},{"n":854,"text":"\t\tconst graph = this.graph;","atom":"a1890","author":"codex-capacity-chair","version":175},{"n":855,"text":"\t\tfor (const n of this.#file(path).vis)","atom":"a1890","author":"codex-capacity-chair","version":175},{"n":856,"text":"\t\t\tyield { id: graph.lineIdOf(n), text: graph.textOf(n), atom: graph.idOfSeq(graph.writerSeqOf(n)) };","atom":"a1890","author":"codex-capacity-chair","version":175},{"n":857,"text":"\t}","atom":"a1890","author":"codex-capacity-chair","version":175},{"n":858,"text":"","atom":"a1890","author":"codex-capacity-chair","version":175},{"n":859,"text":"\t/** Atom-building line handles; text is loaded only when requested. */","atom":"a1890","author":"codex-capacity-chair","version":175},{"n":860,"text":"\tbuildLines(path: string): readonly VisibleLine[] {","atom":"a1890","author":"codex-capacity-chair","version":175},{"n":861,"text":"\t\tconst graph = this.graph;","atom":"a1890","author":"codex-capacity-chair","version":175},{"n":862,"text":"\t\tconst vis = this.#file(path).vis;","atom":"a1890","author":"codex-capacity-chair","version":175},{"n":863,"text":"\t\tconst lines: VisibleLine[] = new Array(vis.length);","atom":"a1890","author":"codex-capacity-chair","version":175},{"n":864,"text":"\t\tfor (let i = 0; i < vis.length; i++) {","atom":"a1890","author":"codex-capacity-chair","version":175},{"n":865,"text":"\t\t\tconst n = vis[i]!;","atom":"a1890","author":"codex-capacity-chair","version":175},{"n":866,"text":"\t\t\tlines[i] = {","atom":"a1890","author":"codex-capacity-chair","version":175},{"n":867,"text":"\t\t\t\tid: graph.lineIdOf(n),","atom":"a1890","author":"codex-capacity-chair","version":175},{"n":868,"text":"\t\t\t\ttextChunks: () => graph.textChunks(n),","atom":"a1890","author":"codex-capacity-chair","version":175},{"n":869,"text":"\t\t\t\tget text() {","atom":"a1890","author":"codex-capacity-chair","version":175},{"n":870,"text":"\t\t\t\t\treturn graph.textOf(n);","atom":"a1890","author":"codex-capacity-chair","version":175},{"n":871,"text":"\t\t\t\t},","atom":"a1890","author":"codex-capacity-chair","version":175},{"n":872,"text":"\t\t\t\tatom: graph.idOfSeq(graph.writerSeqOf(n)),","atom":"a1890","author":"codex-capacity-chair","version":175},{"n":873,"text":"\t\t\t};","atom":"a1890","author":"codex-capacity-chair","version":175},{"n":874,"text":"\t\t}","atom":"a1890","author":"codex-capacity-chair","version":175},{"n":875,"text":"\t\treturn lines;","atom":"a1890","author":"codex-capacity-chair","version":175},{"n":876,"text":"\t}","atom":"a0","author":"init","version":0},{"n":877,"text":"","atom":"a0","author":"init","version":0},{"n":878,"text":"\t/** Visible lines with their ids. */","atom":"a0","author":"init","version":0},{"n":879,"text":"\tlines(path: string): readonly VisibleLine[] {","atom":"a0","author":"init","version":0},{"n":880,"text":"\t\tif (this.#linesCache?.path === path) return this.#linesCache.lines;","atom":"a0","author":"init","version":0},{"n":881,"text":"\t\tconst graph = this.graph;","atom":"a0","author":"init","version":0},{"n":882,"text":"\t\tconst vis = this.#file(path).vis;","atom":"a0","author":"init","version":0},{"n":883,"text":"\t\tconst lines: VisibleLine[] = new Array(vis.length);","atom":"a0","author":"init","version":0},{"n":884,"text":"\t\tfor (let i = 0; i < vis.length; i++) {","atom":"a0","author":"init","version":0},{"n":885,"text":"\t\t\tconst n = vis[i]!;","atom":"a0","author":"init","version":0},{"n":886,"text":"\t\t\tlines[i] = { id: graph.lineIdOf(n), text: graph.textOf(n), atom: graph.idOfSeq(graph.writerSeqOf(n)) };","atom":"a0","author":"init","version":0},{"n":887,"text":"\t\t}","atom":"a0","author":"init","version":0},{"n":888,"text":"\t\tthis.#linesCache = { path, lines };","atom":"a0","author":"init","version":0},{"n":889,"text":"\t\treturn lines;","atom":"a0","author":"init","version":0},{"n":890,"text":"\t}","atom":"a0","author":"init","version":0},{"n":891,"text":"","atom":"a0","author":"init","version":0},{"n":892,"text":"\t/** The full linearized sequence of a file, tombstones included. */","atom":"a0","author":"init","version":0},{"n":893,"text":"\tsequence(path: string): readonly SeqLine[] {","atom":"a0","author":"init","version":0},{"n":894,"text":"\t\tif (this.#seqCache?.path === path) return this.#seqCache.seq;","atom":"a0","author":"init","version":0},{"n":895,"text":"\t\tconst graph = this.graph;","atom":"a0","author":"init","version":0},{"n":896,"text":"\t\tconst f = this.#file(path, true);","atom":"a1006","author":"codex-capacity-chair","version":110},{"n":897,"text":"\t\tconst out: SeqLine[] = new Array(f.seq.length);","atom":"a0","author":"init","version":0},{"n":898,"text":"\t\tfor (let i = 0; i < f.seq.length; i++) {","atom":"a0","author":"init","version":0},{"n":899,"text":"\t\t\tconst n = f.seq[i]!;","atom":"a0","author":"init","version":0},{"n":900,"text":"\t\t\tconst by = f.deletedBy.get(i);","atom":"a0","author":"init","version":0},{"n":901,"text":"\t\t\tout[i] = {","atom":"a0","author":"init","version":0},{"n":902,"text":"\t\t\t\tid: graph.lineIdOf(n),","atom":"a0","author":"init","version":0},{"n":903,"text":"\t\t\t\ttext: graph.textOf(n),","atom":"a0","author":"init","version":0},{"n":904,"text":"\t\t\t\tatom: graph.idOfSeq(graph.writerSeqOf(n)),","atom":"a0","author":"init","version":0},{"n":905,"text":"\t\t\t\tdeletedBy: by ? by.map((s) => graph.idOfSeq(s)) : NONE,","atom":"a0","author":"init","version":0},{"n":906,"text":"\t\t\t\tvisible: by === undefined,","atom":"a0","author":"init","version":0},{"n":907,"text":"\t\t\t};","atom":"a0","author":"init","version":0},{"n":908,"text":"\t\t}","atom":"a0","author":"init","version":0},{"n":909,"text":"\t\tthis.#seqCache = { path, seq: out };","atom":"a0","author":"init","version":0},{"n":910,"text":"\t\treturn out;","atom":"a0","author":"init","version":0},{"n":911,"text":"\t}","atom":"a0","author":"init","version":0},{"n":912,"text":"","atom":"a0","author":"init","version":0},{"n":913,"text":"\t/** Two visible neighbours without retaining the file's historical sequence. */","atom":"a1143","author":"codex-capacity-chair","version":138},{"n":914,"text":"\tvisibleNeighbours(path: string, line: LineId): LineId[] {","atom":"a1143","author":"codex-capacity-chair","version":138},{"n":915,"text":"\t\tconst graph = this.graph;","atom":"a1143","author":"codex-capacity-chair","version":138},{"n":916,"text":"\t\tconst target = graph.lineN(line);","atom":"a1143","author":"codex-capacity-chair","version":138},{"n":917,"text":"\t\tconst start = graph.startCodeOf(path);","atom":"a1143","author":"codex-capacity-chair","version":138},{"n":918,"text":"\t\tif (target < 0 || start === undefined) return [];","atom":"a1143","author":"codex-capacity-chair","version":138},{"n":919,"text":"\t\tconst scan = (nodes: Iterable<number>): LineId[] => {","atom":"a1143","author":"codex-capacity-chair","version":138},{"n":920,"text":"\t\t\tlet previous: LineId | undefined;","atom":"a1143","author":"codex-capacity-chair","version":138},{"n":921,"text":"\t\t\tlet found = false;","atom":"a1143","author":"codex-capacity-chair","version":138},{"n":922,"text":"\t\t\tfor (const n of nodes) {","atom":"a1143","author":"codex-capacity-chair","version":138},{"n":923,"text":"\t\t\t\tif (n === target) {","atom":"a1143","author":"codex-capacity-chair","version":138},{"n":924,"text":"\t\t\t\t\tfound = true;","atom":"a1143","author":"codex-capacity-chair","version":138},{"n":925,"text":"\t\t\t\t\tcontinue;","atom":"a1143","author":"codex-capacity-chair","version":138},{"n":926,"text":"\t\t\t\t}","atom":"a1143","author":"codex-capacity-chair","version":138},{"n":927,"text":"\t\t\t\tlet deleted = false;","atom":"a1143","author":"codex-capacity-chair","version":138},{"n":928,"text":"\t\t\t\tfor (const seq of graph.eachDeleterSeqOf(n))","atom":"a1143","author":"codex-capacity-chair","version":138},{"n":929,"text":"\t\t\t\t\tif (this.#has(seq)) {","atom":"a1143","author":"codex-capacity-chair","version":138},{"n":930,"text":"\t\t\t\t\t\tdeleted = true;","atom":"a1143","author":"codex-capacity-chair","version":138},{"n":931,"text":"\t\t\t\t\t\tbreak;","atom":"a1143","author":"codex-capacity-chair","version":138},{"n":932,"text":"\t\t\t\t\t}","atom":"a1143","author":"codex-capacity-chair","version":138},{"n":933,"text":"\t\t\t\tif (deleted) continue;","atom":"a1143","author":"codex-capacity-chair","version":138},{"n":934,"text":"\t\t\t\tconst id = graph.lineIdOf(n);","atom":"a1143","author":"codex-capacity-chair","version":138},{"n":935,"text":"\t\t\t\tif (found) return previous === undefined ? [id] : [previous, id];","atom":"a1143","author":"codex-capacity-chair","version":138},{"n":936,"text":"\t\t\t\tprevious = id;","atom":"a1143","author":"codex-capacity-chair","version":138},{"n":937,"text":"\t\t\t}","atom":"a1143","author":"codex-capacity-chair","version":138},{"n":938,"text":"\t\t\treturn found && previous !== undefined ? [previous] : [];","atom":"a1143","author":"codex-capacity-chair","version":138},{"n":939,"text":"\t\t};","atom":"a1143","author":"codex-capacity-chair","version":138},{"n":940,"text":"\t\tif (this.#scratchMoves())","atom":"a2302","author":"capacity","version":205},{"n":941,"text":"\t\t\treturn graph.withProjectionScratch((scratch) =>","atom":"a1143","author":"codex-capacity-chair","version":138},{"n":942,"text":"\t\t\t\tscan(scratchLayoutNodes(graph, (id) => this.#has(graph.atom(id).seq), scratch, graph.nodeOf(start))),","atom":"a1143","author":"codex-capacity-chair","version":138},{"n":943,"text":"\t\t\t);","atom":"a1143","author":"codex-capacity-chair","version":138},{"n":944,"text":"\t\treturn scan(this.#layoutNodes(start));","atom":"a1143","author":"codex-capacity-chair","version":138},{"n":945,"text":"\t}","atom":"a1143","author":"codex-capacity-chair","version":138},{"n":946,"text":"","atom":"a1143","author":"codex-capacity-chair","version":138},{"n":947,"text":"\t/** Index of a line in `sequence(path)`, or -1. */","atom":"a0","author":"init","version":0},{"n":948,"text":"\tsequenceIndex(path: string, line: LineId): number {","atom":"a0","author":"init","version":0},{"n":949,"text":"\t\tconst f = this.#file(path, true);","atom":"a1006","author":"codex-capacity-chair","version":110},{"n":950,"text":"\t\tif (!f.seqIndex) {","atom":"a0","author":"init","version":0},{"n":951,"text":"\t\t\tf.seqIndex = new Map();","atom":"a0","author":"init","version":0},{"n":952,"text":"\t\t\tfor (let i = 0; i < f.seq.length; i++) f.seqIndex.set(f.seq[i]!, i);","atom":"a0","author":"init","version":0},{"n":953,"text":"\t\t}","atom":"a0","author":"init","version":0},{"n":954,"text":"\t\treturn f.seqIndex.get(this.graph.lineN(line)) ?? -1;","atom":"a0","author":"init","version":0},{"n":955,"text":"\t}","atom":"a0","author":"init","version":0},{"n":956,"text":"","atom":"a0","author":"init","version":0},{"n":957,"text":"\t/** Index of a line in `lines(path)` (0-based visible line number), or -1 if not visible. */","atom":"a0","author":"init","version":0},{"n":958,"text":"\tlineNumber(path: string, line: LineId): number {","atom":"a0","author":"init","version":0},{"n":959,"text":"\t\treturn this.lineNumberOf(path, this.graph.lineN(line));","atom":"a2350","author":"capacity","version":212},{"n":960,"text":"\t}","atom":"a2350","author":"capacity","version":212},{"n":961,"text":"","atom":"a2350","author":"capacity","version":212},{"n":962,"text":"\t/** lineNumber by the line's number, with no lookup of its id. */","atom":"a2350","author":"capacity","version":212},{"n":963,"text":"\tlineNumberOf(path: string, n: number): number {","atom":"a2350","author":"capacity","version":212},{"n":964,"text":"\t\tconst f = this.#file(path);","atom":"a0","author":"init","version":0},{"n":965,"text":"\t\tif (!f.visIndex) {","atom":"a0","author":"init","version":0},{"n":966,"text":"\t\t\tf.visIndex = new Map();","atom":"a0","author":"init","version":0},{"n":967,"text":"\t\t\tfor (let i = 0; i < f.vis.length; i++) f.visIndex.set(f.vis[i]!, i);","atom":"a0","author":"init","version":0},{"n":968,"text":"\t\t}","atom":"a0","author":"init","version":0},{"n":969,"text":"\t\treturn f.visIndex.get(n) ?? -1;","atom":"a2350","author":"capacity","version":212},{"n":970,"text":"\t}","atom":"a2350","author":"capacity","version":212},{"n":971,"text":"","atom":"a2350","author":"capacity","version":212},{"n":972,"text":"\t/** The seq of the atom that wrote each visible line, in order: lines() without ids or text. */","atom":"a2350","author":"capacity","version":212},{"n":973,"text":"\tvisibleWriters(path: string): number[] {","atom":"a2350","author":"capacity","version":212},{"n":974,"text":"\t\tconst graph = this.graph;","atom":"a2350","author":"capacity","version":212},{"n":975,"text":"\t\treturn Array.from(this.#file(path).vis, (n) => graph.writerSeqOf(n));","atom":"a2350","author":"capacity","version":212},{"n":976,"text":"\t}","atom":"a0","author":"init","version":0},{"n":977,"text":"","atom":"a0","author":"init","version":0},{"n":978,"text":"\t/** All projected text files, path -> text, in path order. Binary files are in `blobs()`. */","atom":"a0","author":"init","version":0},{"n":979,"text":"\tfiles(): Record<string, string> {","atom":"a0","author":"init","version":0},{"n":980,"text":"\t\tconst out: Record<string, string> = {};","atom":"a0","author":"init","version":0},{"n":981,"text":"\t\tfor (const path of this.paths()) if (this.#file(path).attrs.blob === null) out[path] = this.text(path);","atom":"a0","author":"init","version":0},{"n":982,"text":"\t\treturn out;","atom":"a0","author":"init","version":0},{"n":983,"text":"\t}","atom":"a0","author":"init","version":0},{"n":984,"text":"","atom":"a0","author":"init","version":0},{"n":985,"text":"\t/** Binary files, path -> the SHA-256 of their bytes, in path order. */","atom":"a0","author":"init","version":0},{"n":986,"text":"\tblobs(): Record<string, string> {","atom":"a0","author":"init","version":0},{"n":987,"text":"\t\tconst out: Record<string, string> = {};","atom":"a0","author":"init","version":0},{"n":988,"text":"\t\tfor (const path of this.paths()) {","atom":"a0","author":"init","version":0},{"n":989,"text":"\t\t\tconst blob = this.#file(path).attrs.blob;","atom":"a0","author":"init","version":0},{"n":990,"text":"\t\t\tif (blob !== null) out[path] = blob;","atom":"a0","author":"init","version":0},{"n":991,"text":"\t\t}","atom":"a0","author":"init","version":0},{"n":992,"text":"\t\treturn out;","atom":"a0","author":"init","version":0},{"n":993,"text":"\t}","atom":"a0","author":"init","version":0},{"n":994,"text":"","atom":"a0","author":"init","version":0},{"n":995,"text":"\t/**","atom":"a0","author":"init","version":0},{"n":996,"text":"\t * About how many bytes of retained state this view costs (#46). This uses","atom":"a934","author":"codex-capacity-policy","version":103},{"n":997,"text":"\t * approximate ownership costs for containers and wrappers, not V8 heap","atom":"a934","author":"codex-capacity-policy","version":103},{"n":998,"text":"\t * measurements. Graph-owned strings and records count only as references.","atom":"a934","author":"codex-capacity-policy","version":103},{"n":999,"text":"\t * This method only inspects already-created state: it does not lay out files,","atom":"a934","author":"codex-capacity-policy","version":103},{"n":1000,"text":"\t * populate lazy caches, enumerate the graph, or count temporary traversal","atom":"a934","author":"codex-capacity-policy","version":103},{"n":1001,"text":"\t * containers and shared empty singleton payloads as retained view state.","atom":"a934","author":"codex-capacity-policy","version":103},{"n":1002,"text":"\t */","atom":"a0","author":"init","version":0},{"n":1003,"text":"\tweight(): number {","atom":"a0","author":"init","version":0},{"n":1004,"text":"\t\tlet n = this.#in.byteLength;","atom":"a934","author":"codex-capacity-policy","version":103},{"n":1005,"text":"\t\tn += 2 * ARRAY_HEADER_BYTES + this.#membershipSeq.byteLength + this.#membershipValue.byteLength;","atom":"a1030","author":"codex-capacity-chair","version":116},{"n":1006,"text":"\t\tif (this.#movers) n += ARRAY_HEADER_BYTES + REFERENCE_BYTES * this.#movers.length;","atom":"a1061","author":"codex-capacity-chair","version":123},{"n":1007,"text":"\t\tn += MAP_HEADER_BYTES; // #files exists from construction.","atom":"a934","author":"codex-capacity-policy","version":103},{"n":1008,"text":"\t\tif (this.#stable) n += this.#stable.retainedBytes;","atom":"a998","author":"codex-capacity-chair","version":109},{"n":1009,"text":"\t\telse if (this.#set) n += OBJECT_BYTES + SET_ENTRY_BYTES * this.#set.size;","atom":"a998","author":"codex-capacity-chair","version":109},{"n":1010,"text":"\t\tif (this.#knownList) n += ARRAY_HEADER_BYTES + REFERENCE_BYTES * this.#knownList.length;","atom":"a934","author":"codex-capacity-policy","version":103},{"n":1011,"text":"\t\tif (this.#relocs) n += MAP_HEADER_BYTES + MAP_ENTRY_BYTES * this.#relocs.size;","atom":"a934","author":"codex-capacity-policy","version":103},{"n":1012,"text":"\t\tif (this.#relocsN) n += MAP_HEADER_BYTES + (MAP_ENTRY_BYTES + OBJECT_BYTES) * this.#relocsN.size;","atom":"a934","author":"codex-capacity-policy","version":103},{"n":1013,"text":"\t\tn += MAP_ENTRY_BYTES * this.#picked.size;","atom":"a2377","author":"capacity","version":216},{"n":1014,"text":"\t\tfor (const f of this.#files.values()) {","atom":"a934","author":"codex-capacity-policy","version":103},{"n":1015,"text":"\t\t\tn += MAP_ENTRY_BYTES;","atom":"a934","author":"codex-capacity-policy","version":103},{"n":1016,"text":"\t\t\tif (f !== NO_FILE) {","atom":"a934","author":"codex-capacity-policy","version":103},{"n":1017,"text":"\t\t\t\t// FileState and FileAttrs are per laid-out file; typed-array","atom":"a934","author":"codex-capacity-policy","version":103},{"n":1018,"text":"\t\t\t\t// headers are separate from their payload byte lengths below.","atom":"a934","author":"codex-capacity-policy","version":103},{"n":1019,"text":"\t\t\t\tn += OBJECT_BYTES + OBJECT_BYTES + 2 * ARRAY_HEADER_BYTES;","atom":"a934","author":"codex-capacity-policy","version":103},{"n":1020,"text":"\t\t\t\tn += f.seq.byteLength + f.vis.byteLength;","atom":"a934","author":"codex-capacity-policy","version":103},{"n":1021,"text":"\t\t\t\tif (f.visText) for (const text of f.visText) n += REFERENCE_BYTES + 2 * (text?.length ?? 0);","atom":"a2312","author":"capacity","version":206},{"n":1022,"text":"\t\t\t\tn += MAP_HEADER_BYTES + (MAP_ENTRY_BYTES + ARRAY_HEADER_BYTES) * f.deletedBy.size;","atom":"a934","author":"codex-capacity-policy","version":103},{"n":1023,"text":"\t\t\t\tfor (const deleters of f.deletedBy.values()) n += REFERENCE_BYTES * deleters.length;","atom":"a934","author":"codex-capacity-policy","version":103},{"n":1024,"text":"\t\t\t\tif (f.seqIndex) n += MAP_HEADER_BYTES + MAP_ENTRY_BYTES * f.seqIndex.size;","atom":"a934","author":"codex-capacity-policy","version":103},{"n":1025,"text":"\t\t\t\tif (f.visIndex) n += MAP_HEADER_BYTES + MAP_ENTRY_BYTES * f.visIndex.size;","atom":"a934","author":"codex-capacity-policy","version":103},{"n":1026,"text":"\t\t\t}","atom":"a934","author":"codex-capacity-policy","version":103},{"n":1027,"text":"\t\t}","atom":"a934","author":"codex-capacity-policy","version":103},{"n":1028,"text":"\t\tif (this.#linesCache)","atom":"a934","author":"codex-capacity-policy","version":103},{"n":1029,"text":"\t\t\tn += OBJECT_BYTES + REFERENCE_BYTES + ARRAY_HEADER_BYTES + 100 * this.#linesCache.lines.length;","atom":"a934","author":"codex-capacity-policy","version":103},{"n":1030,"text":"\t\tif (this.#seqCache) {","atom":"a934","author":"codex-capacity-policy","version":103},{"n":1031,"text":"\t\t\tn += OBJECT_BYTES + REFERENCE_BYTES + ARRAY_HEADER_BYTES + 120 * this.#seqCache.seq.length;","atom":"a934","author":"codex-capacity-policy","version":103},{"n":1032,"text":"\t\t\tfor (const line of this.#seqCache.seq)","atom":"a938","author":"codex-capacity-policy","version":103},{"n":1033,"text":"\t\t\t\tif (line.deletedBy !== NONE) n += ARRAY_HEADER_BYTES + REFERENCE_BYTES * line.deletedBy.length;","atom":"a938","author":"codex-capacity-policy","version":103},{"n":1034,"text":"\t\t}","atom":"a934","author":"codex-capacity-policy","version":103},{"n":1035,"text":"\t\tif (this.#textCache) n += OBJECT_BYTES + REFERENCE_BYTES + ARRAY_HEADER_BYTES + 2 * this.#textCache.text.length;","atom":"a938","author":"codex-capacity-policy","version":103},{"n":1036,"text":"\t\treturn n;","atom":"a0","author":"init","version":0},{"n":1037,"text":"\t}","atom":"a0","author":"init","version":0},{"n":1038,"text":"","atom":"a0","author":"init","version":0},{"n":1039,"text":"\t#file(path: string, complete = false): FileState {","atom":"a1006","author":"codex-capacity-chair","version":110},{"n":1040,"text":"\t\tlet state = this.#files.get(path);","atom":"a0","author":"init","version":0},{"n":1041,"text":"\t\tif (!state || (complete && !state.complete)) {","atom":"a1006","author":"codex-capacity-chair","version":110},{"n":1042,"text":"\t\t\tstate = this.graph.hasAtomsIn(path) ? this.#layout(path, complete) : NO_FILE;","atom":"a1045","author":"codex-capacity-chair","version":119},{"n":1043,"text":"\t\t\tthis.#files.set(path, state);","atom":"a0","author":"init","version":0},{"n":1044,"text":"\t\t}","atom":"a0","author":"init","version":0},{"n":1045,"text":"\t\treturn state;","atom":"a0","author":"init","version":0},{"n":1046,"text":"\t}","atom":"a0","author":"init","version":0},{"n":1047,"text":"}","atom":"a0","author":"init","version":0},{"n":1048,"text":"","atom":"a0","author":"init","version":0},{"n":1049,"text":"/** The files of a closed set, path -> text. */","atom":"a0","author":"init","version":0},{"n":1050,"text":"export function project(graph: Graph, set: Iterable<AtomId>): Record<string, string> {","atom":"a0","author":"init","version":0},{"n":1051,"text":"\treturn new View(graph, set).files();","atom":"a0","author":"init","version":0},{"n":1052,"text":"}","atom":"a0","author":"init","version":0},{"n":1053,"text":"","atom":"a0","author":"init","version":0},{"n":1054,"text":"/** Where a node sits in a file's sequence: the index just after it (0 for a start node). */","atom":"a0","author":"init","version":0},{"n":1055,"text":"export function indexAfter(view: Pick<ReadView, \"sequenceIndex\">, path: string, node: NodeId): number {","atom":"a1327","author":"codex-capacity-chair","version":143},{"n":1056,"text":"\tif (isStartNode(node)) return 0;","atom":"a0","author":"init","version":0},{"n":1057,"text":"\tconst i = view.sequenceIndex(path, node);","atom":"a0","author":"init","version":0},{"n":1058,"text":"\tif (i < 0) throw new EngineError(\"not-in-view\", `line ${node} is not in ${path} in this view`);","atom":"a0","author":"init","version":0},{"n":1059,"text":"\treturn i + 1;","atom":"a0","author":"init","version":0},{"n":1060,"text":"}","atom":"a0","author":"init","version":0}],"atoms":[{"atom":"a0","author":"init","message":"Start the project","time":1791506895507,"timeIso":"2026-10-09T00:48:15.507Z","publish":{"draft":null,"version":0,"agent":"init","message":"Start the project","time":1791506895507,"timeIso":"2026-10-09T00:48:15.507Z"}},{"atom":"a934","author":"codex-capacity-policy","message":"","time":1791757356684,"timeIso":"2026-10-11T22:22:36.684Z","publish":{"draft":null,"version":103,"agent":"codex-capacity-policy","message":"Test deterministic replay and account view cache weight","time":1791758093484,"timeIso":"2026-10-11T22:34:53.484Z"}},{"atom":"a938","author":"codex-capacity-policy","message":"","time":1791757780561,"timeIso":"2026-10-11T22:29:40.561Z","publish":{"draft":null,"version":103,"agent":"codex-capacity-policy","message":"Test deterministic replay and account view cache weight","time":1791758093484,"timeIso":"2026-10-11T22:34:53.484Z"}},{"atom":"a979","author":"codex-capacity-chair","message":"","time":1791824286794,"timeIso":"2026-10-12T16:58:06.794Z","publish":{"draft":null,"version":109,"agent":"codex-capacity-chair","message":"Add opt-in persistent writer state, checked reopen and bounded adoption","time":1791825459416,"timeIso":"2026-10-12T17:17:39.416Z"}},{"atom":"a998","author":"codex-capacity-chair","message":"","time":1791825397225,"timeIso":"2026-10-12T17:16:37.225Z","publish":{"draft":null,"version":109,"agent":"codex-capacity-chair","message":"Add opt-in persistent writer state, checked reopen and bounded adoption","time":1791825459416,"timeIso":"2026-10-12T17:17:39.416Z"}},{"atom":"a1006","author":"codex-capacity-chair","message":"","time":1791826635046,"timeIso":"2026-10-12T17:37:15.046Z","publish":{"draft":null,"version":110,"agent":"codex-capacity-chair","message":"Keep current-file views and key scans from retaining historical state","time":1791826888785,"timeIso":"2026-10-12T17:41:28.785Z"}},{"atom":"a1030","author":"codex-capacity-chair","message":"","time":1791829993612,"timeIso":"2026-10-12T18:33:13.612Z","publish":{"draft":null,"version":116,"agent":"codex-capacity-chair","message":"Bound repeated indexed view membership lookups","time":1791830067862,"timeIso":"2026-10-12T18:34:27.862Z"}},{"atom":"a1039","author":"codex-capacity-chair","message":"","time":1791830965974,"timeIso":"2026-10-12T18:49:25.974Z","publish":{"draft":null,"version":118,"agent":"codex-capacity-chair","message":"Avoid retaining deleted historical paths in indexed current views","time":1791831208035,"timeIso":"2026-10-12T18:53:28.035Z"}},{"atom":"a1045","author":"codex-capacity-chair","message":"","time":1791832874791,"timeIso":"2026-10-12T19:21:14.791Z","publish":{"draft":null,"version":119,"agent":"codex-capacity-chair","message":"Page per-file atom indexes and stream current-view attribute scans","time":1791832938431,"timeIso":"2026-10-12T19:22:18.431Z"}},{"atom":"a1061","author":"codex-capacity-chair","message":"","time":1791835105494,"timeIso":"2026-10-12T19:58:25.494Z","publish":{"draft":null,"version":123,"agent":"codex-capacity-chair","message":"Stream mover history when opening persisted views","time":1791835165952,"timeIso":"2026-10-12T19:59:25.952Z"}},{"atom":"a1075","author":"codex-capacity-chair","message":"","time":1791837487244,"timeIso":"2026-10-12T20:38:07.244Z","publish":{"draft":null,"version":126,"agent":"codex-capacity-chair","message":"Identify suppressed relocation cycles across persistent reads","time":1791837654331,"timeIso":"2026-10-12T20:40:54.331Z"}},{"atom":"a1083","author":"codex-capacity-chair","message":"","time":1791838569201,"timeIso":"2026-10-12T20:56:09.201Z","publish":{"draft":null,"version":128,"agent":"codex-capacity-chair","message":"Page deletion history and short-circuit current visibility","time":1791838722988,"timeIso":"2026-10-12T20:58:42.988Z"}},{"atom":"a1091","author":"codex-capacity-chair","message":"","time":1791840276400,"timeIso":"2026-10-12T21:24:36.400Z","publish":{"draft":null,"version":130,"agent":"codex-capacity-chair","message":"Stream paged child history into layout filtering","time":1791840531495,"timeIso":"2026-10-12T21:28:51.495Z"}},{"atom":"a1105","author":"codex-capacity-chair","message":"","time":1791841517646,"timeIso":"2026-10-12T21:45:17.646Z","publish":{"draft":null,"version":131,"agent":"codex-capacity-chair","message":"Bound persisted no-move layout with ordered successor traversal","time":1791841517646,"timeIso":"2026-10-12T21:45:17.646Z"}},{"atom":"a1112","author":"codex-capacity-chair","message":"","time":1791842213961,"timeIso":"2026-10-12T21:56:53.961Z","publish":{"draft":null,"version":132,"agent":"codex-capacity-chair","message":"Bound persistent relocation projection memory with rollback-only scratch","time":1791842416230,"timeIso":"2026-10-12T22:00:16.230Z"}},{"atom":"a1114","author":"codex-capacity-chair","message":"","time":1791842283610,"timeIso":"2026-10-12T21:58:03.610Z","publish":{"draft":null,"version":132,"agent":"codex-capacity-chair","message":"Bound persistent relocation projection memory with rollback-only scratch","time":1791842416230,"timeIso":"2026-10-12T22:00:16.230Z"}},{"atom":"a1143","author":"codex-capacity-chair","message":"","time":1791844562011,"timeIso":"2026-10-12T22:36:02.011Z","publish":{"draft":null,"version":138,"agent":"codex-capacity-chair","message":"Find reason-warning neighbors without materializing file history","time":1791844690202,"timeIso":"2026-10-12T22:38:10.202Z"}},{"atom":"a1152","author":"codex-capacity-chair","message":"","time":1791845368566,"timeIso":"2026-10-12T22:49:28.566Z","publish":{"draft":null,"version":140,"agent":"codex-capacity-chair","message":"Avoid line projection for file attribute queries","time":1791845368566,"timeIso":"2026-10-12T22:49:28.566Z"}},{"atom":"a1327","author":"codex-capacity-chair","message":"","time":1791854964720,"timeIso":"2026-10-13T01:29:24.720Z","publish":{"draft":null,"version":143,"agent":"codex-capacity-chair","message":"Add inactive disk projection provider and verified transactional readers (#16)","time":1791855032023,"timeIso":"2026-10-13T01:30:32.023Z"}},{"atom":"a1890","author":"codex-capacity-chair","message":"","time":1791967583646,"timeIso":"2026-10-14T08:46:23.646Z","publish":{"draft":null,"version":175,"agent":"codex-capacity-chair","message":"Reduce disk-backed record and publish allocations; reviewed in core ask 52 with parsed-code budget and exact aligned-line follow-ups. Keep disk-first activation off.","time":1791967673854,"timeIso":"2026-10-14T08:47:53.854Z"}},{"atom":"a2302","author":"capacity","message":"","time":1792030074826,"timeIso":"2026-10-15T02:07:54.826Z","publish":{"draft":null,"version":205,"agent":"capacity","message":"Disk-first reads stop walking the whole history (disk-first 2, stage 1; abso Capacity). Shared's closure is kept on disk per version (spaces.ts indexClosure): the atoms a version needs beyond what it published, as events like membership's, with drops handled; views and Project.#closed trust a set marked closed, and over a closed stored base only a draft's own atoms are walked. A view resolves its moves once in memory (up to MOVED_LINES_KEPT, 20,000 moved lines) instead of again on disk for every file it lays out, and finds lines moved under a node from them. Graph.eachChildN skips the per-line children lookup when the paged child counts say none. On game's export (writer adopted, lock held): shared() went from not finishing in 8 minutes to 9-13 s cold and 0.15-0.25 s warm, 291,000 queries to 57,000; pathsAt(head) 0.1-0.2 s.","time":1792030075730,"timeIso":"2026-10-15T02:07:55.730Z"}},{"atom":"a2312","author":"capacity","message":"","time":1792031851172,"timeIso":"2026-10-15T02:37:31.172Z","publish":{"draft":null,"version":206,"agent":"capacity","message":"Each file's line history packed (disk-first 2, lines by file; abso Capacity). A stored graph appends every line written in a file ([n, parent code, writer seq, k, replaces]) and its text, every delete of one of its lines, and every attribute set on it to that file's pages as atoms are added, a run at a time (storedLists appendAll). A view lays a file out from those pages in memory: membership checked once per atom, moves followed from the ones it already resolved, lines moved in from other files read from theirs. Same tree and order as before (packed-files.test.ts checks it against the in-memory graph through edits, deletes and moves). Graphs adopted before have no packs and lay out line by line as before; packFiles: false keeps that path for its tests. On game's export: first shared() 13 s to 2-3.6 s at 20,000 queries, warm 56-82 ms, pathsAt(head) 29-119 ms; files at a version 14 s to 3 s, compare 26 s to 11 s, a path's log 27 s to 4.5 s; every answer the harness finished matches Project.load.","time":1792031851789,"timeIso":"2026-10-15T02:37:31.789Z"}},{"atom":"a2319","author":"capacity","message":"","time":1792033263147,"timeIso":"2026-10-15T03:01:03.147Z","publish":{"draft":null,"version":207,"agent":"capacity","message":"Each shared version's changed files kept as it lands (disk-first 2; abso Capacity, version-files.ts). A version's files are decided from what it touched: visible lines in and out per file, their texts' balance, a running count of each file's visible lines for made and taken out, and mode and blob; a version with moves, drops or a closure change, or whose lines in and out have the same texts, is laid out as before. Views of consecutive versions share resolved moves and where lines sit (View.shareMoves). PathIndex.keep records them, into the shapes table when the host gives one. version-files.test.ts checks log, path logs and every show against the in-memory project through edits, new and removed files, same text put back, a move and a drop. On game's export all 27 harness answers now match Project.load: the log 70 ms (was over 30 s), a path's history 0.56 s (was over 30 s), the tree 3.1-3.4 s (was over 30 s); adoption about 85 s; heap 14.4 MB at most.","time":1792033264009,"timeIso":"2026-10-15T03:01:04.009Z"}},{"atom":"a2350","author":"capacity","message":"","time":1792036931359,"timeIso":"2026-10-15T04:02:11.359Z","publish":{"draft":null,"version":212,"agent":"capacity","message":"Draft reads on a stored writer (disk-first 2; abso Capacity): where, drafts, status and collisions on website's export.\n\n- where looks deleted lines up by number (graph.deletedNumbers, View.fileOfNumber, View.lineNumberOf). It takes the agent's view once instead of once per line, since each read weighed every cached view. It finds the draft's lines by writer (View.visibleWriters), with no text or id read per line.\n- Draft files (overlaps.ts) go by number the same way.\n- An agent's view takes its base's resolved moves when both hold the same atoms that move lines (View.shareMoves checks this).\n- Draft collisions:\n  - build the union view only when two drafts share a file;\n  - work out each agent's touched files and its \"shared now plus draft\" view once;\n  - find claimants among the drafts from the drafts' own keys (collisions.ts claimantsAmong) instead of walking each key's history;\n  - have the definition rule keep a draft's uses, and the newer work's definitions, across partners.\n- A stored list read in order reads its length once, not before every element.\n\ndraft-reads-stored.test.ts checks where and collisions against the in-memory project. It covers edits, a whole file deleted, a line collision, one name defined twice, and bases before and after a move. 135 of 136 related tests pass; none fail.\n\nOn website's export (1,387 entries) the answers match Project.load:\n- status: 17 s to 4.5 s\n- where: over 60 s to 8.8 s\n- drafts: 14 s to 5.3 s\n- collisions: over 60 s to 54 s, measured under the profiler before the last two changes","time":1792036932387,"timeIso":"2026-10-15T04:02:12.387Z"}},{"atom":"a2368","author":"capacity","message":"","time":1792039881156,"timeIso":"2026-10-15T04:51:21.156Z","publish":{"draft":null,"version":215,"agent":"capacity","message":"Moves resolved over the moved lines alone, and closure over a named draft's own atoms (disk-first 2; abso Capacity), for abso's status and drafts.\n\n- view.ts MoveSkeleton: once per graph, and extended as it grows, each mover's moved lines, each moved line's relocations, and for any node the nearest node above it that a move ever relocated (or its file's start), memoised up to 200,000 nodes. A view's relocations and its loop check now hop between moved lines instead of walking every moved line's file up to its start, and fileOf hops the same way. The per-view location memos are gone. On abso's export (1,687 moved lines, 972 movers), status went from 104 s to 41 s under the profiler; agent views no longer re-walk each base's moves.\n- project.ts #closed opens unions down to their closed parts. An agent in a named draft has the draft's atoms over a closed shared base, one union deeper than #closed looked, so it walked all of shared's atoms and their dependencies.\n\nTests: 97 of 97 across moves, relocation, projection-move-resolution, packed-files, view, drop, queued-moves, named-drafts, stored-closure, stored-membership, version-files, draft-reads-stored and writer storage. tsc clean.","time":1792039881566,"timeIso":"2026-10-15T04:51:21.566Z"}},{"atom":"a2377","author":"capacity","message":"","time":1792040841430,"timeIso":"2026-10-15T05:07:21.430Z","publish":{"draft":null,"version":216,"agent":"capacity","message":"Moves picked as walks reach them, and shared's file list from kept shapes (disk-first 2; abso Capacity), for abso's status, drafts and file list.\n\n- view.ts: a view picks a moved line's relocation only when a walk to find a line's file reaches that line. That is #relocations' own pick, right whenever the walk goes on to a file's start, since only lines on a loop have their relocation set aside; a walk that comes back to a line it passed resolves every move as before. shareMoves now takes the other view's moves only when this view first needs all of them, such as for a layout, so a view that only finds a few lines' files never resolves them. weight() counts the picks.\n- pathindex.ts keptPaths: shared's files at a version, folded from version 0 over each version's kept files made and taken out, with no file laid out. Only on a stored writer, and only when every version up to it has a kept row that describes it; otherwise the version is laid out as before. pathsAt uses it.\n\nOn abso's export (81,855 entries, 1,224 versions), one opened project, answers matching Project.load:\n- status: 104 s to 5.8 s (under the profiler)\n- drafts: over 60 s to 5.7 s\n- files at head: over 60 s to 1.2 s\n- files at 612: 54 s to 0.3 s\n\nversion-files.test.ts now also checks the file list at every version against the in-memory project. 124 of 124 related tests pass; tsc clean.","time":1792040841430,"timeIso":"2026-10-15T05:07:21.430Z"}},{"atom":"a2383","author":"capacity","message":"","time":1792041717296,"timeIso":"2026-10-15T05:21:57.296Z","publish":{"draft":null,"version":218,"agent":"capacity","message":"why on a stored writer (disk-first 2; abso Capacity).\n\n- A View reads atoms' numbers from their ids instead of reading each atom: building one from a plain set read every atom twice, and every mover once.\n- keptThrough, the settle a line was kept through, looks only among the atoms that write or take out the file's lines (graph.eachAtomIn), and lays out the file just before that settle from a lazy prefix of the view's set when that set is closed. It used to read every atom in the history and list all the earlier ones.\n- publishOf looks in shared before listing the named drafts, since listing them decodes each one's space.\n- view.ts loses #eachMover, unused since 215.\n\nOn abso's export, why for line 1 of issues/src/index.ts went from 41 s to 11 s on one opened writer, matching Project.load. The rest is trail's search for a moved line's origin among nearby changes.\n\nNamed tests: trail, named-drafts, files-reads, project, markers, version-files, draft-reads-stored, view, moves, drop (109 of 109); tsc and biome clean.","time":1792041717647,"timeIso":"2026-10-15T05:21:57.647Z"}},{"atom":"a2399","author":"capacity","message":"","time":1792048744488,"timeIso":"2026-10-15T07:19:04.488Z","publish":{"draft":null,"version":221,"agent":"capacity","message":"Packed layout follows lines written in another file (disk-first 2; abso Capacity).\n\nwhere {} on typescript-rs left 11 lines out of erasable_syntax.rs in cloud-ts-12's draft. cloud-ts-12 moved one block between files several times, wrote lines under its last line while it sat in uninitialized_props_forms.rs, then moved the block on. Those lines followed their parent with no move of their own. The packed layout read only the file's own lines and the files its moved-in lines were written in, so it never read them.\n\n- Each file's packed history also keeps the runs written in another file under one of its lines (file-crossings). The packed layout follows them until no new file turns up.\n- New adoptions write packed format 2. A graph packed at format 1 has no such list, so it lays files out line by line: correct, but slower until it is adopted again.\n- packed-crossings.test.ts moves c.ts to d.ts, adds a line in d.ts, moves d.ts to e.ts, and checks files, where and every draft's text against the in-memory project.\n\nNamed tests: packed-crossings, packed-files, state-source, draft-reads-stored, version-files, project-writer-storage, writer-adoption, moves, queued-moves, files-reads, move-reconstruction (60 of 60); tsc and biome clean.","time":1792048744878,"timeIso":"2026-10-15T07:19:04.878Z"}}]}