Skip to content

Commit

Permalink
updated logic to enqueue distance results
Browse files Browse the repository at this point in the history
  • Loading branch information
0xKitsune committed Jan 31, 2024
1 parent 9c94ab4 commit 7049f92
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
29 changes: 15 additions & 14 deletions src/coordinator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,21 +277,23 @@ impl Coordinator {

if distance > self.hamming_distance_threshold {
if closest_distances.len() < self.n_closest_distances {
closest_distances.push(Distance::new(distance, id));
closest_distances
.push((ordered_float::OrderedFloat(distance), id));

max_closest_distance = closest_distances
.peek()
.expect("There should be at least one element")
.distance
.0
.into_inner();
} else if distance < max_closest_distance {
closest_distances.pop();
closest_distances.push(Distance::new(distance, id));
closest_distances
.push((ordered_float::OrderedFloat(distance), id));

max_closest_distance = closest_distances
.peek()
.expect("There should be at least one element")
.distance
.0
.into_inner();
}
} else {
Expand All @@ -305,7 +307,7 @@ impl Coordinator {

let closest_n_distances = closest_distances
.into_iter()
.map(|d| d)
.map(|d| Distance::new(d.0.into_inner(), d.1))
.collect::<Vec<Distance>>();

let distance_results =
Expand Down Expand Up @@ -337,15 +339,14 @@ impl Coordinator {
&self,
distance_results: DistanceResults,
) -> eyre::Result<()> {
todo!();

// let distances_queue = self
// .aws_client
// .send_message()
// .queue_url(self.distances_queue_url.clone())
// // .message_body(input) //TODO: update/uncomment this
// .send()
// .await?;
//TODO: Implement DLQ logic

self.aws_client
.send_message()
.queue_url(self.distances_queue_url.clone())
.message_body(serde_json::to_string(&distance_results)?)
.send()
.await?;

Ok(())
}
Expand Down
11 changes: 5 additions & 6 deletions src/distance.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use bytemuck::{Pod, Zeroable};
use rayon::prelude::*;
use serde::{Deserialize, Serialize};

use crate::arch;
pub use crate::bits::Bits;
Expand Down Expand Up @@ -53,22 +54,20 @@ impl DistanceEngine {
}
}

#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord)]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Distance {
pub distance: ordered_float::OrderedFloat<f64>,
pub distance: f64,
pub id: usize,
}

impl Distance {
pub fn new(distance: f64, id: usize) -> Self {
Self {
distance: ordered_float::OrderedFloat(distance),
id,
}
Self { distance, id }
}
}

//TODO: docs
#[derive(Debug, Serialize, Deserialize)]
pub struct DistanceResults {
pub latest_id: usize,
pub closest_distances: Vec<Distance>,
Expand Down

0 comments on commit 7049f92

Please sign in to comment.