Include values of Prefab and Pop in their Hash and Eq impls

This commit is contained in:
Tad Hardesty 2022-04-30 11:15:17 -07:00
parent a2eaf42f9e
commit e979b2e69a
2 changed files with 12 additions and 5 deletions

View file

@ -118,7 +118,6 @@ pub struct ZLevel<'a> {
pub grid: ndarray::ArrayView<'a, Key, ndarray::Dim<[usize; 2]>>,
}
// TODO: port to ast::Prefab<Constant>
#[derive(Debug, Default, Clone)]
pub struct Prefab {
pub path: String,
@ -128,7 +127,7 @@ pub struct Prefab {
impl PartialEq for Prefab {
fn eq(&self, other: &Self) -> bool {
self.path == other.path && self.vars.keys().eq(other.vars.keys())
self.path == other.path && self.vars == other.vars
}
}
@ -137,7 +136,11 @@ impl Eq for Prefab {}
impl std::hash::Hash for Prefab {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.path.hash(state);
self.vars.keys().for_each(|key| {key.hash(state)});
let mut items: Vec<_> = self.vars.iter().collect();
items.sort_by_key(|&(k, _)| k);
for kvp in items {
kvp.hash(state);
}
}
}

View file

@ -26,7 +26,7 @@ pub struct Pop {
impl PartialEq for Pop {
fn eq(&self, other: &Self) -> bool {
self.path == other.path && self.vars.keys().eq(other.vars.keys())
self.path == other.path && self.vars == other.vars
}
}
@ -35,7 +35,11 @@ impl Eq for Pop {}
impl std::hash::Hash for Pop {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.path.hash(state);
self.vars.keys().for_each(|key| {key.hash(state)});
let mut items: Vec<_> = self.vars.iter().collect();
items.sort_by_key(|&(k, _)| k);
for kvp in items {
kvp.hash(state);
}
}
}