Compound PartialEq
This commit is contained in:
parent
bb100cc0dd
commit
7225960363
|
@ -173,6 +173,21 @@ impl<'a, D: Domain> Hash for dyn Value<D> + 'a {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn iters_eq<'a, D: Domain>(
|
||||||
|
mut i1: Box<dyn Iterator<Item = &dyn Value<D>> + 'a>,
|
||||||
|
mut i2: Box<dyn Iterator<Item = &dyn Value<D>> + 'a>,
|
||||||
|
) -> bool {
|
||||||
|
loop {
|
||||||
|
match i1.next() {
|
||||||
|
None => return i2.next().is_none(),
|
||||||
|
Some(v1) => match i2.next() {
|
||||||
|
None => return false,
|
||||||
|
Some(v2) => if v1 != v2 { return false; },
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<'a, D: Domain> PartialEq for dyn Value<D> + 'a {
|
impl<'a, D: Domain> PartialEq for dyn Value<D> + 'a {
|
||||||
fn eq(&self, other: &Self) -> bool {
|
fn eq(&self, other: &Self) -> bool {
|
||||||
let cls = self.value_class();
|
let cls = self.value_class();
|
||||||
|
@ -195,7 +210,23 @@ impl<'a, D: Domain> PartialEq for dyn Value<D> + 'a {
|
||||||
self.as_symbol().unwrap() == other.as_symbol().unwrap(),
|
self.as_symbol().unwrap() == other.as_symbol().unwrap(),
|
||||||
}
|
}
|
||||||
ValueClass::Compound(c) => match c {
|
ValueClass::Compound(c) => match c {
|
||||||
_ => todo!(),
|
CompoundClass::Record => {
|
||||||
|
if self.label().unwrap() != other.label().unwrap() { return false; }
|
||||||
|
iters_eq(self.iter().unwrap(), other.iter().unwrap())
|
||||||
|
}
|
||||||
|
CompoundClass::Sequence => {
|
||||||
|
iters_eq(self.iter().unwrap(), other.iter().unwrap())
|
||||||
|
}
|
||||||
|
CompoundClass::Set => {
|
||||||
|
let s1 = self.iter().unwrap().collect::<Set<_>>();
|
||||||
|
let s2 = other.iter().unwrap().collect::<Set<_>>();
|
||||||
|
s1 == s2
|
||||||
|
}
|
||||||
|
CompoundClass::Dictionary => {
|
||||||
|
let d1 = self.entries().unwrap().collect::<Map<_, _>>();
|
||||||
|
let d2 = other.entries().unwrap().collect::<Map<_, _>>();
|
||||||
|
d1 == d2
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ValueClass::Embedded => self.embedded().unwrap() == other.embedded().unwrap(),
|
ValueClass::Embedded => self.embedded().unwrap() == other.embedded().unwrap(),
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue