-
Notifications
You must be signed in to change notification settings - Fork 91
Implement Clone on the bitmap::Iter type #289
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
3526627
Implement Clone on the bitmap::Iter type
Kerollmops 0d72193
Implement Clone on the roaring bitmap
Kerollmops e972ff4
Inline most the insertion functions
Kerollmops 1f1c222
Inline the RoaringBitmap max method
Kerollmops f3e289d
Introduce the Statistics data structure
Kerollmops f8e5aeb
Make the Statistics struct non exhaustive
Kerollmops 2d1a330
Make sure not to overflow values in the the Statistics
Kerollmops a27587f
Add more documentation to the ArrayStore capacity method
Kerollmops 06f3578
Bump MSRV to 1.71.1
Kerollmops 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
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,107 @@ | ||
use core::mem; | ||
|
||
use crate::bitmap::container::Container; | ||
use crate::RoaringBitmap; | ||
|
||
use super::store::Store; | ||
|
||
/// Detailed statistics on the composition of a bitmap. | ||
#[derive(Clone, Copy, PartialEq, Debug)] | ||
#[non_exhaustive] | ||
pub struct Statistics { | ||
/// Number of containers in the bitmap | ||
pub n_containers: u32, | ||
/// Number of array containers in the bitmap | ||
pub n_array_containers: u32, | ||
/// Number of run containers in the bitmap | ||
pub n_run_containers: u32, | ||
/// Number of bitset containers in the bitmap | ||
pub n_bitset_containers: u32, | ||
/// Number of values stored in array containers | ||
pub n_values_array_containers: u32, | ||
/// Number of values stored in run containers | ||
pub n_values_run_containers: u32, | ||
/// Number of values stored in bitset containers | ||
pub n_values_bitset_containers: u64, | ||
/// Number of bytes used by array containers | ||
pub n_bytes_array_containers: u64, | ||
/// Number of bytes used by run containers | ||
pub n_bytes_run_containers: u64, | ||
/// Number of bytes used by bitset containers | ||
pub n_bytes_bitset_containers: u64, | ||
/// Maximum value stored in the bitmap | ||
pub max_value: Option<u32>, | ||
/// Minimum value stored in the bitmap | ||
pub min_value: Option<u32>, | ||
/// Number of values stored in the bitmap | ||
pub cardinality: u64, | ||
} | ||
|
||
impl RoaringBitmap { | ||
/// Returns statistics about the composition of a roaring bitmap. | ||
/// | ||
/// ``` | ||
/// use roaring::RoaringBitmap; | ||
/// | ||
/// let mut bitmap: RoaringBitmap = (1..100).collect(); | ||
/// let statistics = bitmap.statistics(); | ||
/// | ||
/// assert_eq!(statistics.n_containers, 1); | ||
/// assert_eq!(statistics.n_array_containers, 1); | ||
/// assert_eq!(statistics.n_run_containers, 0); | ||
/// assert_eq!(statistics.n_bitset_containers, 0); | ||
/// assert_eq!(statistics.n_values_array_containers, 99); | ||
/// assert_eq!(statistics.n_values_run_containers, 0); | ||
/// assert_eq!(statistics.n_values_bitset_containers, 0); | ||
/// assert_eq!(statistics.n_bytes_array_containers, 512); | ||
/// assert_eq!(statistics.n_bytes_run_containers, 0); | ||
/// assert_eq!(statistics.n_bytes_bitset_containers, 0); | ||
/// assert_eq!(statistics.max_value, Some(99)); | ||
/// assert_eq!(statistics.min_value, Some(1)); | ||
/// assert_eq!(statistics.cardinality, 99); | ||
/// ``` | ||
pub fn statistics(&self) -> Statistics { | ||
let mut n_containers = 0; | ||
let mut n_array_containers = 0; | ||
let mut n_bitset_containers = 0; | ||
let mut n_values_array_containers = 0; | ||
let mut n_values_bitset_containers = 0; | ||
let mut n_bytes_array_containers = 0; | ||
let mut n_bytes_bitset_containers = 0; | ||
let mut cardinality = 0; | ||
|
||
for Container { key: _, store } in &self.containers { | ||
match store { | ||
Store::Array(array) => { | ||
cardinality += array.len(); | ||
n_values_array_containers += array.len() as u32; | ||
n_bytes_array_containers += (array.capacity() * mem::size_of::<u32>()) as u64; | ||
n_array_containers += 1; | ||
} | ||
Store::Bitmap(bitmap) => { | ||
cardinality += bitmap.len(); | ||
n_values_bitset_containers += bitmap.len(); | ||
n_bytes_bitset_containers += bitmap.capacity() as u64; | ||
n_bitset_containers += 1; | ||
} | ||
} | ||
n_containers += 1; | ||
} | ||
|
||
Statistics { | ||
n_containers, | ||
n_array_containers, | ||
n_run_containers: 0, | ||
n_bitset_containers, | ||
n_values_array_containers, | ||
n_values_run_containers: 0, | ||
n_values_bitset_containers, | ||
n_bytes_array_containers, | ||
n_bytes_run_containers: 0, | ||
n_bytes_bitset_containers, | ||
max_value: self.max(), | ||
min_value: self.min(), | ||
cardinality, | ||
} | ||
} | ||
} |
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
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.
Uh oh!
There was an error while loading. Please reload this page.