From 8a7c51271ed06e75fc0f45894a54ab489b2561bc Mon Sep 17 00:00:00 2001 From: Michael Sproul Date: Tue, 19 Mar 2019 19:19:21 +1100 Subject: [PATCH] Bitfield: use BitOr instead of BitAnd for union Closes #314 --- eth2/utils/boolean-bitfield/src/lib.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/eth2/utils/boolean-bitfield/src/lib.rs b/eth2/utils/boolean-bitfield/src/lib.rs index e37f2488d..cdd0bc3d7 100644 --- a/eth2/utils/boolean-bitfield/src/lib.rs +++ b/eth2/utils/boolean-bitfield/src/lib.rs @@ -168,10 +168,11 @@ impl cmp::PartialEq for BooleanBitfield { /// Create a new bitfield that is a union of two other bitfields. /// /// For example `union(0101, 1000) == 1101` -impl std::ops::BitAnd for BooleanBitfield { +// TODO: length-independent intersection for BitAnd +impl std::ops::BitOr for BooleanBitfield { type Output = Self; - fn bitand(self, other: Self) -> Self { + fn bitor(self, other: Self) -> Self { let (biggest, smallest) = if self.len() > other.len() { (&self, &other) } else { @@ -464,11 +465,11 @@ mod tests { } #[test] - fn test_bitand() { + fn test_bitor() { let a = BooleanBitfield::from_bytes(&vec![2, 8, 1][..]); let b = BooleanBitfield::from_bytes(&vec![4, 8, 16][..]); let c = BooleanBitfield::from_bytes(&vec![6, 8, 17][..]); - assert_eq!(c, a & b); + assert_eq!(c, a | b); } #[test]