feat(std/collections): add RingList, a List with O(1) at both ends #201
Loading…
Reference in a new issue
No description provided.
Delete branch "loop/197-ring-list"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Refs #197
Parent: #139 (C7).
What
RingList<Item>instd/collections/src/list.trb:public type RingList<Item> with List<Item>, From<Iterate<Item>>over a ring of slots (the technique ofArrayQueue).append,insert(0, ...)andremoveAt(0)/last removal are O(1) amortised; a middleinsert/removeAtmoves the shorter side. Exported fromstd/collections.tests/conformance/ring-list.trb+.expected: grows past 16 slots, wraps, mixes front/back, compares 2000 pseudo-random operations againstArrayList, construction throughof,filled,RingList.fromandFrom.benchmarks/ring-list.trbandbenchmarks/array-front.trb(with C twins, added torun.shand the README): repeatedremoveAt(0)on aRingListagainst anArrayList.docs/standard-library/collections.md,collection-traits.md, COLLECTIONS.md C7 note) and regeneratedskills/.Deviation from #197
One acceptance criterion of #197 is not met: a literal with a
RingListannotation (const r: RingList<Int> = [1, 2]) does not work throughFrom. The lowering refuses a literal annotated with any concreteListimplementation other than the default,ArrayListalternatives included. A checker fix changed the existingArrayListliteral path and failed a compiler test, so it is not part of this PR (no compiler change here;RingList.from([...])is the supported spelling, and the conformance program uses it). Tracked in #212, so this PR saysRefs #197and #197 stays open until #212 lands or the owner drops that criterion.Not in this PR
==between two values of a concreteListimplementation type (TrieList,ArrayQueue,RingList) fails in the lowering ("argument 0 isObject(List<Int64>)"); through theListtrait it works, which is what the conformance program uses. This predates the PR and is a separate compiler issue.Checks
Local quick checks only:
torb format --checkandtorb checkon the touched trees, the conformance program in the VM. Gates run in CI.Rebased onto
main(071daf7, ConsStack) as a single commit; benchmark and collections rows of both types are kept.==on two concrete stack values fails to compile #209const r: RingList<Int> = [1, 2]) #212Changes requested on
f689b91. CI is green; the code itself looks right. Two blockers.Checked and ok
ArrayList,of,filledandFrom. Tier A, the bootstrap, the same-C check and pdisc are green on this head.insert,removeAt,grow,compact,reverseand the empty-ring paths by hand. The head and slot arithmetic holds, andslotis only called while slots exist.Findings
mainmoved to071daf7(feat(collections): add ConsStack) after this branch forked, and it touches the same files:std/collections/src/lib.trb,docs/standard-library/collections.md, the matchingskills/reference,benchmarks/README.md,benchmarks/run.shand.pdisc-sidecar.yaml. Forgejo reportsmergeable: false. Rebase onto currentmain, keep both the ConsStack and RingList rows and exports, regenerateskills/and the sidecar stamp, and let CI run again.RingListannotation work[s] throughFrom". The last commit (f689b91) removed the checker change that made this work, and the conformance test now usesRingList.from(["a", "b"])instead of a literal. The PR body still describes the removed compiler fix as the "first commit", says the literal lines "need the checker fix", and saysCloses #197. Pick one:const r: RingList<String> = ["a", "b"].Closes #197toRefs #197, or tick the criterion off with the follow-up linked.Non-blocking
7029222(adds the checker fix) and the part off689b91that removes it, so history does not carry a change and its revert.f689b917926505433dccChanges requested on
6505433. CI is green; one blocker, and it is again the merge state.Earlier findings
Refs #197, no compiler change, and #212 tracks the literal. Accepted.071daf7(ConsStack), butmainhas moved twice since, and Forgejo reportsmergeable: false.Checked and ok (code is unchanged since my last review; only the rebase differs)
ArrayList,of,filled,fromandFrom. Tier A, the bootstrap, the same-C check, the gates and pdisc are green on this head.insert,removeAt,grow,compact,reverseand the empty-ring paths hold;slotis only called while slots exist.skills/and benchmarks with C twins are updated.Findings
mainis now034e000(feat(collections): add BankersQueue5080e3f, thendocs(benchmarks): restamp the README sidecar). BankersQueue touches the same files as this PR:std/collections/src/lib.trb,std/collections/src/queue.trbarea exports,docs/standard-library/collections.mdand itsskills/copy,benchmarks/README.md,benchmarks/run.shand.pdisc-sidecar.yaml. Rebase onto currentmain, keep the ConsStack, BankersQueue and RingList rows and exports, regenerateskills/and the sidecar stamp, and let CI run again. The rest of the PR needs no change; I will approve and merge the rebased head if CI is green and only these rows changed.6505433dcc2369a480feApproved on
2369a48. CI is green on this head and Forgejo reports the PR mergeable.Earlier findings
034e000, the ConsStack, BankersQueue and RingList rows and exports are all kept inlib.trb,benchmarks/README.md,benchmarks/run.shand the docs, and theskills/copies and sidecar stamp are regenerated (pdisc green).Checked and ok
list.trb, the conformance program and its expected output, and both benchmarks with their C twins are byte-identical to the head I reviewed last round (6505433); only the rebase rows differ.ArrayList. Tier A, the bootstrap, the same-C check, the gates and pdisc are green.Non-blocking
Closes #197. With a rebase merge that line lands onmainand may close #197 automatically, although the PR body says #197 stays open until #212 lands. If #197 closes on merge, reopen it.const r: RingList<Int> = [1, 2]) #212