Lines 273–290 at 228 (were 273–278 at 227)
273273 readonly #childCounts?: ChildCounts; 274274 #atoms: Atom[] = []; 275275 #lamport: number[] = []; 277+ * A stored graph's lamport numbers, 256 to a row (abso Capacity). A graph that already has them a row each (#lamport) 278+ * keeps that; the choice is made when first needed, so opening reads nothing. 280+ #lamportPaged: ReturnType<typeof storedNumbers> | undefined; 281+ #lamportPagesKnown: ReturnType<typeof storedNumbers> | null | undefined; 282+ get #lamportPages(): ReturnType<typeof storedNumbers> | null { 283+ if (this.#lamportPagesKnown === undefined) 284+ this.#lamportPagesKnown = 285+ this.#lamportPaged && this.#storage!.read("lamport:meta", "length") === undefined ? this.#lamportPaged : null; 286+ return this.#lamportPagesKnown; 276288 // Lines, packed (#46): line n is the k-th line atom seq wrote, n = #lineBase[seq] + k. Each holds its 277289 // atom's seq, the file it was written in (an index into #paths) and its parent (a line's n, or -1 - a 278290 // path's index for a file's start). Its text stays in the atom. Ids and LineInfo objects are made only Lines 559–565 at 228 (were 547–552 at 227)
549561 this.#lamport = storedArray(storage, "lamport"); 562+ this.#lamportPaged = storedNumbers(storage, "lamport-pages"); 550563 this.#lineBase = storedArray(storage, "line-base"); 551564 this.#paths = storedArray(storage, "paths"); 552565 this.#movers = storedArray(storage, "movers"); Lines 806–813 at 228 (were 793–798 at 227)
793806 #relocatedToCode: StateMap<number, RelocationInfo[]> = new Map(); 794807 #relocatedToCodePages: ReturnType<typeof storedLists<RelocationInfo>> | undefined; 795808 #movers: AtomId[] = []; 809+ /** A stored graph's movers, read once (abso Capacity): every view walks them, a row each. */ 810+ #moverList: AtomId[] | undefined; 796811 #atomFiles: (readonly string[])[] = []; 797812 /** Each atom's deleted lines by n, packed (#46), or undefined when it deletes none. */ 798813 #atomDeletes: (readonly number[] | Int32Array | undefined)[] = []; Lines 845–851 at 228 (were 830–836 at 227)
830845 /** lamport(a) = 1 + max lamport of its deps; 0 for an atom with no deps (such as a0). */ 831846 lamport(id: AtomId): number { 832847 if (!this.has(id)) throw new EngineError("unknown-atom", `no atom ${id}`); 833− return this.#lamport[this.#seq(id)]!;
848+ return this.#lamportAt(this.#seq(id)); 836851 /** Compare by priority (lamport, then seq). Negative when a comes first (is lower). */ Lines 984–995 at 228 (were 969–976 at 227)
969984 return atomId(seq); 987+ #lamportAt(seq: number): number { 988+ return this.#lamportPages ? this.#lamportPages.at(seq) : this.#lamport[seq]!; 972991 lamportOfSeq(seq: number): number { 973− return this.#lamport[seq]!;
992+ return this.#lamportAt(seq); 976995 /** The file line n was written in. */ Lines 1275–1287 at 228 (were 1256–1262 at 227)
12571276 /** Atoms that move lines, in seq order. */ 12581277 movers(): readonly AtomId[] { 1259− return this.#movers;
1278+ if (!this.#storage) return this.#movers; 1279+ // Checked against the stored list's length and last mover, so a rolled-back add can't leave one behind. 1280+ const length = this.#movers.length; 1281+ const list = this.#moverList; 1282+ if (list && list.length === length && (length === 0 || list[length - 1] === this.#movers[length - 1])) return list; 1283+ this.#moverList = [...this.#movers]; 1284+ return this.#moverList; 12621287 /** Atoms that list this one directly in their deps. */ Lines 1355–1361 at 228 (were 1330–1336 at 227)
13301355 * the search never descends below the target's lamport. 13321357 #reaches(from: Iterable<AtomId>, target: AtomId): boolean { 1333− const floor = this.#lamport[this.#seq(target)]!;
1358+ const floor = this.#lamportAt(this.#seq(target)); 13341359 if (this.#storage) { 13351360 return this.withProjectionScratch((scratch) => { Lines 1366–1378 at 228 (were 1341–1353 at 227)
13421367 for (const id of from) { 13431368 if (id === target) return true; 1344− if (this.#lamport[this.#seq(id)]! > floor) push(id);
1369+ if (this.#lamportAt(this.#seq(id)) > floor) push(id); 13461371 while (length > 0) { 13471372 const key = String(--length); 13481373 const current = scratch.read("stack", key) as AtomId; 13491374 scratch.remove("stack", key); 1350− if (this.#lamport[this.#seq(current)]! <= floor) continue;
1375+ if (this.#lamportAt(this.#seq(current)) <= floor) continue; 13511376 for (const dependency of this.atom(current).deps) { 13521377 if (dependency === target) return true; 13531378 push(dependency); Lines 1388–1394 at 228 (were 1363–1369 at 227)
13631388 if (cur === target) return true; 13641389 if (seen.has(cur)) continue; 1366− if (this.#lamport[this.#seq(cur)]! <= floor) continue;
1391+ if (this.#lamportAt(this.#seq(cur)) <= floor) continue; 13671392 for (const d of this.atom(cur).deps) if (!seen.has(d)) stack.push(d); Lines 1532–1539 at 228 (were 1507–1513 at 227)
15071532 this.#atoms.push(this.#storage ? atom : frozen); 15091534 for (const d of deps) lam = Math.max(lam, this.lamport(d) + 1); 1510− this.#lamport.push(lam);
1535+ if (this.#lamportPages) this.#lamportPages.push(lam); 1536+ else this.#lamport.push(lam); 15121538 // The run starts' parents and the deleted lines, as codes, before this atom's own lines exist. 15131539 // The atom as given: with lists kept elsewhere, the frozen one reads them back from the log.