Lines 2–8 at 229 (were 2–7 at 228)
22// is the project in memory. 44import { type AtomId, type Graph, parseKey, type ReadView } from "../../src/engine/index.ts"; 5+import { StableSet, unionOverlay } from "../../src/engine/state-source.ts"; 56import { claimantsAmong, describeSide, fileOfKey, pairsFrom } from "./collisions.ts"; 67import type { DefinitionRule } from "./definition-rule.ts"; 78import { type Definition, definedTwice } from "./definitions.ts"; Lines 38–66 at 229 (were 37–42 at 228)
3738 * top of a file (refused once the second syncs onto the first's work). Exact for shared at `version`; as shared moves on, so can 3839 * the answer, as a real publish's would. `file` or `folder` narrows it. 42+ * A set and some drafts' atoms, by lookup (abso Capacity): copying shared's atoms into a new set read every one of them 43+ * from disk on a stored writer, once per pair of agents. 45+class WithDrafts extends StableSet<AtomId> { 46+ readonly retainedBytes: number; 47+ readonly #base: ReadonlySet<AtomId>; 48+ readonly #drafts: ReadonlySet<AtomId>; 49+ constructor(base: ReadonlySet<AtomId>, drafts: Iterable<AtomId>) { 52+ this.#drafts = new Set(drafts); 53+ this.retainedBytes = 64 + this.#drafts.size * 32; 55+ has(atom: AtomId): boolean { 56+ return this.#drafts.has(atom) || this.#base.has(atom); 58+ *values(): SetIterator<AtomId> { 60+ for (const atom of this.#drafts) if (!this.#base.has(atom)) yield atom; 4064export function draftCollisions( 4165 host: DraftCollisionHost, 4266 options: { file?: string; folder?: string } = {}, Lines 95–108 at 229 (were 71–81 at 228)
7195 if (!set) draftSets.set(agent, (set = new Set(host.draft(agent)))); 74− // Shared now with each agent's draft on top, once per agent: the key of a view of a set lists every atom in it.
98+ // Shared now with each agent's draft on top, once per agent. Over shared's view's own set (abso Capacity): a view's set 99+ // is closed under dependencies anyway, so shared's closed set and the drafts lay out what shared's atoms and the drafts 100+ // do, and only the drafts' atoms are walked to close it. 101+ const withDraftsView = (...drafts: readonly AtomId[][]) => host.view(unionOverlay(sharedView.set, drafts.flat())); 75102 const nowViews = new Map<Agent, ReadView>(); 76103 const nowViewOf = (agent: Agent) => { 77104 let view = nowViews.get(agent); 78− if (!view) nowViews.set(agent, (view = host.view(new Set([...shared, ...host.draft(agent)]))));
105+ if (!view) nowViews.set(agent, (view = withDraftsView(host.draft(agent)))); 81108 // Each agent's touched files once, not once per pair (abso Capacity). Lines 120–126 at 229 (were 93–99 at 228)
93120 const draftA = host.draft(a); 94121 const draftB = host.draft(b); 95122 const newer = draftSet(a); 96− const union = new Set([...shared, ...draftA, ...draftB]);
123+ const union = new WithDrafts(shared, [...draftA, ...draftB]); 97124 const viewA = host.agentView(a); 98125 const viewB = host.agentView(b); Lines 161–175 at 229 (were 134–148 at 228)
134161 const mineB = new Set(draftB); 135162 const filesA = touchedBy(a); 136163 for (const file of [...touchedBy(b)].filter((f) => filesA.has(f)).toSorted()) { 137− both ??= host.view(union);
164+ both ??= withDraftsView(draftA, draftB); 138165 if (!both.hasFile(file)) continue; 139166 for (const [name, defs] of definedTwice(both, file)) { 140− const by = (mine: Set<AtomId>) => defs.find((d) => d.lines.some((l) => mine.has(host.graph.line(l)!.atom)));
167+ const by = (mine: Set<AtomId>) => defs.find((d) => d.lines.some((l) => mine.has(host.graph.lineAtom(l)!))); 141168 const dA = by(mineA); 142169 const dB = by(mineB); 143170 if (!dA || !dB || dA === dB) continue; 144171 const atomsOf = (d: Definition, mine: Set<AtomId>) => 145− d.lines.map((l) => host.graph.line(l)!.atom).filter((x) => mine.has(x));
172+ d.lines.map((l) => host.graph.lineAtom(l)!).filter((x) => mine.has(x)); 146173 if (atomsOf(dA, mineA).some((x) => atomsOf(dB, mineB).some((y) => paired.has(`${x} ${y}`)))) continue; 148175 kind: "duplicate",