Skip to content

Commit

Permalink
fix Gtree's PartialEq impl
Browse files Browse the repository at this point in the history
  • Loading branch information
noib3 committed Jan 27, 2024
1 parent 9e25c4d commit d9378c9
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/gtree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ const _NODE_IDX_LAYOUT_CHECK: usize = {
/// which the internal and leaf nodes are stored in memory.
///
/// TODO: finish describing the data structure.
#[derive(Clone, PartialEq)]
#[derive(Clone)]
pub(crate) struct Gtree<const ARITY: usize, L: Leaf> {
/// The internal nodes of the Gtree.
///
Expand Down Expand Up @@ -2395,6 +2395,29 @@ impl<const ARITY: usize, L: Leaf> Gtree<ARITY, L> {
}
}

impl<const N: usize, const M: usize, L: Leaf> PartialEq<Gtree<M, L>>
for Gtree<N, L>
where
L: PartialEq,
{
#[inline]
fn eq(&self, other: &Gtree<M, L>) -> bool {
let mut this = self.leaves_from_first();
let mut other = other.leaves_from_first();
loop {
match (this.next(), other.next()) {
(None, None) => return true,
(Some((_, this)), Some((_, other))) => {
if this != other {
return false;
}
},
_ => return false,
}
}
}
}

/// The index inside the `children` array of a particular child of an internal
/// node.
type ChildIdx = usize;
Expand Down

0 comments on commit d9378c9

Please sign in to comment.