From 3c5a94452a46a22990fb6e9c4b41a653d0e360ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A1n=20Arroyo=20Calle?= Date: Fri, 20 Aug 2021 12:38:15 +0200 Subject: [PATCH 1/2] Fix #1009 by providing a naive num-bigint implementation of count_ones --- crates/num-rug-adapter/src/lib.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/crates/num-rug-adapter/src/lib.rs b/crates/num-rug-adapter/src/lib.rs index a95d42c8..2f67b80d 100644 --- a/crates/num-rug-adapter/src/lib.rs +++ b/crates/num-rug-adapter/src/lib.rs @@ -117,6 +117,10 @@ impl Integer { pub fn gcd(&self, other: &Self) -> Self { Integer(num_integer::Integer::gcd(&self.0, &other.0)) } + + pub fn count_ones(&self) -> Option { + Some(self.0.to_u32_digits().1.iter().map(|&d| d.count_ones()).sum()) + } } impl From<&Integer> for Integer { From 9bcc56e337794b7a64ab995cb79a0c30177d1d35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A1n=20Arroyo=20Calle?= Date: Fri, 20 Aug 2021 12:40:27 +0200 Subject: [PATCH 2/2] Make it line --- crates/num-rug-adapter/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/num-rug-adapter/src/lib.rs b/crates/num-rug-adapter/src/lib.rs index 2f67b80d..6cb19918 100644 --- a/crates/num-rug-adapter/src/lib.rs +++ b/crates/num-rug-adapter/src/lib.rs @@ -118,6 +118,7 @@ impl Integer { Integer(num_integer::Integer::gcd(&self.0, &other.0)) } + #[inline] pub fn count_ones(&self) -> Option { Some(self.0.to_u32_digits().1.iter().map(|&d| d.count_ones()).sum()) }