rshyper_algo/astar/
priority_node.rs1use core::cmp::Ordering;
6use rshyper::idx::{RawIndex, VertexId};
7
8#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq)]
10#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
11pub struct PriorityNode<P = i64, Idx = usize>
12where
13 Idx: RawIndex,
14{
15 pub(crate) vertex: VertexId<Idx>,
16 pub(crate) priority: P, }
18
19impl<P, Idx> PriorityNode<P, Idx>
20where
21 Idx: RawIndex,
22{
23 pub fn new(vertex: VertexId<Idx>, priority: P) -> Self {
25 Self { vertex, priority }
26 }
27 pub const fn priority(&self) -> &P {
29 &self.priority
30 }
31 pub const fn vertex(&self) -> &VertexId<Idx> {
33 &self.vertex
34 }
35}
36
37impl<P, Idx> PartialEq<P> for PriorityNode<P, Idx>
38where
39 P: PartialEq,
40 Idx: RawIndex + PartialEq,
41{
42 fn eq(&self, other: &P) -> bool {
43 self.priority() == other
44 }
45}
46
47impl<P, Idx> Ord for PriorityNode<P, Idx>
48where
49 P: Ord,
50 Idx: RawIndex + Ord,
51{
52 fn cmp(&self, other: &Self) -> Ordering {
53 other.priority().cmp(&self.priority)
55 }
56}
57
58impl<P, Idx> PartialOrd for PriorityNode<P, Idx>
59where
60 P: PartialOrd,
61 Idx: RawIndex + PartialOrd,
62{
63 fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
64 other.priority().partial_cmp(&self.priority)
66 }
67}
68
69impl<P, Idx> PartialOrd<P> for PriorityNode<P, Idx>
70where
71 P: PartialOrd,
72 Idx: RawIndex + PartialOrd,
73{
74 fn partial_cmp(&self, other: &P) -> Option<Ordering> {
75 other.partial_cmp(self.priority())
77 }
78}