Skip to content

Commit 7b66110

Browse files
committed
Make the new Clippy happy
1 parent 7bc9350 commit 7b66110

File tree

14 files changed

+52
-39
lines changed

14 files changed

+52
-39
lines changed

benches/benchmark.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
use hannoy::{distances::Cosine, Database, Writer};
1+
use hannoy::distances::Cosine;
2+
use hannoy::{Database, Writer};
23
use heed::{Env, EnvOpenOptions, RwTxn};
3-
use rand::{rngs::StdRng, Rng, SeedableRng};
4+
use rand::rngs::StdRng;
5+
use rand::{Rng, SeedableRng};
46
use tempfile::tempdir;
57

68
static M: usize = 16;
@@ -31,7 +33,7 @@ mod hnsw {
3133
fn create_db_and_fill_with_vecs<const DIM: usize>(
3234
env: &Env,
3335
size: usize,
34-
) -> hannoy::Result<(Writer<Cosine>, RwTxn, Database<Cosine>)> {
36+
) -> hannoy::Result<(Writer<Cosine>, RwTxn<'_>, Database<Cosine>)> {
3537
let mut wtxn = env.write_txn().unwrap();
3638

3739
let db: Database<Cosine> = env.create_database(&mut wtxn, None)?;

src/distance/hamming.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
use std::fmt;
22

3+
use bytemuck::{Pod, Zeroable};
4+
35
use crate::distance::Distance;
46
use crate::node::Item;
57
use crate::unaligned_vector::{Binary, UnalignedVector};
6-
use bytemuck::{Pod, Zeroable};
78

89
/// The Hamming distance between two vectors is the number of positions at
910
/// which the corresponding symbols are different.
@@ -70,7 +71,7 @@ pub fn hamming_bitwise_fast(u: &[u8], v: &[u8]) -> f32 {
7071
})
7172
.sum::<u32>();
7273

73-
if u.len() % CHUNK_SIZE != 0 {
74+
if !u.len().is_multiple_of(CHUNK_SIZE) {
7475
distance += u
7576
.chunks_exact(CHUNK_SIZE)
7677
.remainder()

src/error.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
use std::io;
22

3-
use crate::{key::Key, node_id::NodeMode, version::Version, ItemId, LayerId};
3+
use crate::key::Key;
4+
use crate::node_id::NodeMode;
5+
use crate::version::Version;
6+
use crate::{ItemId, LayerId};
47

58
/// The different set of errors that hannoy can encounter.
69
#[derive(Debug, thiserror::Error)]

src/hnsw.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,8 @@ impl<'a, D: Distance, const M: usize, const M0: usize> HnswBuilder<'a, D, M, M0>
169169

170170
level_groups.into_iter().try_for_each(|grp| {
171171
grp.into_par_iter().try_for_each(|&(item_id, lvl)| {
172-
if cancel_index.fetch_add(1, Relaxed) % CANCELLATION_PROBING == 0 && (self.cancel)()
172+
if cancel_index.fetch_add(1, Relaxed).is_multiple_of(CANCELLATION_PROBING)
173+
&& (self.cancel)()
173174
{
174175
Err(Error::BuildCancelled)
175176
} else {
@@ -362,7 +363,7 @@ impl<'a, D: Distance, const M: usize, const M0: usize> HnswBuilder<'a, D, M, M0>
362363
let cancel_index = AtomicUsize::new(0);
363364

364365
links_in_db.into_par_iter().try_for_each(|result| {
365-
if cancel_index.fetch_add(1, Ordering::Relaxed) % CANCELLATION_PROBING == 0
366+
if cancel_index.fetch_add(1, Ordering::Relaxed).is_multiple_of(CANCELLATION_PROBING)
366367
&& (self.cancel)()
367368
{
368369
return Err(Error::BuildCancelled);

src/metadata.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ impl<'a> heed::BytesEncode<'a> for MetadataCodec {
2424

2525
fn bytes_encode(item: &'a Self::EItem) -> Result<Cow<'a, [u8]>, BoxedError> {
2626
let Metadata { dimensions, items, entry_points, distance, max_level } = item;
27-
debug_assert!(!distance.as_bytes().iter().any(|&b| b == 0));
27+
debug_assert!(!distance.as_bytes().contains(&0));
2828

2929
let mut output = Vec::with_capacity(
3030
size_of::<u32>()

src/node.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,11 +189,15 @@ impl fmt::Display for InvalidNodeDecoding {
189189

190190
#[cfg(test)]
191191
mod tests {
192-
use super::{Item, Links, Node, NodeCodec};
193-
use crate::{distance::Cosine, internals::UnalignedVector, Distance};
192+
use std::borrow::Cow;
193+
194194
use heed::{BytesDecode, BytesEncode};
195195
use roaring::RoaringBitmap;
196-
use std::borrow::Cow;
196+
197+
use super::{Item, Links, Node, NodeCodec};
198+
use crate::distance::Cosine;
199+
use crate::internals::UnalignedVector;
200+
use crate::Distance;
197201

198202
#[test]
199203
fn check_bytes_encode_decode() {

src/python.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
//! Python bindings for hannoy.
2+
use std::path::PathBuf;
3+
use std::sync::LazyLock;
4+
25
use heed::{RoTxn, RwTxn, WithoutTls};
36
use once_cell::sync::OnceCell;
47
use parking_lot::{MappedMutexGuard, Mutex, MutexGuard};
5-
use pyo3::{
6-
exceptions::{PyIOError, PyRuntimeError},
7-
prelude::*,
8-
types::PyType,
9-
};
10-
use pyo3_stub_gen::{
11-
define_stub_info_gatherer,
12-
derive::{gen_stub_pyclass, gen_stub_pyclass_enum, gen_stub_pymethods},
13-
};
14-
use std::{path::PathBuf, sync::LazyLock};
8+
use pyo3::exceptions::{PyIOError, PyRuntimeError};
9+
use pyo3::prelude::*;
10+
use pyo3::types::PyType;
11+
use pyo3_stub_gen::define_stub_info_gatherer;
12+
use pyo3_stub_gen::derive::{gen_stub_pyclass, gen_stub_pyclass_enum, gen_stub_pymethods};
1513

1614
use crate::{distance, Database, ItemId, Reader, Writer};
1715
static DEFAULT_ENV_SIZE: usize = 1024 * 1024 * 1024; // 1GiB
@@ -257,7 +255,8 @@ pub(super) struct PyWriter {
257255

258256
impl PyWriter {
259257
fn build(&self) -> PyResult<()> {
260-
use rand::{rngs::StdRng, SeedableRng};
258+
use rand::rngs::StdRng;
259+
use rand::SeedableRng;
261260

262261
let mut rng = StdRng::seed_from_u64(42);
263262
let mut wtxn = get_rw_txn()?;

src/reader.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,14 +198,15 @@ impl<D: Distance> Reader<D> {
198198
index: u16,
199199
metadata: &Metadata,
200200
) -> Result<()> {
201-
use crate::unaligned_vector::UnalignedVectorCodec;
201+
use std::collections::VecDeque;
202+
use std::sync::atomic::{AtomicUsize, Ordering};
202203

203204
use heed::types::Bytes;
204205
use madvise::AccessPattern;
205-
use std::collections::VecDeque;
206-
use std::sync::atomic::{AtomicUsize, Ordering};
207206
use tracing::warn;
208207

208+
use crate::unaligned_vector::UnalignedVectorCodec;
209+
209210
let page_size = page_size::get();
210211
let mut available_memory: usize = std::env::var(READER_AVAILABLE_MEMORY)
211212
.ok()

src/spaces/simple.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ pub fn dot_product_non_optimized(u: &UnalignedVector<f32>, v: &UnalignedVector<f
102102
///
103103
/// 2. Then we need to do the sum of the results:
104104
/// 2.1 First we must do the sum of the operation on the `Word`s
105-
/// /!\ We must be careful here because `1 - 0` actually translates to `1 - 1 = 0`.
106-
/// `word.count_ones() - word.count_zeroes()` should do it:
105+
/// /!\ We must be careful here because `1 - 0` actually translates to `1 - 1 = 0`.
106+
/// `word.count_ones() - word.count_zeroes()` should do it:
107107
/// ```text
108108
/// 00 => -2
109109
/// 01 => 0

src/spaces/simple_neon.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
#[cfg(target_feature = "neon")]
2-
use crate::unaligned_vector::UnalignedVector;
31
use std::arch::aarch64::*;
42
use std::ptr::read_unaligned;
53

4+
#[cfg(target_feature = "neon")]
5+
use crate::unaligned_vector::UnalignedVector;
6+
67
#[cfg(target_feature = "neon")]
78
pub(crate) unsafe fn euclid_similarity_neon(
89
v1: &UnalignedVector<f32>,

0 commit comments

Comments
 (0)