docs(adr): ids sort in natural order everywhere (improvise-cq1q.1)
Defines natural order, applies it to the display suffix, and adds a Status row for the conflict with CellKey's String::cmp order: RecordHash values change and saved data lines reorder; the loader canonicalises. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VdfEGXA7aJ6ftMsCc9PJze
This commit is contained in:
committed by
Edward Langley
parent
cb73ad3d55
commit
12642e40b6
@@ -18,6 +18,7 @@ true. Where the amendment replaces an ADR 007 rule or an existing behaviour:
|
||||
| 1 | `measure_item_names` merges a formula into a stored measure of the same name | a formula never merges: it gets its own id, `profit-<n>` beside a stored `profit` |
|
||||
| 2 | a display already in use in a scope is refused | equal displays in a scope are shown with a gapless ` #2`, ` #3`, … suffix in id order |
|
||||
| 2 | `CellKey` pairs are `(CategoryId, ItemId)` | `(CategoryId, ItemHandle)` |
|
||||
| 4 | ids sort by plain string order (`CellKey::new` sorts with `String::cmp`, and the writer orders data lines by their text) | ids sort in natural order. `CellKey`'s canonical coordinate order changes with it, so `RecordHash` values change (they are on the wire, not in files), and a saved file's data lines and their coordinates are written in the new order; the loader canonicalises keys, so the data read back is the same |
|
||||
| 2, 5 | a collapsed entry and a group reference name a group by name | by its id |
|
||||
| 4 | casefold; a run of U+0020 spaces becomes one `_`; strip characters outside `a`–`z`, `0`–`9`, `-`, `_`; remove a leading `_` | casefold; every character outside `a`–`z`, `0`–`9` and `-` becomes `_`; runs of `_` collapse; leading and trailing `_` and `-` are removed; `n` is prepended before a leading digit |
|
||||
| 5 | a hand-written id uses the alphabet `a`–`z`, `0`–`9`, `-`, `_` | a hand-written id obeys every syntax rule of a generated id |
|
||||
@@ -104,10 +105,9 @@ cost`); a dimension target is rare, for a derived dimension.
|
||||
the same display, they are shown with a suffix: the first keeps the bare display, and
|
||||
the rest get ` #2`, ` #3`, … (a space, then `#` and the number) as a gapless
|
||||
sequence in the order their ids sort.
|
||||
- The order is the ids' plain string order, the order `CellKey` already sorts ids
|
||||
in, not the counter's numeric order. So
|
||||
`profit`, `profit-1` and `profit-2` show as `Profit`, `Profit #2` and `Profit #3`,
|
||||
and `profit-10` sorts before `profit-2`.
|
||||
- The order is the ids' natural order (clause 4), so `profit`, `profit-1`,
|
||||
`profit-2` and `profit-10` show as `Profit`, `Profit #2`, `Profit #3` and
|
||||
`Profit #4`.
|
||||
- Gapless: if the thing shown as `Profit #2` is removed, `Profit #3` becomes
|
||||
`Profit #2`.
|
||||
- The suffix is computed when a display is shown, from the things that share it, and
|
||||
@@ -159,6 +159,12 @@ also what the counter may make of `east`. They never collide, because every id a
|
||||
document holds is taken however it was made: a display slugging to a held `east-1`
|
||||
becomes `east-1-<n>`, and a held counter candidate is skipped.
|
||||
|
||||
**Ids are always sorted in natural order**, wherever ids are ordered. Split each id into
|
||||
alternating runs of digits and non-digits; compare the runs pairwise, a digit run by its
|
||||
numeric value and a non-digit run by byte order; when two digit runs have equal value,
|
||||
the shorter (fewer leading zeros) sorts first; when one id runs out of runs first, it
|
||||
sorts first. So `profit`, `profit-1`, `profit-2`, `profit-10`, and `a-7` before `a-007`.
|
||||
|
||||
**Hand-written ids obey every syntax rule of a generated id.** `east-1`, `item-4` and
|
||||
`q1_-_2024` load; `-east`, `east-`, `2024`, `a__b` and `_draft` are refused at load.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user