kdtree/
heap_element.rs

1use num_traits::Float;
2use std::cmp::Ordering;
3
4pub struct HeapElement<A, T> {
5    pub distance: A,
6    pub element: T,
7}
8
9impl<A: Float, T> Ord for HeapElement<A, T> {
10    fn cmp(&self, other: &Self) -> Ordering {
11        self.partial_cmp(other).unwrap_or(Ordering::Equal)
12    }
13}
14
15impl<A: Float, T> PartialOrd for HeapElement<A, T> {
16    fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
17        self.distance.partial_cmp(&other.distance)
18    }
19}
20
21impl<A: Float, T> PartialOrd<A> for HeapElement<A, T>
22where
23    HeapElement<A, T>: PartialEq<A>,
24{
25    fn partial_cmp(&self, other: &A) -> Option<Ordering> {
26        self.distance.partial_cmp(other)
27    }
28}
29
30impl<A: Float, T> Eq for HeapElement<A, T> {}
31
32impl<A: Float, T> PartialEq for HeapElement<A, T> {
33    fn eq(&self, other: &Self) -> bool {
34        self.distance == other.distance
35    }
36}
37
38impl<A: Float, T> PartialEq<A> for HeapElement<A, T> {
39    fn eq(&self, other: &A) -> bool {
40        self.distance == *other
41    }
42}
43
44impl<A: Float, T> From<HeapElement<A, T>> for (A, T) {
45    fn from(e: HeapElement<A, T>) -> Self {
46        (e.distance, e.element)
47    }
48}