Skip to content
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

GCD wrapper uses DividerU64 #1478

Merged
merged 1 commit into from
Aug 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion fastfield_codecs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub trait FastFieldDataAccess {
fn get_val(&self, position: u64) -> u64;

/// Returns a iterator over the data
fn iter<'a>(&'a self) -> Box<dyn Iterator<Item = u64> + 'a>;
fn iter(&self) -> Box<dyn Iterator<Item = u64> + '_>;

/// min value of the data
fn min_value(&self) -> u64;
Expand Down
13 changes: 8 additions & 5 deletions src/fastfield/serializer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::io::{self, Write};
use std::num::NonZeroU64;

use common::{BinarySerializable, CountingWriter};
use fastdivide::DividerU64;
pub use fastfield_codecs::bitpacked::{
BitpackedFastFieldSerializer, BitpackedFastFieldSerializerLegacy,
};
Expand Down Expand Up @@ -142,17 +143,19 @@ impl CompositeFastFieldSerializer {
base_value: u64,
max_value: u64,
num_vals: u64,
gcd: u64,
gcd: DividerU64,
}

impl<T: FastFieldDataAccess> FastFieldDataAccess for GCDWrappedFFAccess<T> {
fn get_val(&self, position: u64) -> u64 {
(self.fastfield_accessor.get_val(position) - self.base_value) / self.gcd
self.gcd
.divide(self.fastfield_accessor.get_val(position) - self.base_value)
}
fn iter<'b>(&'b self) -> Box<dyn Iterator<Item = u64> + 'b> {
fn iter(&self) -> Box<dyn Iterator<Item = u64> + '_> {
Box::new(
self.fastfield_accessor
.iter()
.map(|val| (val - self.base_value) / self.gcd),
.map(|val| self.gcd.divide(val - self.base_value)),
Copy link
Contributor

@PSeitz PSeitz Aug 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you release a new version of fastdivide with the Div impl, the code could stay the same, which is more readable

)
}
fn min_value(&self) -> u64 {
Expand All @@ -177,7 +180,7 @@ impl CompositeFastFieldSerializer {
base_value,
max_value,
num_vals,
gcd,
gcd: DividerU64::divide_by(gcd),
};

Self::create_auto_detect_u64_fast_field_with_idx_gcd(
Expand Down
2 changes: 1 addition & 1 deletion src/fastfield/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ impl<'map, 'bitp> FastFieldDataAccess for WriterFastFieldAccessProvider<'map, 'b
}
}

fn iter<'a>(&'a self) -> Box<dyn Iterator<Item = u64> + 'a> {
fn iter(&self) -> Box<dyn Iterator<Item = u64> + '_> {
if let Some(doc_id_map) = self.doc_id_map {
Box::new(
doc_id_map
Expand Down
6 changes: 3 additions & 3 deletions src/indexer/merger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ impl IndexMerger {
self.fast_field_readers[segment_ord as usize].get(doc_id)
}

fn iter<'b>(&'b self) -> Box<dyn Iterator<Item = u64> + 'b> {
fn iter(&self) -> Box<dyn Iterator<Item = u64> + '_> {
Box::new(
self.doc_id_mapping
.iter_old_doc_addrs()
Expand Down Expand Up @@ -583,7 +583,7 @@ impl IndexMerger {
self.offsets[doc as usize]
}

fn iter<'b>(&'b self) -> Box<dyn Iterator<Item = u64> + 'b> {
fn iter(&self) -> Box<dyn Iterator<Item = u64> + '_> {
Box::new(self.offsets.iter().cloned())
}
fn min_value(&self) -> u64 {
Expand Down Expand Up @@ -804,7 +804,7 @@ impl IndexMerger {
vals[pos_in_values as usize]
}

fn iter<'b>(&'b self) -> Box<dyn Iterator<Item = u64> + 'b> {
fn iter(&self) -> Box<dyn Iterator<Item = u64> + '_> {
Box::new(
self.doc_id_mapping
.iter_old_doc_addrs()
Expand Down