From d35caf1ede1803344fe2d4cd16cc579926dd5d3d Mon Sep 17 00:00:00 2001 From: David Onuh Date: Wed, 15 May 2024 05:47:18 +0100 Subject: [PATCH] Allow dead_code in server and basic clippy suggestions --- ahnlich/server/src/algorithm/heap.rs | 20 ++++++++++---------- ahnlich/server/src/algorithm/similarity.rs | 9 +++------ ahnlich/server/src/engine/store.rs | 17 +++++++++++------ ahnlich/server/src/main.rs | 2 ++ ahnlich/types/src/keyval.rs | 1 - 5 files changed, 26 insertions(+), 23 deletions(-) diff --git a/ahnlich/server/src/algorithm/heap.rs b/ahnlich/server/src/algorithm/heap.rs index f86a6f98..653f621a 100644 --- a/ahnlich/server/src/algorithm/heap.rs +++ b/ahnlich/server/src/algorithm/heap.rs @@ -82,28 +82,28 @@ impl<'a> MaxHeap<'a> { } pub(crate) enum AlgorithmHeapType<'a> { - MIN(MinHeap<'a>), - MAX(MaxHeap<'a>), + Min(MinHeap<'a>), + Max(MaxHeap<'a>), } impl<'a> AlgorithmHeapType<'a> { pub(crate) fn push(&mut self, item: SimilarityVector<'a>) { match self { - Self::MAX(h) => h.push(item), - Self::MIN(h) => h.push(item), + Self::Max(h) => h.push(item), + Self::Min(h) => h.push(item), } } pub(crate) fn pop(&mut self) -> Option> { match self { - Self::MAX(h) => h.pop(), - Self::MIN(h) => h.pop(), + Self::Max(h) => h.pop(), + Self::Min(h) => h.pop(), } } pub(crate) fn output(&mut self) -> Vec<(&'a StoreKey, f64)> { match self { - Self::MIN(h) => h.output(), - Self::MAX(h) => h.output(), + Self::Min(h) => h.output(), + Self::Max(h) => h.output(), } } } @@ -111,9 +111,9 @@ impl<'a> AlgorithmHeapType<'a> { impl From<(&Algorithm, NonZeroUsize)> for AlgorithmHeapType<'_> { fn from((value, capacity): (&Algorithm, NonZeroUsize)) -> Self { match value { - Algorithm::EuclideanDistance => AlgorithmHeapType::MIN(MinHeap::new(capacity)), + Algorithm::EuclideanDistance => AlgorithmHeapType::Min(MinHeap::new(capacity)), Algorithm::CosineSimilarity | Algorithm::DotProductSimilarity => { - AlgorithmHeapType::MAX(MaxHeap::new(capacity)) + AlgorithmHeapType::Max(MaxHeap::new(capacity)) } } } diff --git a/ahnlich/server/src/algorithm/similarity.rs b/ahnlich/server/src/algorithm/similarity.rs index 527ca81a..37b20458 100644 --- a/ahnlich/server/src/algorithm/similarity.rs +++ b/ahnlich/server/src/algorithm/similarity.rs @@ -71,7 +71,7 @@ fn cosine_similarity(first: &StoreKey, second: &StoreKey) -> f64 { // // - let dot_product = dot_product(&first, &second); + let dot_product = dot_product(first, second); // the magnitude can be calculated using the arr.norm method. let mag_first = &first.0.iter().map(|x| x * x).sum::().sqrt(); @@ -84,9 +84,7 @@ fn cosine_similarity(first: &StoreKey, second: &StoreKey) -> f64 { .sum::() .sqrt(); - let cosine_sim = dot_product / (mag_first * mag_second); - - cosine_sim + dot_product / (mag_first * mag_second) } /// @@ -130,8 +128,7 @@ fn euclidean_distance(first: &StoreKey, second: &StoreKey) -> f64 { } // Calculate the square root of the sum of squared differences - let distance = f64::sqrt(sum_of_squared_differences); - distance + f64::sqrt(sum_of_squared_differences) } #[cfg(test)] diff --git a/ahnlich/server/src/engine/store.rs b/ahnlich/server/src/engine/store.rs index 41b76645..5913f633 100644 --- a/ahnlich/server/src/engine/store.rs +++ b/ahnlich/server/src/engine/store.rs @@ -103,7 +103,8 @@ impl StoreHandler { predicates: Vec, ) -> Result<(), ServerError> { let store = self.get(store_name)?; - Ok(store.reindex(predicates.into_iter().collect())) + store.reindex(predicates.into_iter().collect()); + Ok(()) } /// Matches DELKEY - removes keys from a store @@ -215,11 +216,15 @@ impl StoreHandler { dimension: NonZeroUsize, predicates: Vec, ) -> Result<(), ServerError> { - if let Err(_) = self.stores.try_insert( - store_name.clone(), - Arc::new(Store::create(dimension, predicates)), - &self.stores.guard(), - ) { + if self + .stores + .try_insert( + store_name.clone(), + Arc::new(Store::create(dimension, predicates)), + &self.stores.guard(), + ) + .is_err() + { return Err(ServerError::StoreAlreadyExists(store_name)); } Ok(()) diff --git a/ahnlich/server/src/main.rs b/ahnlich/server/src/main.rs index 8e036e35..efc39a4c 100644 --- a/ahnlich/server/src/main.rs +++ b/ahnlich/server/src/main.rs @@ -1,3 +1,5 @@ +#![allow(dead_code)] + mod algorithm; mod engine; mod errors; diff --git a/ahnlich/types/src/keyval.rs b/ahnlich/types/src/keyval.rs index 0fde16f5..553380f0 100644 --- a/ahnlich/types/src/keyval.rs +++ b/ahnlich/types/src/keyval.rs @@ -2,7 +2,6 @@ use crate::metadata::MetadataKey; use crate::metadata::MetadataValue; use ndarray::Array1; use std::collections::HashMap as StdHashMap; -use std::ops::Deref; /// Name of a Store #[derive(Debug, Clone, PartialEq, Eq, Ord, PartialOrd, Hash)]