From c45f98cc4ff815ea1fe6e591524661a5aee2bdbc Mon Sep 17 00:00:00 2001 From: Paul Masurel Date: Wed, 24 Aug 2022 19:10:35 +0200 Subject: [PATCH] GCD wrapper uses DividerU64 --- fastfield_codecs/src/lib.rs | 2 +- src/fastfield/serializer/mod.rs | 13 ++++++++----- src/fastfield/writer.rs | 2 +- src/indexer/merger.rs | 6 +++--- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/fastfield_codecs/src/lib.rs b/fastfield_codecs/src/lib.rs index 0641f144c5..666e7ab9d8 100644 --- a/fastfield_codecs/src/lib.rs +++ b/fastfield_codecs/src/lib.rs @@ -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 + 'a>; + fn iter(&self) -> Box + '_>; /// min value of the data fn min_value(&self) -> u64; diff --git a/src/fastfield/serializer/mod.rs b/src/fastfield/serializer/mod.rs index cd07e03ca0..90fcaeada6 100644 --- a/src/fastfield/serializer/mod.rs +++ b/src/fastfield/serializer/mod.rs @@ -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, }; @@ -142,17 +143,19 @@ impl CompositeFastFieldSerializer { base_value: u64, max_value: u64, num_vals: u64, - gcd: u64, + gcd: DividerU64, } + impl FastFieldDataAccess for GCDWrappedFFAccess { 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 + 'b> { + fn iter(&self) -> Box + '_> { Box::new( self.fastfield_accessor .iter() - .map(|val| (val - self.base_value) / self.gcd), + .map(|val| self.gcd.divide(val - self.base_value)), ) } fn min_value(&self) -> u64 { @@ -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( diff --git a/src/fastfield/writer.rs b/src/fastfield/writer.rs index a91bd8f729..0cef6a905a 100644 --- a/src/fastfield/writer.rs +++ b/src/fastfield/writer.rs @@ -403,7 +403,7 @@ impl<'map, 'bitp> FastFieldDataAccess for WriterFastFieldAccessProvider<'map, 'b } } - fn iter<'a>(&'a self) -> Box + 'a> { + fn iter(&self) -> Box + '_> { if let Some(doc_id_map) = self.doc_id_map { Box::new( doc_id_map diff --git a/src/indexer/merger.rs b/src/indexer/merger.rs index bf9a64edeb..d1c71dae79 100644 --- a/src/indexer/merger.rs +++ b/src/indexer/merger.rs @@ -385,7 +385,7 @@ impl IndexMerger { self.fast_field_readers[segment_ord as usize].get(doc_id) } - fn iter<'b>(&'b self) -> Box + 'b> { + fn iter(&self) -> Box + '_> { Box::new( self.doc_id_mapping .iter_old_doc_addrs() @@ -583,7 +583,7 @@ impl IndexMerger { self.offsets[doc as usize] } - fn iter<'b>(&'b self) -> Box + 'b> { + fn iter(&self) -> Box + '_> { Box::new(self.offsets.iter().cloned()) } fn min_value(&self) -> u64 { @@ -804,7 +804,7 @@ impl IndexMerger { vals[pos_in_values as usize] } - fn iter<'b>(&'b self) -> Box + 'b> { + fn iter(&self) -> Box + '_> { Box::new( self.doc_id_mapping .iter_old_doc_addrs()