Skip to content

Commit

Permalink
more clippy for rust 1.83 ('elision)
Browse files Browse the repository at this point in the history
  • Loading branch information
jean-pierreBoth committed Dec 19, 2024
1 parent f54f9af commit 7ba4a86
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 24 deletions.
11 changes: 4 additions & 7 deletions src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub trait AnnT {
fn file_dump(&self, path: &Path, file_basename: &str) -> anyhow::Result<String>;
}

impl<'b, T, D> AnnT for Hnsw<'b, T, D>
impl<T, D> AnnT for Hnsw<'_, T, D>
where
T: Serialize + DeserializeOwned + Clone + Send + Sync,
D: Distance<T> + Send + Sync,
Expand All @@ -63,12 +63,9 @@ where
self.parallel_search(data, knbn, ef_s)
}

/// The main entry point to do a dump.
/// It will generate two files one for the graph part of the data. The other for the real data points of the structure.
/// The names of file are $filename.hnsw.graph for the graph and $filename.hnsw.data.
///
///
// The main entry point to do a dump.
// It will generate two files one for the graph part of the data. The other for the real data points of the structure.
// The names of file are $filename.hnsw.graph for the graph and $filename.hnsw.data.
fn file_dump(&self, path: &Path, file_basename: &str) -> anyhow::Result<String> {
info!("In Hnsw::file_dump");
//
Expand Down
2 changes: 1 addition & 1 deletion src/datamap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ impl DataMap {
/// returns Keys in order they are in the file, thus optimizing file/memory access.
/// Note that in case of parallel insertion this can be different from insertion odrer.
pub fn get_dataid_iter(&self) -> indexmap::map::Keys<DataId, usize> {
return self.hmap.keys();
self.hmap.keys()
}

/// returns full data type name
Expand Down
2 changes: 1 addition & 1 deletion src/flatten.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ impl FlatNeighborhood {
}
} // end impl block for FlatNeighborhood

impl<'b, T: Clone + Send + Sync, D: Distance<T> + Send + Sync> From<&Hnsw<'b, T, D>>
impl<T: Clone + Send + Sync, D: Distance<T> + Send + Sync> From<&Hnsw<'_, T, D>>
for FlatNeighborhood
{
/// extract from the Hnsw strucure a hashtable mapping original DataId into a FlatPoint structure gathering its neighbourhood information.
Expand Down
18 changes: 9 additions & 9 deletions src/hnsw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl PartialOrd for PointIdWithOrder {
} // end cmp
} // end impl PartialOrd

impl<'b, T: Send + Sync + Clone + Copy> From<&PointWithOrder<'b, T>> for PointIdWithOrder {
impl<T: Send + Sync + Clone + Copy> From<&PointWithOrder<'_, T>> for PointIdWithOrder {
fn from(point: &PointWithOrder<T>) -> PointIdWithOrder {
PointIdWithOrder::new(point.point_ref.p_id, point.dist_to_ref)
}
Expand Down Expand Up @@ -270,23 +270,23 @@ pub(crate) struct PointWithOrder<'b, T: Clone + Send + Sync> {
dist_to_ref: f32,
}

impl<'b, T: Clone + Send + Sync> PartialEq for PointWithOrder<'b, T> {
impl<T: Clone + Send + Sync> PartialEq for PointWithOrder<'_, T> {
fn eq(&self, other: &PointWithOrder<T>) -> bool {
self.dist_to_ref == other.dist_to_ref
} // end eq
}

impl<'b, T: Clone + Send + Sync> Eq for PointWithOrder<'b, T> {}
impl<T: Clone + Send + Sync> Eq for PointWithOrder<'_, T> {}

// order points by distance to self.
#[allow(clippy::non_canonical_partial_ord_impl)]
impl<'b, T: Clone + Send + Sync> PartialOrd for PointWithOrder<'b, T> {
impl<T: Clone + Send + Sync> PartialOrd for PointWithOrder<'_, T> {
fn partial_cmp(&self, other: &PointWithOrder<T>) -> Option<Ordering> {
self.dist_to_ref.partial_cmp(&other.dist_to_ref)
} // end cmp
} // end impl PartialOrd

impl<'b, T: Clone + Send + Sync> Ord for PointWithOrder<'b, T> {
impl<T: Clone + Send + Sync> Ord for PointWithOrder<'_, T> {
fn cmp(&self, other: &PointWithOrder<T>) -> Ordering {
if !self.dist_to_ref.is_nan() && !other.dist_to_ref.is_nan() {
self.dist_to_ref.partial_cmp(&other.dist_to_ref).unwrap()
Expand Down Expand Up @@ -375,7 +375,7 @@ impl LayerGenerator {
log::info!("using scale for sampling levels : {:.2e}", self.scale);
}

///
//
fn get_level_scale(&self) -> f64 {
self.scale
}
Expand Down Expand Up @@ -406,7 +406,7 @@ pub struct PointIndexation<'b, T: Clone + Send + Sync> {
// A point indexation may contain circular references. To deallocate these after a point indexation goes out of scope,
// implement the Drop trait.

impl<'b, T: Clone + Send + Sync> Drop for PointIndexation<'b, T> {
impl<T: Clone + Send + Sync> Drop for PointIndexation<'_, T> {
fn drop(&mut self) {
let cpu_start = ProcessTime::now();
let sys_now = SystemTime::now();
Expand Down Expand Up @@ -643,7 +643,7 @@ impl<'a, 'b, T: Clone + Send + Sync> IterPoint<'a, 'b, T> {
} // end of block impl IterPoint

/// iterator for layer 0 to upper layer.
impl<'a, 'b, T: Clone + Send + Sync> Iterator for IterPoint<'a, 'b, T> {
impl<'b, T: Clone + Send + Sync> Iterator for IterPoint<'_, 'b, T> {
type Item = Arc<Point<'b, T>>;
//
fn next(&mut self) -> Option<Self::Item> {
Expand Down Expand Up @@ -711,7 +711,7 @@ impl<'a, 'b, T: Clone + Send + Sync> IterPointLayer<'a, 'b, T> {
} // end of block impl IterPointLayer

/// iterator for layer 0 to upper layer.
impl<'a, 'b, T: Clone + Send + Sync + 'b> Iterator for IterPointLayer<'a, 'b, T> {
impl<'b, T: Clone + Send + Sync + 'b> Iterator for IterPointLayer<'_, 'b, T> {
type Item = Arc<Point<'b, T>>;
//
fn next(&mut self) -> Option<Self::Item> {
Expand Down
8 changes: 4 additions & 4 deletions src/hnswio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ pub struct HnswIo {
impl HnswIo {
/// - directory is directory containing the dumped files,
/// - basename is used to build $basename.hnsw.data and $basename.hnsw.graph
///
/// default is to use default ReloadOptions.
pub fn new(directory: &Path, basename: &str) -> Self {
HnswIo {
Expand Down Expand Up @@ -1055,7 +1056,7 @@ pub fn load_description(io_in: &mut dyn Read) -> Result<Description> {
/// 1. The value MAGICDATAP (u32)
/// 2. origin_id as a u64
/// 3. The vector of data (the length is known from Description)
///
fn dump_point<T: Serialize + Clone + Sized + Send + Sync, W: Write>(
point: &Point<T>,
mode: DumpMode,
Expand Down Expand Up @@ -1295,7 +1296,7 @@ fn load_point_graph(graph_in: &mut dyn Read, descr: &Description) -> Result<Poin
// . list of point of layer
// dump entry point
//
impl<'b, T: Serialize + DeserializeOwned + Clone + Send + Sync> HnswIoT for PointIndexation<'b, T> {
impl<T: Serialize + DeserializeOwned + Clone + Send + Sync> HnswIoT for PointIndexation<'_, T> {
fn dump(&self, mode: DumpMode, dumpinit: &mut DumpInit) -> Result<i32> {
let graphout = &mut dumpinit.graph_out;
let dataout = &mut dumpinit.data_out;
Expand Down Expand Up @@ -1343,10 +1344,9 @@ impl<'b, T: Serialize + DeserializeOwned + Clone + Send + Sync> HnswIoT for Poin
//

impl<
'b,
T: Serialize + DeserializeOwned + Clone + Sized + Send + Sync,
D: Distance<T> + Send + Sync,
> HnswIoT for Hnsw<'b, T, D>
> HnswIoT for Hnsw<'_, T, D>
{
/// The dump method for hnsw.
/// - graphout is a BufWriter dedicated to the dump of the graph part of Hnsw
Expand Down
5 changes: 3 additions & 2 deletions src/libext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ use crate::hnswio::*;

/// returns a pointer to a Hnswio
/// args corresponds to string giving base filename of dump, supposed to be in current directory
/// # Safety
/// pointer must be char* pointer to the string
#[no_mangle]
pub unsafe extern "C" fn get_hnswio(flen: u64, name: *const u8) -> *const HnswIo {
let slice = unsafe { std::slice::from_raw_parts(name, flen as usize) };
Expand Down Expand Up @@ -101,7 +103,6 @@ super::declare_myapi_type!(HnswApif64, f64);
//===================================================================================================
// These are the macros to generate trait implementation for useful numeric types
#[allow(unused_macros)]

macro_rules! generate_insert(
($function_name:ident, $api_name:ty, $type_val:ty) => (
/// # Safety
Expand Down Expand Up @@ -281,7 +282,7 @@ macro_rules! generate_loadhnsw(
/// function to reload from a previous dump (knowing data type and distance used).
/// This function takes as argument a pointer to Hnswio_api that drives the reloading.
/// The pointer is provided by the function [get_hnswio()](get_hnswio).
///
/// # Safety
/// The function is unsafe because it dereferences a raw pointer
///
#[no_mangle]
Expand Down

0 comments on commit 7ba4a86

Please sign in to comment.