Skip to content

Commit

Permalink
use binary search instead of linear for get_val in merge (#1548)
Browse files Browse the repository at this point in the history
* use binary search instead of linear for get_val in merge

* use partition_point
  • Loading branch information
PSeitz authored Sep 26, 2022
1 parent ea8e6d7 commit 21e0ade
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/indexer/sorted_doc_id_multivalue_column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,9 @@ impl<'a> SortedDocIdMultiValueColumn<'a> {
impl<'a> Column for SortedDocIdMultiValueColumn<'a> {
fn get_val(&self, pos: u64) -> u64 {
// use the offsets index to find the doc_id which will contain the position.
// the offsets are strictly increasing so we can do a simple search on it.
let new_doc_id: DocId = self
.offsets
.iter()
.position(|&offset| offset > pos)
.expect("pos is out of bounds") as DocId
- 1u32;
// the offsets are strictly increasing so we can do a binary search on it.

let new_doc_id: DocId = self.offsets.partition_point(|&offset| offset <= pos) as DocId - 1; // Offsets start at 0, so -1 is safe

// now we need to find the position of `pos` in the multivalued bucket
let num_pos_covered_until_now = self.offsets[new_doc_id as usize];
Expand Down

0 comments on commit 21e0ade

Please sign in to comment.