Skip to main content

Module ids

Module ids 

Source
Expand description

Element ids kept across edits: a file’s new parse matched against its last, sibling list by sibling list, so an element keeps its id however the lines around it change. Siblings with a key are matched by it; the others by a shortest edit script over the list (Myers’ diff), comparing each element whole — its name, its own attributes and everything in it — and then, among what is left between two matches, an element with one of the same name, in order, as an edit of it. A matched element’s children are matched the same way; an element left over is new and takes the file’s next id.

The cost is a pass over the file: lists are trimmed of what they share at either end, and Myers’ diff, which costs a list’s length times its edits, is searched to MAX_EDITS edits. Past that — a save that rewrote the list — the list is matched by a histogram diff: every element that occurs once on each side is matched wherever it now is, the longest run of them in order splits the list into gaps, and each gap is matched again the same way. That is near-linear however many edits there are, and never pairs the list by position.

A store that keeps designs between saves reads its files through Remembering, which keeps each design file’s last parse and matches the next against it.

Structs§

Parses
Each design file’s last parse, by path. A clone shares them: a store keeps one and reads through it with whichever files each resolve uses.
Remembering
files, with each design file parsed matched against its last parse in Parses — and remembered there as its last.

Constants§

MAX_EDITS
The longest edit script searched for between two lists of siblings.

Functions§

key
The key an element names itself by among its siblings, if it has one.
matched
new, its elements given the ids of the elements of last they match, and fresh ones from last’s next id where they match none.