about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDavid Creswick <dcrewi@gyrae.net>2013-09-09 11:31:40 -0500
committerDavid Creswick <dcrewi@gyrae.net>2013-09-09 11:31:40 -0500
commit4946e0ea5ee727893a74321be2fb3b291f320809 (patch)
treece8dafaec59c62ad744ad9a931fa53fee4b1edf7
parent54368afc03054937e7f5a3b7a9b8cf9c8e85d962 (diff)
downloadrust-4946e0ea5ee727893a74321be2fb3b291f320809.tar.gz
rust-4946e0ea5ee727893a74321be2fb3b291f320809.zip
Merge RandBigUint and RandBigInt into single trait
-rw-r--r--src/libextra/num/bigint.rs38
1 files changed, 17 insertions, 21 deletions
diff --git a/src/libextra/num/bigint.rs b/src/libextra/num/bigint.rs
index b691cb3c296..93ffbb1c45c 100644
--- a/src/libextra/num/bigint.rs
+++ b/src/libextra/num/bigint.rs
@@ -521,27 +521,6 @@ impl FromStrRadix for BigUint {
     }
 }
 
-trait RandBigUInt {
-    /// Generate a random BigUint of the given bit size.
-    fn gen_biguint(&mut self, bit_size: uint) -> BigUint;
-}
-
-impl<R: Rng> RandBigUInt for R {
-    /// Generate a random BigUint of the given bit size.
-    fn gen_biguint(&mut self, bit_size: uint) -> BigUint {
-        let (digits, rem) = bit_size.div_rem(&BigDigit::bits);
-        let mut data = vec::with_capacity(digits+1);
-        for _ in range(0, digits) {
-            data.push(self.gen());
-        }
-        if rem > 0 {
-            let final_digit: BigDigit = self.gen();
-            data.push(final_digit >> (BigDigit::bits - rem));
-        }
-        return BigUint::new(data);
-    }
-}
-
 impl BigUint {
     /// Creates and initializes an BigUint.
     #[inline]
@@ -1074,12 +1053,29 @@ impl FromStrRadix for BigInt {
 }
 
 trait RandBigInt {
+    /// Generate a random BigUint of the given bit size.
+    fn gen_biguint(&mut self, bit_size: uint) -> BigUint;
+
     /// Generate a random BigInt of the given bit size.
     fn gen_bigint(&mut self, bit_size: uint) -> BigInt;
 }
 
 impl<R: Rng> RandBigInt for R {
     /// Generate a random BigUint of the given bit size.
+    fn gen_biguint(&mut self, bit_size: uint) -> BigUint {
+        let (digits, rem) = bit_size.div_rem(&BigDigit::bits);
+        let mut data = vec::with_capacity(digits+1);
+        for _ in range(0, digits) {
+            data.push(self.gen());
+        }
+        if rem > 0 {
+            let final_digit: BigDigit = self.gen();
+            data.push(final_digit >> (BigDigit::bits - rem));
+        }
+        return BigUint::new(data);
+    }
+
+    /// Generate a random BigInt of the given bit size.
     fn gen_bigint(&mut self, bit_size: uint) -> BigInt {
         // Generate a random BigUint...
         let biguint = self.gen_biguint(bit_size);