]> Repositorios git - scryer-prolog.git/commitdiff
Fix #1009 by providing a naive num-bigint implementation of count_ones
authorAdrián Arroyo Calle <[email protected]>
Fri, 20 Aug 2021 10:38:15 +0000 (12:38 +0200)
committerAdrián Arroyo Calle <[email protected]>
Fri, 20 Aug 2021 10:38:15 +0000 (12:38 +0200)
crates/num-rug-adapter/src/lib.rs

index a95d42c8d0af886a8eb788099d155f37b53a88b8..2f67b80da259f38ffe0e0fc315d9f465e7578ef5 100644 (file)
@@ -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<u32> {
+        Some(self.0.to_u32_digits().1.iter().map(|&d| d.count_ones()).sum())
+    }
 }
 
 impl From<&Integer> for Integer {