-
-
Notifications
You must be signed in to change notification settings - Fork 700
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
remove get_val in serialization #1587
Merged
Merged
Changes from all commits
Commits
Show all changes
2 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 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 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 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 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 |
---|---|---|
@@ -1,5 +1,4 @@ | ||
use std::io; | ||
use std::sync::Mutex; | ||
|
||
use fastfield_codecs::{Column, MonotonicallyMappableToU64, VecColumn}; | ||
use fnv::FnvHashMap; | ||
|
@@ -204,112 +203,68 @@ impl MultiValuedFastFieldWriter { | |
pub(crate) struct MultivalueStartIndex<'a, C: Column> { | ||
column: &'a C, | ||
doc_id_map: &'a DocIdMapping, | ||
min_max_opt: Mutex<Option<(u64, u64)>>, | ||
random_seeker: Mutex<MultivalueStartIndexRandomSeeker<'a, C>>, | ||
} | ||
|
||
struct MultivalueStartIndexRandomSeeker<'a, C: Column> { | ||
seek_head: MultivalueStartIndexIter<'a, C>, | ||
seek_next_id: u64, | ||
} | ||
impl<'a, C: Column> MultivalueStartIndexRandomSeeker<'a, C> { | ||
fn new(column: &'a C, doc_id_map: &'a DocIdMapping) -> Self { | ||
Self { | ||
seek_head: MultivalueStartIndexIter { | ||
column, | ||
doc_id_map, | ||
new_doc_id: 0, | ||
offset: 0u64, | ||
}, | ||
seek_next_id: 0u64, | ||
} | ||
} | ||
min: u64, | ||
max: u64, | ||
} | ||
|
||
impl<'a, C: Column> MultivalueStartIndex<'a, C> { | ||
pub fn new(column: &'a C, doc_id_map: &'a DocIdMapping) -> Self { | ||
assert_eq!(column.num_vals(), doc_id_map.num_old_doc_ids() as u64 + 1); | ||
let (min, max) = | ||
tantivy_bitpacker::minmax(iter_remapped_multivalue_index(doc_id_map, column)) | ||
.unwrap_or((0u64, 0u64)); | ||
MultivalueStartIndex { | ||
column, | ||
doc_id_map, | ||
min_max_opt: Mutex::default(), | ||
random_seeker: Mutex::new(MultivalueStartIndexRandomSeeker::new(column, doc_id_map)), | ||
} | ||
} | ||
|
||
fn minmax(&self) -> (u64, u64) { | ||
if let Some((min, max)) = *self.min_max_opt.lock().unwrap() { | ||
return (min, max); | ||
min, | ||
max, | ||
} | ||
let (min, max) = tantivy_bitpacker::minmax(self.iter()).unwrap_or((0u64, 0u64)); | ||
*self.min_max_opt.lock().unwrap() = Some((min, max)); | ||
(min, max) | ||
} | ||
} | ||
impl<'a, C: Column> Column for MultivalueStartIndex<'a, C> { | ||
fn get_val(&self, idx: u64) -> u64 { | ||
let mut random_seeker_lock = self.random_seeker.lock().unwrap(); | ||
if random_seeker_lock.seek_next_id > idx { | ||
*random_seeker_lock = | ||
MultivalueStartIndexRandomSeeker::new(self.column, self.doc_id_map); | ||
} | ||
let to_skip = idx - random_seeker_lock.seek_next_id; | ||
random_seeker_lock.seek_next_id = idx + 1; | ||
random_seeker_lock.seek_head.nth(to_skip as usize).unwrap() | ||
fn get_val(&self, _idx: u64) -> u64 { | ||
unimplemented!() | ||
} | ||
|
||
fn min_value(&self) -> u64 { | ||
self.minmax().0 | ||
self.min | ||
} | ||
|
||
fn max_value(&self) -> u64 { | ||
self.minmax().1 | ||
self.max | ||
} | ||
|
||
fn num_vals(&self) -> u64 { | ||
(self.doc_id_map.num_new_doc_ids() + 1) as u64 | ||
} | ||
|
||
fn iter<'b>(&'b self) -> Box<dyn Iterator<Item = u64> + 'b> { | ||
Box::new(MultivalueStartIndexIter::new(self.column, self.doc_id_map)) | ||
} | ||
} | ||
|
||
struct MultivalueStartIndexIter<'a, C: Column> { | ||
pub column: &'a C, | ||
pub doc_id_map: &'a DocIdMapping, | ||
pub new_doc_id: usize, | ||
pub offset: u64, | ||
} | ||
|
||
impl<'a, C: Column> MultivalueStartIndexIter<'a, C> { | ||
fn new(column: &'a C, doc_id_map: &'a DocIdMapping) -> Self { | ||
Self { | ||
column, | ||
doc_id_map, | ||
new_doc_id: 0, | ||
offset: 0, | ||
} | ||
fn iter(&self) -> Box<dyn Iterator<Item = u64> + '_> { | ||
Box::new(iter_remapped_multivalue_index( | ||
self.doc_id_map, | ||
&self.column, | ||
)) | ||
} | ||
} | ||
|
||
impl<'a, C: Column> Iterator for MultivalueStartIndexIter<'a, C> { | ||
type Item = u64; | ||
|
||
fn next(&mut self) -> Option<Self::Item> { | ||
if self.new_doc_id > self.doc_id_map.num_new_doc_ids() { | ||
return None; | ||
} | ||
let new_doc_id = self.new_doc_id; | ||
self.new_doc_id += 1; | ||
let start_offset = self.offset; | ||
if new_doc_id < self.doc_id_map.num_new_doc_ids() { | ||
let old_doc = self.doc_id_map.get_old_doc_id(new_doc_id as u32) as u64; | ||
let num_vals_for_doc = self.column.get_val(old_doc + 1) - self.column.get_val(old_doc); | ||
self.offset += num_vals_for_doc; | ||
} | ||
Some(start_offset) | ||
} | ||
fn iter_remapped_multivalue_index<'a, C: Column>( | ||
doc_id_map: &'a DocIdMapping, | ||
column: &'a C, | ||
) -> impl Iterator<Item = u64> + 'a { | ||
let mut offset = 0; | ||
doc_id_map | ||
.iter_old_doc_ids() | ||
.chain(std::iter::once(u32::MAX)) | ||
.map(move |old_doc| { | ||
if old_doc == u32::MAX { | ||
// sentinel value for last offset | ||
return offset; | ||
} | ||
Comment on lines
+258
to
+261
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. wouldn't doing the chain below do the same thing?
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. It would, but offset is already owned by the closure |
||
let num_vals_for_doc = | ||
column.get_val(old_doc as u64 + 1) - column.get_val(old_doc as u64); | ||
let start_offset = offset; | ||
offset += num_vals_for_doc; | ||
start_offset | ||
}) | ||
} | ||
|
||
#[cfg(test)] | ||
|
@@ -344,11 +299,5 @@ mod tests { | |
vec![0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55] | ||
); | ||
assert_eq!(multivalue_start_index.num_vals(), 11); | ||
assert_eq!(multivalue_start_index.get_val(3), 2); | ||
assert_eq!(multivalue_start_index.get_val(5), 5); | ||
assert_eq!(multivalue_start_index.get_val(8), 21); | ||
assert_eq!(multivalue_start_index.get_val(4), 3); | ||
assert_eq!(multivalue_start_index.get_val(0), 0); | ||
assert_eq!(multivalue_start_index.get_val(10), 55); | ||
} | ||
} |
This file contains 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 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 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.
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 like the step_by solution.
Can you change the column.num_vals() limit above to 100 too, to make proofreading even easier.
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 don't understand, 100 instead of 100_000?