-
Notifications
You must be signed in to change notification settings - Fork 0
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
Implement LevelHistograms as a struct #1
Implement LevelHistograms as a struct #1
Conversation
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.
Thanks @alamb. This looks great. I learned a lot from it.
self.repetition_level_histogram.as_mut().map(LevelHistogram::reset); | ||
self.definition_level_histogram.as_mut().map(LevelHistogram::reset); |
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.
So much nicer than what I was doing 😮
if let Some(hist) = self.repetition_level_histogram.as_mut() {
hist.reset()
}
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 your way is pretty nice too -- this is borderline too functional for my taste, but it seemed to be ok :)
if let (Some(page_hist), Some(chunk_hist)) = (page_histogram, chunk_histogram) { | ||
chunk_hist.add(page_hist); |
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 thought I tried this and it didn't work. Thanks. My approach was to have add
take an Option<LevelHistogram>
.
/// Length will be `max_level + 1`. | ||
/// | ||
/// Returns `None` when `max_level == 0` (because histograms are not necessary in this case) | ||
pub fn try_new(max_level: i16) -> Option<Self> { |
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 struggled with this name, as the consensus seemed to be that try_new
returns a Result
. I wound up opting for maybe_new
, but I prefer this!
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.
Yeah maybe there is a better convention but I think this is pretty standard in my experience
impl From<Vec<i64>> for LevelHistogram { | ||
fn from(inner: Vec<i64>) -> Self { | ||
Self { inner } | ||
} | ||
} | ||
|
||
impl From<LevelHistogram> for Vec<i64> { | ||
fn from(value: LevelHistogram) -> Self { | ||
value.into_inner() | ||
} | ||
} |
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.
So much nicer. Thank you!
let repetition_level_histogram = repetition_level_histogram.map(LevelHistogram::from); | ||
let definition_level_histogram = definition_level_histogram.map(LevelHistogram::from); |
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.
❤️
Add test for metadata equivalence
This PR targets apache#6105
Per the suggestion on apache#6105 (review) I tried out encapsulating the information about level histograms in a rust struct,
LevelHistogram
I think I like this as it encapsulates the
Vec<i64>
for histograms, so that the operations on it can be named and documented