-
Notifications
You must be signed in to change notification settings - Fork 172
Chore: Vectors even more cleanup #5038
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
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // SPDX-FileCopyrightText: Copyright the Vortex contributors | ||
|
|
||
| //! [`FromIterator`] and related implementations for [`BoolVectorMut`]. | ||
|
|
||
| use vortex_buffer::BitBufferMut; | ||
| use vortex_mask::MaskMut; | ||
|
|
||
| use crate::BoolVectorMut; | ||
|
|
||
| impl FromIterator<Option<bool>> for BoolVectorMut { | ||
| /// Creates a new [`BoolVectorMut`] from an iterator of `Option<bool>` values. | ||
| /// | ||
| /// `None` values will be marked as invalid in the validity mask. | ||
| /// | ||
| /// # Examples | ||
| /// | ||
| /// ``` | ||
| /// use vortex_vector::{BoolVectorMut, VectorMutOps}; | ||
| /// | ||
| /// let mut vec = BoolVectorMut::from_iter([Some(true), None, Some(false)]); | ||
| /// assert_eq!(vec.len(), 3); | ||
| /// ``` | ||
| fn from_iter<I>(iter: I) -> Self | ||
| where | ||
| I: IntoIterator<Item = Option<bool>>, | ||
| { | ||
| let iter = iter.into_iter(); | ||
| let (lower_bound, _) = iter.size_hint(); | ||
|
|
||
| let mut bits = Vec::with_capacity(lower_bound); | ||
| let mut validity = MaskMut::with_capacity(lower_bound); | ||
|
|
||
| for opt_val in iter { | ||
| match opt_val { | ||
| Some(val) => { | ||
| bits.push(val); | ||
| validity.append_n(true, 1); | ||
| } | ||
| None => { | ||
| bits.push(false); // Value doesn't matter for invalid entries. | ||
| validity.append_n(false, 1); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| BoolVectorMut { | ||
| bits: BitBufferMut::from_iter(bits), | ||
| validity, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl FromIterator<bool> for BoolVectorMut { | ||
| /// Creates a new [`BoolVectorMut`] from an iterator of `bool` values. | ||
| /// | ||
| /// All values will be treated as non-null. | ||
| /// | ||
| /// # Examples | ||
| /// | ||
| /// ``` | ||
| /// use vortex_vector::{BoolVectorMut, VectorMutOps}; | ||
| /// | ||
| /// let mut vec = BoolVectorMut::from_iter([true, false, false, true]); | ||
| /// assert_eq!(vec.len(), 4); | ||
| /// ``` | ||
| fn from_iter<I>(iter: I) -> Self | ||
| where | ||
| I: IntoIterator<Item = bool>, | ||
| { | ||
| let buffer = BitBufferMut::from_iter(iter); | ||
| let validity = MaskMut::new_true(buffer.len()); | ||
|
|
||
| BoolVectorMut { | ||
| bits: buffer, | ||
| validity, | ||
| } | ||
| } | ||
| } | ||
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // SPDX-FileCopyrightText: Copyright the Vortex contributors | ||
|
|
||
| //! [`FromIterator`] and related implementations for [`PVectorMut<T>`]. | ||
|
|
||
| use vortex_buffer::BufferMut; | ||
| use vortex_dtype::NativePType; | ||
| use vortex_mask::MaskMut; | ||
|
|
||
| use crate::PVectorMut; | ||
|
|
||
| impl<T: NativePType> FromIterator<Option<T>> for PVectorMut<T> { | ||
| /// Creates a new [`PVectorMut<T>`] from an iterator of `Option<T>` values. | ||
| /// | ||
| /// `None` values will be marked as invalid in the validity mask. | ||
| /// | ||
| /// # Examples | ||
| /// | ||
| /// ``` | ||
| /// use vortex_vector::{PVectorMut, VectorMutOps}; | ||
| /// | ||
| /// let mut vec = PVectorMut::<i32>::from_iter([Some(1), None, Some(3)]); | ||
| /// assert_eq!(vec.len(), 3); | ||
| /// ``` | ||
| fn from_iter<I>(iter: I) -> Self | ||
| where | ||
| I: IntoIterator<Item = Option<T>>, | ||
| { | ||
| let iter = iter.into_iter(); | ||
| let (lower_bound, _) = iter.size_hint(); | ||
|
|
||
| let mut elements = Vec::with_capacity(lower_bound); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use BitBufferMut |
||
| let mut validity = MaskMut::with_capacity(lower_bound); | ||
|
|
||
| for opt_val in iter { | ||
| match opt_val { | ||
| Some(val) => { | ||
| elements.push(val); | ||
| validity.append_n(true, 1); | ||
| } | ||
| None => { | ||
| elements.push(T::default()); // Use default for invalid entries. | ||
| validity.append_n(false, 1); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| PVectorMut { | ||
| elements: BufferMut::from_iter(elements), | ||
| validity, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl<T: NativePType> FromIterator<T> for PVectorMut<T> { | ||
| /// Creates a new [`PVectorMut<T>`] from an iterator of `T` values. | ||
| /// | ||
| /// All values will be treated as non-null. | ||
| /// | ||
| /// # Examples | ||
| /// | ||
| /// ``` | ||
| /// use vortex_vector::{PVectorMut, VectorMutOps}; | ||
| /// | ||
| /// let mut vec = PVectorMut::<i32>::from_iter([1, 2, 3, 4]); | ||
| /// assert_eq!(vec.len(), 4); | ||
| /// ``` | ||
| fn from_iter<I>(iter: I) -> Self | ||
| where | ||
| I: IntoIterator<Item = T>, | ||
| { | ||
| let buffer = BufferMut::from_iter(iter); | ||
| let validity = MaskMut::new_true(buffer.len()); | ||
|
|
||
| PVectorMut { | ||
| elements: buffer, | ||
| validity, | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
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.
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.
Use BitBufferMut here
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.
The change is in #5040
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.
Wanna port it over here while we're here?