Skip to content

abso-core

Public

abso is version control for agents: the client, the engine and a server you can run on your own Cloudflare account.

Check passed
MCP
code on this site's /mcp
CLI
none: the JSON below is the answer
JSON
/christopher/abso-core/files/worker/project/move-line-text.ts?version=295&format=json
74 linescodex-capacity-chair 99% · First import 1%Last change codex-capacity-chair in version 175, 1 version changed it

You're reading version 295. The newest is 318, and no version since then changed this file. Go to the newestCompare with 318

1import type { Graph } from "../../src/engine/graph.ts";
2import { PLAIN_LINE } from "./collisions.ts";
3
4/** Exact text symbols backed by graph line IDs, never retained whole strings. */
5export class MoveLineText {
6 readonly graph: Graph;
7 readonly buckets = new Map<string, { symbol: number; line: number }[]>();
8 readonly plain: boolean[] = [];
9 readonly lines: number[] = [];
10 readonly symbolsByLine = new Map<number, number>();
11 constructor(graph: Graph) {
12 this.graph = graph;
13 }
14 text(symbol: number): string {
15 const line = this.lines[symbol];
16 if (line === undefined) throw Error("unknown move text symbol");
17 return this.graph.textOf(line);
18 }
20 intern(id: string): number {
21 const line = this.graph.lineN(id);
22 const known = this.symbolsByLine.get(line);
23 if (known !== undefined) return known;
24 let hash = 2166136261,
25 length = 0,
26 plain = true;
27 for (const chunk of this.graph.textChunks(line)) {
28 length += chunk.length;
29 if (!PLAIN_LINE.test(chunk)) plain = false;
30 for (let i = 0; i < chunk.length; i++) hash = Math.imul(hash ^ chunk.charCodeAt(i), 16777619) >>> 0;
31 }
32 const key = `${length}:${hash}`;
33 const bucket = this.buckets.get(key) ?? [];
34 for (const candidate of bucket)
35 if (sameChunks(this.graph.textChunks(line), this.graph.textChunks(candidate.line))) {
36 this.symbolsByLine.set(line, candidate.symbol);
37 return candidate.symbol;
38 }
39 const symbol = this.plain.length;
40 this.plain.push(plain);
41 this.lines.push(line);
42 bucket.push({ symbol, line });
43 this.buckets.set(key, bucket);
44 this.symbolsByLine.set(line, symbol);
45 return symbol;
46 }
49function sameChunks(a: IterableIterator<string>, b: IterableIterator<string>): boolean {
50 let x = a.next(),
51 y = b.next(),
52 i = 0,
53 j = 0;
54 try {
55 for (;;) {
56 while (!x.done && i === x.value.length) {
57 x = a.next();
58 i = 0;
59 }
60 while (!y.done && j === y.value.length) {
61 y = b.next();
62 j = 0;
63 }
64 if (x.done || y.done) return x.done === y.done;
65 const length = Math.min(x.value.length - i, y.value.length - j);
66 if (x.value.slice(i, i + length) !== y.value.slice(j, j + length)) return false;
67 i += length;
68 j += length;
69 }
70 } finally {
71 a.return?.();
72 b.return?.();
73 }