Skip to content

Commit

Permalink
Allow dead_code in server and basic clippy suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
Iamdavidonuh committed May 15, 2024
1 parent 0e5e2c7 commit d35caf1
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 23 deletions.
20 changes: 10 additions & 10 deletions ahnlich/server/src/algorithm/heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,38 +82,38 @@ 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<SimilarityVector<'a>> {
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(),
}
}
}

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))
}
}
}
Expand Down
9 changes: 3 additions & 6 deletions ahnlich/server/src/algorithm/similarity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<f64>().sqrt();
Expand All @@ -84,9 +84,7 @@ fn cosine_similarity(first: &StoreKey, second: &StoreKey) -> f64 {
.sum::<f64>()
.sqrt();

let cosine_sim = dot_product / (mag_first * mag_second);

cosine_sim
dot_product / (mag_first * mag_second)
}

///
Expand Down Expand Up @@ -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)]
Expand Down
17 changes: 11 additions & 6 deletions ahnlich/server/src/engine/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ impl StoreHandler {
predicates: Vec<MetadataKey>,
) -> 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
Expand Down Expand Up @@ -215,11 +216,15 @@ impl StoreHandler {
dimension: NonZeroUsize,
predicates: Vec<MetadataKey>,
) -> 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(())
Expand Down
2 changes: 2 additions & 0 deletions ahnlich/server/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(dead_code)]

mod algorithm;
mod engine;
mod errors;
Expand Down
1 change: 0 additions & 1 deletion ahnlich/types/src/keyval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down

0 comments on commit d35caf1

Please sign in to comment.