Add more container functions to support future indexed binary heap

This commit is contained in:
Michael Bradley 2025-01-31 01:01:10 -05:00
parent d8fef9b806
commit d56d2cf117
Signed by: MichaelBradley
SSH key fingerprint: SHA256:cj/YZ5VT+QOKncqSkx+ibKTIn0Obg7OIzwzl9BL8EO8
2 changed files with 18 additions and 2 deletions

View file

@ -13,11 +13,25 @@ impl<D: Clone, P: PartialOrd + Clone> Pair<D, P> {
Self { data, priority } Self { data, priority }
} }
/// Retrieves the internal data. /// Returns the internal data.
/// It would be nicer to implement this using [`From`] or [`Into`], but I don't see a way to do that using generics. /// It might(?) be nicer to implement this using [`From`] or [`Into`], but I don't see a way to do that using generics.
pub fn data(self) -> D { pub fn data(self) -> D {
self.data self.data
} }
pub fn get_data(&self) -> &D {
&self.data
}
/// Retrieve the priority associated with the data
pub fn get_priority(&self) -> &P {
&self.priority
}
/// Update the priority associated with the data
pub fn set_priority(&mut self, priority: P) {
self.priority = priority
}
} }
impl<D: Clone, P: PartialOrd + Clone> PartialOrd for Pair<D, P> { impl<D: Clone, P: PartialOrd + Clone> PartialOrd for Pair<D, P> {

View file

@ -48,6 +48,8 @@ impl PartialEq for PyItem {
} }
} }
impl Eq for PyItem {}
impl Hash for PyItem { impl Hash for PyItem {
fn hash<H: Hasher>(&self, state: &mut H) { fn hash<H: Hasher>(&self, state: &mut H) {
// TODO: Should warn or fail instead of defaulting to 0 // TODO: Should warn or fail instead of defaulting to 0