fix: Use sort_by_key on time rather than implementing traits
Needed because the PartialOrd/Ord trait implementations would then
disagree with the PartialEq/Eq trait implementations, which isn't really
what's desired.
Change the method name to make it clearer that this isn't using the Ord
trait's sort.
@@ -271,7 +271,7 @@ impl Stream for ReadMergeStream<'_> {
}
if sort {
- batch.sort();
+ batch.sort_by_time();
}
Poll::Ready(Some(batch))
@@ -284,18 +284,6 @@ pub enum ReadValues {
F64(Vec<ReadPoint<f64>>),
}
-impl<T: Eq + PartialEq + Clone> Ord for ReadPoint<T> {
- fn cmp(&self, other: &Self) -> Ordering {
- self.time.cmp(&other.time)
- }
-}
-
-impl<T: Eq + PartialEq + Clone> PartialOrd for ReadPoint<T> {
- fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
- Some(self.cmp(other))
- }
-}
-
#[derive(Debug, PartialEq, Clone)]
pub struct ReadBatch {
pub key: String,
@@ -320,10 +308,10 @@ impl ReadBatch {
}
}
- fn sort(&mut self) {
+ fn sort_by_time(&mut self) {
match &mut self.values {
- ReadValues::I64(vals) => vals.sort(),
- ReadValues::F64(vals) => vals.sort_by(|a, b| a.time.partial_cmp(&b.time).unwrap()),
+ ReadValues::I64(vals) => vals.sort_by_key(|v| v.time),
+ ReadValues::F64(vals) => vals.sort_by_key(|v| v.time),
}
}
