1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
use std::cmp::Ordering;
pub struct RefWithCost<'a, Real, T: 'a> {
pub object: &'a T,
pub cost: Real,
}
impl<'a, Real: PartialEq, T> PartialEq for RefWithCost<'a, Real, T> {
#[inline]
fn eq(&self, other: &RefWithCost<'a, Real, T>) -> bool {
self.cost.eq(&other.cost)
}
}
impl<'a, Real: PartialEq, T> Eq for RefWithCost<'a, Real, T> {}
impl<'a, Real: PartialOrd, T> PartialOrd for RefWithCost<'a, Real, T> {
#[inline]
fn partial_cmp(&self, other: &RefWithCost<'a, Real, T>) -> Option<Ordering> {
self.cost.partial_cmp(&other.cost)
}
}
impl<'a, Real: PartialOrd, T> Ord for RefWithCost<'a, Real, T> {
#[inline]
fn cmp(&self, other: &RefWithCost<'a, Real, T>) -> Ordering {
if self.cost < other.cost {
Ordering::Less
} else if self.cost > other.cost {
Ordering::Greater
} else {
Ordering::Equal
}
}
}