orx_tree/common_traits/
eq.rs

1use crate::{Dfs, MemoryPolicy, NodeRef, Tree, TreeVariant, pinned_storage::PinnedStorage};
2
3impl<V1, M1, P1, V2, M2, P2> PartialEq<Tree<V1, M1, P1>> for Tree<V2, M2, P2>
4where
5    V1: TreeVariant,
6    M1: MemoryPolicy,
7    P1: PinnedStorage,
8    V2: TreeVariant<Item = V1::Item>,
9    M2: MemoryPolicy,
10    P2: PinnedStorage,
11    V1::Item: PartialEq,
12{
13    fn eq(&self, other: &Tree<V1, M1, P1>) -> bool {
14        // TODO: currently we use one of the default traversals.
15        // equality check performance can be improved by walking two trees at once.
16        match self.len() == other.len() {
17            true => match self.len() {
18                0 => true,
19                _ => self
20                    .root()
21                    .walk::<Dfs>()
22                    .zip(other.root().walk::<Dfs>())
23                    .all(|(a, b)| a == b),
24            },
25            false => false,
26        }
27    }
28}