[alloc + set] Introducing BStackChunk API with sorting and iterator - #38
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a new fixed-stride “record view” abstraction (BStackChunk<'a>) over BStackSlice, plus a lazy iterator (BStackChunkIter<'a>), enabling chunk-oriented iteration and APIs like binary search, stable sorting, and selection on whole records.
Changes:
- Introduces
BStackChunk/BStackChunkIterwithchunks/rchunksconstructors (and owned-slice mirrors), iteration, and view utilities (get,as_slice,into_slice,with_stride). - Adds chunk-level algorithms:
binary_search_by(_key)(alloc-only) andsort_by(_key)/select_nth_by(_key)(gated behindset+atomic). - Expands tests and documentation (README/CHANGELOG), and updates the roadmap (PLANNED.md) to reflect the implemented strategy and future work.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/alloc/chunk.rs | New BStackChunk / BStackChunkIter implementation, chunking constructors on BStackSlice, and chunk algorithms. |
| src/alloc/mod.rs | Wires in the new chunk module and re-exports the new types. |
| src/lib.rs | Re-exports BStackChunk and BStackChunkIter from the crate’s public API. |
| src/test.rs | Adds unit tests covering construction, remainder behavior, iteration, sorting, searching, selection, and trait semantics. |
| README.md | Documents the new types, trait semantics, and the chunked-view API surface. |
| CHANGELOG.md | Adds release notes describing the new BStackChunk API and behavior/traits. |
| PLANNED.md | Updates the design notes to focus on future external-merge-sort and out-of-core selection strategies for chunks. |
Suppressed comments (1)
src/alloc/chunk.rs:567
ExactSizeIteratorrequires thatlen()be exact, but forBStackChunkIterthe number of remaining chunks is derived from au64length and can exceed what fits inusizeon 32-bit platforms. With the current implementation this can silently truncate viasize_hintand violate theExactSizeIteratorcontract. Consider only implementingExactSizeIteratorwhere it is always representable (e.g. gate it on 64-bit pointer width) or remove the impl.
impl<'a> ExactSizeIterator for BStackChunkIter<'a> {}
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description: Adding
BStackChunk<'a>with its iteratorBStackChunkIter<'a>— fixed-stride view overBStackSlice. It holds the same semantic position asBStackSlice<'a>and offers additional atomic search/sort/select APIs (binary_search_by/binary_search_by_key/sort_by/sort_by_key/select_nth_by/select_nth_by_key).New Feature: Yes
Important Feature: Yes
Feature Flags:
alloc(+set+atomic)Breaking change: No
New Types:
BStackChunkandBStackChunkIterRust Only: Yes
Fuzz: Not needed