-
Notifications
You must be signed in to change notification settings - Fork 13.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conventions and cleanup for Bitv and BitvSet #19216
Conversation
That looks like the wrong reference. |
Whoops, fixed. |
/// false, false, false, true, | ||
/// false, false, true, false])); | ||
/// ``` | ||
pub fn from_bytes(bytes: &[u8]) -> Bitv { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could consider providing FromIterator
/Extend
instances for bool
, u8
, u16
, u32
and u64
instead. That would give you maximal flexibility while keeping the API surface thin and standard.
(I suppose this would put further pressure on the performance of these traits, though. Perhaps it's worth spending time on that soon.)
I've reviewed the API changes and left a few comments. The biggest thing is that, in the long run, I'd really like to reduce the number of ad hoc I didn't have time right now to review the implementation changes in any detail -- maybe one of the other reviewers you mentioned can do that. But I'm happy with the API. |
/// Iterator over the underlying blocks of data | ||
fn blocks(&self) -> Take<Cloned<Items<u32>>> { | ||
let blocks = blocks_for_bits(self.len()); | ||
self.storage.iter().cloned().take(blocks) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these would be more efficient as self.storage.slice_to(blocks).iter().cloned()
. That just stores two pointers (and updates one), while .take
stores the pointers and a uint
and updates a pointer and the uint
on each step (LLVM may optimise this out, but there's no guarantee).
Part of rust-lang#18424 This commit changes the semantics of `reserve` and `capacity` for Bitv and BitvSet to match conventions. It also introduces the notion of `reserve_index` and `reserve_index_exact` for collections with maximum-index-based capacity semantics. Deprecates free function constructors in favour of functions on Bitv itself. Changes `Bitv::pop` to return an Option rather than panicking. Deprecates and renames several methods in favour of conventions. Marks several blessed methods as unstable. This commit also substantially refactors Bitv and BitvSet's implementations. The new implementation is simpler, cleaner, better documented, and more robust against overflows. It also reduces coupling between Bitv and BitvSet. Tests have been seperated into seperate submodules. Fixes rust-lang#16958 [breaking-change]
use std::hash; | ||
|
||
use vec::Vec; | ||
|
||
// FIXME(conventions): look, we just need to refactor this whole thing. Inside and out. | ||
type Blocks<'a> = Cloned<Items<'a, u32>> | ||
type MutBlocks<'a> MutItems<'a, u32>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing ;
on Blocks and =
in MutBlocks.
After I fix the above noted things, I can build your branch, and indeed my |
@cuviper Oh, woah thanks! I've had this branch on the backburner for school work and because it needs an RFC for some of the changes. Thanks for looking at this! Feel free to send a PR with all your fixes! |
Merged in @cuviper's fixes. Still need to wait on /rust-lang/rfcs/pull/509 to merge this, though. (not bothering with rebasing until then) |
4765043
to
2f52dfb
Compare
I have rebased on to master with some fixes from @tbu- Thanks everyone! |
9620f4d
to
7781058
Compare
@huonw I've rebased and fixed up stuff to match the collections reform part 2 RFC, which has been merged. I've also squashed the commits as much as I consider appropriate. The first commit is all the previously reviewed work. r? |
I checked this pretty far but got a spurious error. May re-run if I find time. |
f9c5548
to
78c8b3f
Compare
Part of rust-lang#18424 This commit changes the semantics of `reserve` and `capacity` for Bitv and BitvSet to match conventions. It also introduces the notion of `reserve_index` and `reserve_index_exact` for collections with maximum-index-based capacity semantics. Deprecates free function constructors in favour of functions on Bitv itself. Changes `Bitv::pop` to return an Option rather than panicking. Deprecates and renames several methods in favour of conventions. Marks several blessed methods as unstable. This commit also substantially refactors Bitv and BitvSet's implementations. The new implementation is simpler, cleaner, better documented, and more robust against overflows. It also reduces coupling between Bitv and BitvSet. Tests have been seperated into seperate submodules. Fixes rust-lang#16958 [breaking-change]
- Fix typos on Blocks and MutBlocks. - Use slice_to_mut() for creating blocks_mut(). - Deref the block parameter in get(). - Access nbits separately from mutating set in pop().
The old logic would be ok with *either* 0 or all 1s in the last word, because it didn't compute a proper mask for the case where nbits is an exact multiple of u32::BITS. Add mask_for_bits() to compute this properly, and use it in all(). Add all/none assertions to most of the tests. Note in particular, the all-zero bitv in test_32_elements() was incorrectly all()==true before this patch.
The length of the underlying vector must now be exactly as long as it needs to be.
Also fix up some tests from last commit.
Rebased |
Looks great to me, thanks @gankro! r=me with a squashing of those last few commits. |
Part of #18424 This commit changes the semantics of `reserve` and `capacity` for Bitv and BitvSet to match conventions. It also introduces the notion of `reserve_index` and `reserve_index_exact` for collections with maximum-index-based capacity semantics. Deprecates free function constructors in favour of functions on Bitv itself. Changes `Bitv::pop` to return an Option rather than panicking. Deprecates and renames several methods in favour of conventions. Marks several blessed methods as unstable. This commit also substantially refactors Bitv and BitvSet's implementations. The new implementation is simpler, cleaner, better documented, and more robust against overflows. It also reduces coupling between Bitv and BitvSet. Tests have been seperated into seperate submodules. Fixes #16958 [breaking-change]
Part of rust-lang#18424 This commit changes the semantics of `reserve` and `capacity` for Bitv and BitvSet to match conventions. It also introduces the notion of `reserve_index` and `reserve_index_exact` for collections with maximum-index-based capacity semantics. Deprecates free function constructors in favour of functions on Bitv itself. Changes `Bitv::pop` to return an Option rather than panicking. Deprecates and renames several methods in favour of conventions. Marks several blessed methods as unstable. This commit also substantially refactors Bitv and BitvSet's implementations. The new implementation is simpler, cleaner, better documented, and more robust against overflows. It also reduces coupling between Bitv and BitvSet. Tests have been seperated into seperate submodules. Fixes rust-lang#16958 [breaking-change]
Gonna try to push the rollup ahead of this (this PR is in the rollup) Rebasing that rollup is gonna be awful if it comes to that... |
Part of #18424 This commit changes the semantics of `reserve` and `capacity` for Bitv and BitvSet to match conventions. It also introduces the notion of `reserve_index` and `reserve_index_exact` for collections with maximum-index-based capacity semantics. Deprecates free function constructors in favour of functions on Bitv itself. Changes `Bitv::pop` to return an Option rather than panicking. Deprecates and renames several methods in favour of conventions. Marks several blessed methods as unstable. This commit also substantially refactors Bitv and BitvSet's implementations. The new implementation is simpler, cleaner, better documented, and more robust against overflows. It also reduces coupling between Bitv and BitvSet. Tests have been seperated into seperate submodules. Fixes #16958 [breaking-change]
internal: Downgrade to ubuntu-22.04 for aarch64 and arm builds
Part of #18424
This commit changes the semantics of
reserve
andcapacity
for Bitv and BitvSet to match conventions. It also introduces the notion ofreserve_index
andreserve_index_exact
for collections with maximum-index-based capacity semantics.Deprecates free function constructors in favour of functions on Bitv itself.
Changes
Bitv::pop
to return an Option rather than panicking.Deprecates and renames several methods in favour of conventions.
Marks several blessed methods as unstable.
This commit also substantially refactors Bitv and BitvSet's implementations. The new implementation is simpler, cleaner, better documented, and more robust against overflows. It also reduces coupling between Bitv and BitvSet. Tests have been seperated into seperate submodules.
Fixes #16958
[breaking-change]