abstutil/
priority_queue.rs1use std::cmp::Ordering;
2
3use serde::{Deserialize, Serialize};
4
5#[derive(Serialize, Deserialize, PartialEq, Eq, Clone)]
8pub struct PriorityQueueItem<K, V> {
9 pub cost: K,
10 pub value: V,
11}
12
13impl<K: Ord, V: Ord> PartialOrd for PriorityQueueItem<K, V> {
14 fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
15 Some(self.cmp(other))
16 }
17}
18
19impl<K: Ord, V: Ord> Ord for PriorityQueueItem<K, V> {
20 fn cmp(&self, other: &Self) -> Ordering {
21 let ord = other.cost.cmp(&self.cost);
22 if ord != Ordering::Equal {
23 return ord;
24 }
25 self.value.cmp(&other.value)
27 }
28}