Fix all clippy error after conflicts

This commit is contained in:
unvalley 2022-10-27 23:58:13 +09:00
parent c7322f704c
commit f4ec1abb9b
11 changed files with 53 additions and 54 deletions

View File

@ -401,7 +401,7 @@ pub mod tests {
fn parse() {
use FilterCondition as Fc;
fn p<'a>(s: &'a str) -> impl std::fmt::Display + 'a {
fn p(s: &str) -> impl std::fmt::Display + '_ {
Fc::parse(s).unwrap().unwrap()
}
@ -494,7 +494,7 @@ pub mod tests {
fn error() {
use FilterCondition as Fc;
fn p<'a>(s: &'a str) -> impl std::fmt::Display + 'a {
fn p(s: &str) -> impl std::fmt::Display + '_ {
Fc::parse(s).unwrap_err().to_string()
}

View File

@ -88,8 +88,7 @@ impl<'a> heed::BytesEncode<'a> for FacetGroupValueCodec {
type EItem = FacetGroupValue;
fn bytes_encode(value: &'a Self::EItem) -> Option<Cow<'a, [u8]>> {
let mut v = vec![];
v.push(value.size);
let mut v = vec![value.size];
CboRoaringBitmapCodec::serialize_into(&value.bitmap, &mut v);
Some(Cow::Owned(v))
}

View File

@ -38,9 +38,9 @@ where
if let Some(first_bound) = get_first_facet_value::<ByteSliceRefCodec>(rtxn, db, field_id)? {
fd.iterate(candidates, highest_level, first_bound, usize::MAX)?;
return Ok(());
Ok(())
} else {
return Ok(());
Ok(())
}
}
@ -84,7 +84,7 @@ where
}
}
}
return Ok(ControlFlow::Continue(()));
Ok(ControlFlow::Continue(()))
}
fn iterate(
&mut self,
@ -98,7 +98,7 @@ where
}
let starting_key =
FacetGroupKey { field_id: self.field_id, level, left_bound: starting_bound };
let iter = self.db.range(&self.rtxn, &(&starting_key..)).unwrap().take(group_size);
let iter = self.db.range(self.rtxn, &(&starting_key..)).unwrap().take(group_size);
for el in iter {
let (key, value) = el.unwrap();
@ -108,7 +108,7 @@ where
return Ok(ControlFlow::Break(()));
}
let docids_in_common = value.bitmap & candidates;
if docids_in_common.len() > 0 {
if !docids_in_common.is_empty() {
let cf = self.iterate(
&docids_in_common,
level - 1,
@ -121,8 +121,7 @@ where
}
}
}
return Ok(ControlFlow::Continue(()));
Ok(ControlFlow::Continue(()))
}
}

View File

@ -60,7 +60,7 @@ where
f.run(highest_level, starting_left_bound, rightmost_bound, group_size)?;
Ok(())
} else {
return Ok(());
Ok(())
}
}
@ -77,7 +77,7 @@ impl<'t, 'b, 'bitmap> FacetRangeSearch<'t, 'b, 'bitmap> {
fn run_level_0(&mut self, starting_left_bound: &'t [u8], group_size: usize) -> Result<()> {
let left_key =
FacetGroupKey { field_id: self.field_id, level: 0, left_bound: starting_left_bound };
let iter = self.db.range(&self.rtxn, &(left_key..))?.take(group_size);
let iter = self.db.range(self.rtxn, &(left_key..))?.take(group_size);
for el in iter {
let (key, value) = el?;
// the right side of the iter range is unbounded, so we need to make sure that we are not iterating
@ -145,7 +145,7 @@ impl<'t, 'b, 'bitmap> FacetRangeSearch<'t, 'b, 'bitmap> {
let left_key =
FacetGroupKey { field_id: self.field_id, level, left_bound: starting_left_bound };
let mut iter = self.db.range(&self.rtxn, &(left_key..))?.take(group_size);
let mut iter = self.db.range(self.rtxn, &(left_key..))?.take(group_size);
// We iterate over the range while keeping in memory the previous value
let (mut previous_key, mut previous_value) = iter.next().unwrap()?;
@ -348,6 +348,7 @@ mod tests {
&mut docids,
)
.unwrap();
#[allow(clippy::format_push_string)]
results.push_str(&format!("{}\n", display_bitmap(&docids)));
}
milli_snap!(results, format!("included_{i}"));
@ -366,6 +367,7 @@ mod tests {
&mut docids,
)
.unwrap();
#[allow(clippy::format_push_string)]
results.push_str(&format!("{}\n", display_bitmap(&docids)));
}
milli_snap!(results, format!("excluded_{i}"));

View File

@ -50,6 +50,7 @@ struct AscendingFacetSort<'t, 'e> {
rtxn: &'t heed::RoTxn<'e>,
db: heed::Database<FacetGroupKeyCodec<ByteSliceRefCodec>, FacetGroupValueCodec>,
field_id: u16,
#[allow(clippy::type_complexity)]
stack: Vec<(
RoaringBitmap,
std::iter::Take<
@ -91,9 +92,9 @@ impl<'t, 'e> Iterator for AscendingFacetSort<'t, 'e> {
}
let starting_key_below =
FacetGroupKey { field_id: self.field_id, level: level - 1, left_bound };
let iter = match self.db.range(&self.rtxn, &(starting_key_below..)) {
let iter = match self.db.range(self.rtxn, &(starting_key_below..)) {
Ok(iter) => iter,
Err(e) => return Some(Err(e.into())),
Err(e) => return Some(Err(e)),
}
.take(group_size as usize);

View File

@ -39,6 +39,7 @@ struct DescendingFacetSort<'t> {
rtxn: &'t heed::RoTxn<'t>,
db: heed::Database<FacetGroupKeyCodec<ByteSliceRefCodec>, FacetGroupValueCodec>,
field_id: u16,
#[allow(clippy::type_complexity)]
stack: Vec<(
RoaringBitmap,
std::iter::Take<
@ -54,7 +55,7 @@ impl<'t> Iterator for DescendingFacetSort<'t> {
fn next(&mut self) -> Option<Self::Item> {
'outer: loop {
let (documents_ids, deepest_iter, right_bound) = self.stack.last_mut()?;
while let Some(result) = deepest_iter.next() {
for result in deepest_iter.by_ref() {
let (
FacetGroupKey { level, left_bound, field_id },
FacetGroupValue { size: group_size, mut bitmap },
@ -100,11 +101,11 @@ impl<'t> Iterator for DescendingFacetSort<'t> {
.db
.remap_key_type::<FacetGroupKeyCodec<ByteSliceRefCodec>>()
.rev_range(
&self.rtxn,
self.rtxn,
&(Bound::Included(starting_key_below), end_key_kelow),
) {
Ok(iter) => iter,
Err(e) => return Some(Err(e.into())),
Err(e) => return Some(Err(e)),
}
.take(group_size as usize);

View File

@ -73,7 +73,7 @@ pub(crate) fn get_highest_level<'t>(
let field_id_prefix = &field_id.to_be_bytes();
Ok(db
.as_polymorph()
.rev_prefix_iter::<_, ByteSlice, DecodeIgnore>(&txn, field_id_prefix)?
.rev_prefix_iter::<_, ByteSlice, DecodeIgnore>(txn, field_id_prefix)?
.next()
.map(|el| {
let (key, _) = el.unwrap();
@ -105,12 +105,9 @@ pub(crate) mod tests {
pub fn get_random_looking_index() -> FacetIndex<OrderedF64Codec> {
let index = FacetIndex::<OrderedF64Codec>::new(4, 8, 5);
let mut txn = index.env.write_txn().unwrap();
let mut rng = rand::rngs::SmallRng::from_seed([0; 32]);
let keys =
std::iter::from_fn(|| Some(rng.gen_range(0..256))).take(128).collect::<Vec<u32>>();
for (_i, key) in keys.into_iter().enumerate() {
for (_i, key) in std::iter::from_fn(|| Some(rng.gen_range(0..256))).take(128).enumerate() {
let mut bitmap = RoaringBitmap::new();
bitmap.insert(key);
bitmap.insert(key + 100);

View File

@ -138,7 +138,7 @@ impl<'t, 'u, 'i> DeleteDocuments<'t, 'u, 'i> {
// the `soft_deleted_documents_ids` bitmap and early exit.
let size_used = self.index.used_size()?;
let map_size = self.index.env.map_size()? as u64;
let nb_documents = self.index.number_of_documents(&self.wtxn)?;
let nb_documents = self.index.number_of_documents(self.wtxn)?;
let nb_soft_deleted = soft_deleted_docids.len();
let percentage_available = 100 - (size_used * 100 / map_size);
@ -474,7 +474,7 @@ impl<'t, 'u, 'i> DeleteDocuments<'t, 'u, 'i> {
self.index.put_faceted_documents_ids(self.wtxn, field_id, facet_type, &docids)?;
let facet_values = remove_docids_from_field_id_docid_facet_value(
&self.index,
self.index,
self.wtxn,
facet_type,
field_id,

View File

@ -111,7 +111,7 @@ impl<R: std::io::Read + std::io::Seek> FacetsUpdateBulkInner<R> {
}
for &field_id in field_ids.iter() {
let (level_readers, all_docids) = self.compute_levels_for_field_id(field_id, &wtxn)?;
let (level_readers, all_docids) = self.compute_levels_for_field_id(field_id, wtxn)?;
handle_all_docids(wtxn, field_id, all_docids)?;
@ -341,7 +341,7 @@ impl<R: std::io::Read + std::io::Seek> FacetsUpdateBulkInner<R> {
handle_group(&bitmaps, left_bounds.first().unwrap())?;
}
}
return Ok(sub_writers);
Ok(sub_writers)
}
}

View File

@ -100,7 +100,7 @@ impl<'i, 'b> FacetsDelete<'i, 'b> {
max_group_size: self.max_group_size,
};
for facet_value in affected_facet_values {
inc.delete(wtxn, field_id, facet_value.as_slice(), &self.docids_to_delete)?;
inc.delete(wtxn, field_id, facet_value.as_slice(), self.docids_to_delete)?;
}
}
}

View File

@ -127,7 +127,7 @@ impl FacetsUpdateIncrementalInner {
if let Some(e) = prefix_iter.next() {
let (key_bytes, value) = e?;
Ok((
FacetGroupKeyCodec::<ByteSliceRefCodec>::bytes_decode(&key_bytes)
FacetGroupKeyCodec::<ByteSliceRefCodec>::bytes_decode(key_bytes)
.ok_or(Error::Encoding)?
.into_owned(),
value,
@ -146,11 +146,11 @@ impl FacetsUpdateIncrementalInner {
.as_polymorph()
.prefix_iter::<_, ByteSlice, FacetGroupValueCodec>(
txn,
&prefix.as_slice(),
prefix.as_slice(),
)?;
let (key_bytes, value) = iter.next().unwrap()?;
Ok((
FacetGroupKeyCodec::<ByteSliceRefCodec>::bytes_decode(&key_bytes)
FacetGroupKeyCodec::<ByteSliceRefCodec>::bytes_decode(key_bytes)
.ok_or(Error::Encoding)?
.into_owned(),
value,
@ -185,15 +185,15 @@ impl FacetsUpdateIncrementalInner {
let mut iter = self
.db
.as_polymorph()
.prefix_iter::<_, ByteSlice, DecodeIgnore>(&txn, &level0_prefix)?;
.prefix_iter::<_, ByteSlice, DecodeIgnore>(txn, &level0_prefix)?;
if iter.next().is_none() {
drop(iter);
self.db.put(txn, &key, &value)?;
return Ok(InsertionResult::Insert);
Ok(InsertionResult::Insert)
} else {
drop(iter);
let old_value = self.db.get(&txn, &key)?;
let old_value = self.db.get(txn, &key)?;
match old_value {
Some(mut updated_value) => {
// now merge the two
@ -236,7 +236,7 @@ impl FacetsUpdateIncrementalInner {
let max_group_size = self.max_group_size;
let result = self.insert_in_level(txn, field_id, level - 1, facet_value.clone(), docids)?;
let result = self.insert_in_level(txn, field_id, level - 1, &(*facet_value), docids)?;
// level below inserted an element
let (insertion_key, insertion_value) =
@ -312,13 +312,13 @@ impl FacetsUpdateIncrementalInner {
};
let mut iter =
self.db.range(&txn, &(start_key..))?.take((size_left as usize) + (size_right as usize));
self.db.range(txn, &(start_key..))?.take((size_left as usize) + (size_right as usize));
let group_left = {
let mut values_left = RoaringBitmap::new();
let mut i = 0;
while let Some(next) = iter.next() {
for next in iter.by_ref() {
let (_key, value) = next?;
i += 1;
values_left |= &value.bitmap;
@ -339,7 +339,7 @@ impl FacetsUpdateIncrementalInner {
FacetGroupValue { bitmap: mut values_right, .. },
) = iter.next().unwrap()?;
while let Some(next) = iter.next() {
for next in iter.by_ref() {
let (_, value) = next?;
values_right |= &value.bitmap;
}
@ -359,7 +359,7 @@ impl FacetsUpdateIncrementalInner {
}
/// Insert the given facet value and corresponding document ids in the database.
pub fn insert<'a, 't>(
pub fn insert<'t>(
&self,
txn: &'t mut RwTxn,
field_id: u16,
@ -371,7 +371,7 @@ impl FacetsUpdateIncrementalInner {
}
let group_size = self.group_size;
let highest_level = get_highest_level(&txn, self.db, field_id)?;
let highest_level = get_highest_level(txn, self.db, field_id)?;
let result =
self.insert_in_level(txn, field_id, highest_level as u8, facet_value, docids)?;
@ -391,7 +391,7 @@ impl FacetsUpdateIncrementalInner {
let size_highest_level = self
.db
.as_polymorph()
.prefix_iter::<_, ByteSlice, ByteSlice>(&txn, &highest_level_prefix)?
.prefix_iter::<_, ByteSlice, ByteSlice>(txn, &highest_level_prefix)?
.count();
if size_highest_level < self.group_size as usize * self.min_level_size as usize {
@ -401,7 +401,7 @@ impl FacetsUpdateIncrementalInner {
let mut groups_iter = self
.db
.as_polymorph()
.prefix_iter::<_, ByteSlice, FacetGroupValueCodec>(&txn, &highest_level_prefix)?;
.prefix_iter::<_, ByteSlice, FacetGroupValueCodec>(txn, &highest_level_prefix)?;
let nbr_new_groups = size_highest_level / self.group_size as usize;
let nbr_leftover_elements = size_highest_level % self.group_size as usize;
@ -412,7 +412,7 @@ impl FacetsUpdateIncrementalInner {
let mut values = RoaringBitmap::new();
for _ in 0..group_size {
let (key_bytes, value_i) = groups_iter.next().unwrap()?;
let key_i = FacetGroupKeyCodec::<ByteSliceRefCodec>::bytes_decode(&key_bytes)
let key_i = FacetGroupKeyCodec::<ByteSliceRefCodec>::bytes_decode(key_bytes)
.ok_or(Error::Encoding)?;
if first_key.is_none() {
@ -435,7 +435,7 @@ impl FacetsUpdateIncrementalInner {
let mut values = RoaringBitmap::new();
for _ in 0..nbr_leftover_elements {
let (key_bytes, value_i) = groups_iter.next().unwrap()?;
let key_i = FacetGroupKeyCodec::<ByteSliceRefCodec>::bytes_decode(&key_bytes)
let key_i = FacetGroupKeyCodec::<ByteSliceRefCodec>::bytes_decode(key_bytes)
.ok_or(Error::Encoding)?;
if first_key.is_none() {
@ -494,7 +494,7 @@ impl FacetsUpdateIncrementalInner {
let (deletion_key, mut bitmap) =
self.find_insertion_key_value(field_id, level, facet_value, txn)?;
let result = self.delete_in_level(txn, field_id, level - 1, facet_value.clone(), docids)?;
let result = self.delete_in_level(txn, field_id, level - 1, &(*facet_value), docids)?;
let mut decrease_size = false;
let next_key = match result {
@ -547,13 +547,13 @@ impl FacetsUpdateIncrementalInner {
docids: &RoaringBitmap,
) -> Result<DeletionResult> {
let key = FacetGroupKey { field_id, level: 0, left_bound: facet_value };
let mut bitmap = self.db.get(&txn, &key)?.unwrap().bitmap;
let mut bitmap = self.db.get(txn, &key)?.unwrap().bitmap;
bitmap -= docids;
if bitmap.is_empty() {
let mut next_key = None;
if let Some((next, _)) =
self.db.remap_data_type::<DecodeIgnore>().get_greater_than(&txn, &key)?
self.db.remap_data_type::<DecodeIgnore>().get_greater_than(txn, &key)?
{
if next.field_id == field_id && next.level == 0 {
next_key = Some(next.left_bound.to_vec());
@ -567,7 +567,7 @@ impl FacetsUpdateIncrementalInner {
}
}
pub fn delete<'a, 't>(
pub fn delete<'t>(
&self,
txn: &'t mut RwTxn,
field_id: u16,
@ -582,7 +582,7 @@ impl FacetsUpdateIncrementalInner {
{
return Ok(());
}
let highest_level = get_highest_level(&txn, self.db, field_id)?;
let highest_level = get_highest_level(txn, self.db, field_id)?;
let result =
self.delete_in_level(txn, field_id, highest_level as u8, facet_value, docids)?;
@ -603,7 +603,7 @@ impl FacetsUpdateIncrementalInner {
|| self
.db
.as_polymorph()
.prefix_iter::<_, ByteSlice, ByteSlice>(&txn, &highest_level_prefix)?
.prefix_iter::<_, ByteSlice, ByteSlice>(txn, &highest_level_prefix)?
.count()
>= self.min_level_size as usize
{
@ -614,7 +614,7 @@ impl FacetsUpdateIncrementalInner {
.db
.as_polymorph()
.prefix_iter::<_, ByteSlice, ByteSlice>(txn, &highest_level_prefix)?;
while let Some(el) = iter.next() {
for el in iter.by_ref() {
let (k, _) = el?;
to_delete.push(
FacetGroupKeyCodec::<ByteSliceRefCodec>::bytes_decode(k)
@ -640,7 +640,7 @@ impl<'a> FacetGroupKey<&'a [u8]> {
}
}
impl<'a> FacetGroupKey<Vec<u8>> {
impl FacetGroupKey<Vec<u8>> {
pub fn as_ref(&self) -> FacetGroupKey<&[u8]> {
FacetGroupKey {
field_id: self.field_id,
@ -804,7 +804,7 @@ mod tests {
let mut bitmap = RoaringBitmap::new();
bitmap.insert(i);
index.verify_structure_validity(&txn, 0);
index.insert(&mut txn, 0, &(&(i as f64)), &bitmap);
index.insert(&mut txn, 0, &(i as f64), &bitmap);
}
for i in (200..256).into_iter().rev() {