Versions 161 to 162
Lines 20–26 at 162 (were 20–26 at 161)
23− | { kind: "insert"; rank: number; text: string }
2626const safe = (value: unknown): value is number => Number.isSafeInteger(value) && Number(value) >= 0;
Lines 132–142 at 162 (were 132–137 at 161)
139+ if (operations.length < 1 || operations.length > 16) throw Error("invalid sequence operation batch");
Lines 197–313 at 162 (were 192–305 at 161)
195− if (operation.kind === "insert") {
196− const { rank, text } = operation;
197− if (!Number.isInteger(rank) || rank < 0 || rank > count(root) || next >= 2 ** 32) throw Error("invalid insert");
198− const added = next++;
199− const insert = (id: Page, at: number, p: Page): number => {
200− if (id === null)
201− return put({
202− id: added,
203− parent: p,
204− left: null,
205− right: null,
206− text,
207− deletions: 0,
208− height: 1,
209− count: 1,
210− visible: 1,
211− fileStarts: text.startsWith("root:") ? 1 : 0,
212− });
213− const node = get(id),
214− leftCount = count(node.left);
215− if (at <= leftCount) save({ ...node, left: insert(node.left, at, id) });
216− else save({ ...node, right: insert(node.right, at - leftCount - 1, id) });
217− return balance(id);
218− };
219− root = insert(root, rank, null);
220− parent(root, null);
221− } else if (operation.kind === "move") {
222− const { from, length, to } = operation;
223− const total = count(root);
224− if (
225− ![from, length, to].every(Number.isSafeInteger) ||
226− from < 0 ||
227− length < 0 ||
228− from + length > total ||
229− to < 0 ||
230− to > total - length
231− )
232− throw Error("invalid move range");
233− // Join two AVL trees around one existing stable marker.
234− const join = (left: Page, pivot: number, right: Page): number => {
235− if (height(left) > height(right) + 1) {
236− const node = get(left!);
237− save({ ...node, right: join(node.right, pivot, right) });
238− const result = balance(left!);
239− parent(result, null);
240− return result;
241− }
242− if (height(right) > height(left) + 1) {
243− const node = get(right!);
244− save({ ...node, left: join(left, pivot, node.left) });
245− const result = balance(right!);
246− parent(result, null);
247− return result;
248− }
249− return save({ ...get(pivot), left, right, parent: null });
250− };
251− const split = (id: Page, at: number): [Page, Page] => {
252− if (id === null) return [null, null];
253− const node = get(id),
254− size = count(node.left);
255− if (at <= size) {
256− const [left, middle] = split(node.left, at);
257− const right = join(middle, id, node.right);
262− const [middle, right] = split(node.right, at - size - 1);
263− const left = join(node.left, id, middle);
264− parent(left, null);
265− parent(right, null);
266− return [left, right];
267− };
268− const merge = (left: Page, right: Page): Page => {
269− if (left === null) {
270− parent(right, null);
271− return right;
273− if (right === null) {
274− parent(left, null);
275− return left;
276− }
277− const [pivot, rest] = split(right, 1);
278− return join(left, pivot!, rest);
279− };
280− if (length && from !== to) {
281− const [left, tail] = split(root, from);
282− const [moved, right] = split(tail, length);
283− const remaining = merge(left, right);
284− const [before, after] = split(remaining, to);
285− root = merge(merge(before, moved), after);
286− parent(root, null);
287− }
288− } else if (operation.kind === "visibility") {
289− let node = get(operation.id);
290− if (
291− !node ||
292− !Number.isInteger(operation.delta) ||
293− Math.abs(operation.delta) !== 1 ||
294− node.deletions + operation.delta < 0
295− )
296− throw Error("invalid visibility");
297− save({ ...node, deletions: node.deletions + operation.delta });
298− while (node.parent !== null) {
299− node = get(node.parent);
300− save(node);
301− }
302− } else throw Error("unknown operation");
- MCP
- compare on this site's /mcp
- CLI
- abso diff 161 162 src/engine/experimental/projection-sequence.ts --json
- JSON
- /christopher/abso-core/compare/161..162?file=src%2Fengine%2Fexperimental%2Fprojection-sequence.ts&format=json