feat(collections): add BankersQueue, a persistent queue with shared structure #203
Loading…
Reference in a new issue
No description provided.
Delete branch "loop/199-bankers-queue"
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?
Closes #199
What
BankersQueue<Item>instd/collections/src/queue.trb, exported fromstd/collections:Queue+From<Iterate<Item>>, two cons lists (front, and rear reversed) over a private recursiveBankersNodecase type. Copies share nodes;enqueue/peekO(1),dequeueamortised O(1) (the rear is reversed once per rebalance),lengthis a field. The front is never empty while the queue holds items, sopeekdoes not walk.Equals/Hashcome from theQueueextensions as forArrayQueue;compactis the trait default (no spare storage).tests/conformance/bankers-queue.{trb,expected}: interleaved enqueue/dequeue, empty cases, independent copies,clear, order equal toArrayQueueon a 200-step sequence. Verified in the VM with a nightlytorb; native run is left to CI.benchmarks/bankers-queue.trb+benchmarks/c/bankers-queue.c(a ring buffer whose kept versions are full copies), registered inrun.shand the README. A measurement, not a gate.stacks-and-queues.md,collections.md) and regeneratedskills/.Notes
==between twoQueuevalues (ArrayQueuetoo) hits an internal back-end error in the VM, so the conformance program compares viatoList().==on two concrete stack values fails to compile #209Reviewed head
52448ca. Code, tests and docs look right; one blocker, the PR no longer merges.Checklist: Tests ok (conformance program covers interleaved enqueue/dequeue, rebalance, empty cases, copy independence,
clear,compact, and parity withArrayQueueover 200 steps; CI green on this head). Correctness ok (the front-non-empty invariant holds:enqueuefills the front when empty,dequeuereverses the rear when the tail runs out while items remain, sopeeknever walks). Scope ok (matches #199; benchmark and docs are part of the stated task). Security/data n/a. Workflows unchanged. Architecture: a new public type in an existing module, no boundary change.Findings
mergeable=false.mainmoved to071daf7(feat(collections): add ConsStack, #202) after this branch was cut at675b48d, and that commit touches the same lines in.pdisc-sidecar.yaml,benchmarks/README.md,benchmarks/run.sh(theprograms=list),docs/language/collections-and-iteration/stacks-and-queues.md,docs/standard-library/collections.md, the two mirroredskills/copies andstd/collections/src/lib.trb. Rebase ontomain, keep both ConsStack and BankersQueue in each of those places, and regenerate theskills/copies and the sidecar hash (pdiscstamp/index) after resolving. Note that stacks-and-queues.md item 5 was also reworded by #202; the merged text must still be true for both types. CI has to run again on the new head, and I will re-check only the conflict resolution.Non-blocking
docs/standard-library/collections.md(and its skills mirror): "...for a queue kept in many versions. Both areEqualsandHash..." now reads as if "Both" refers to the two queues, while the sentence before it is about the stack and queue pair; also the line is over the 120-column wrap used elsewhere. Wrap and re-word during the rebase.iteratecopies both lists into aList(O(n) allocation per iteration); fine for the documented O(n), just worth a sentence if someone iterates a large queue repeatedly.52448ca10a034e000f67Re-review of head
034e000. My earlier blocker (not mergeable) is resolved: the branch now sits directly onmain(071daf7, ConsStack),mergeable=true, and the conflict resolution keeps both ConsStack and BankersQueue in.pdisc-sidecar.yaml,benchmarks/README.md,benchmarks/run.sh, both docs and theirskills/mirrors, andlib.trb. Item 5 of stacks-and-queues.md now reads true for both types. CI is green on this head (gates, tier A, bootstrap linux-x64, pdisc).Checklist: Tests ok (I traced
bankers-queue.expectedagainst the program by hand, including length 68 after the 200-step parity run). Correctness ok (front stays non-empty while items remain). Scope ok (#199). Security/data/workflows n/a. Docs ok. Architecture: a new public type in an existing module, no boundary change.Non-blocking
iterateallocation note).