Skip to content

Commit

Permalink
Fix Feature eq + hash
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBlueMatt committed Dec 24, 2023
1 parent 9f49883 commit 64cea32
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions lightning/src/ln/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -469,12 +469,24 @@ impl<T: sealed::Context> Clone for Features<T> {
}
impl<T: sealed::Context> Hash for Features<T> {
fn hash<H: Hasher>(&self, hasher: &mut H) {
self.flags.hash(hasher);
let mut nonzero_flags = &self.flags[..];
while nonzero_flags.last() == Some(&0) {
nonzero_flags = &nonzero_flags[..nonzero_flags.len() - 1];
}
nonzero_flags.hash(hasher);
}
}
impl<T: sealed::Context> PartialEq for Features<T> {
fn eq(&self, o: &Self) -> bool {
self.flags.eq(&o.flags)
let mut o_iter = o.flags.iter();
let mut self_iter = self.flags.iter();
loop {
match (o_iter.next(), self_iter.next()) {
(Some(o), Some(us)) => if o != us { return false },
(Some(b), None) | (None, Some(b)) => if *b != 0 { return false },
(None, None) => return true,
}
}
}
}
impl<T: sealed::Context> PartialOrd for Features<T> {
Expand Down

0 comments on commit 64cea32

Please sign in to comment.