18
18
//!
19
19
//! ## Example
20
20
//!
21
- //! ```rust
22
- //! use num::{BigUint, Zero, One};
21
+ //! ```rust,ignore
22
+ //! use num_bigint::BigUint;
23
+ //! use num_traits::{Zero, One};
23
24
//! use std::mem::replace;
24
25
//!
25
26
//! // Calculate large fibonacci numbers.
42
43
//!
43
44
//! ```rust
44
45
//! extern crate rand;
45
- //! extern crate num ;
46
+ //! extern crate num_bigint as bigint ;
46
47
//!
47
48
//! # #[cfg(feature = "rand")]
48
49
//! # fn main() {
49
- //! use num:: bigint::{ToBigInt, RandBigInt};
50
+ //! use bigint::{ToBigInt, RandBigInt};
50
51
//!
51
52
//! let mut rng = rand::thread_rng();
52
53
//! let a = rng.gen_bigint(1000);
64
65
//! # }
65
66
//! ```
66
67
68
+ #[ cfg( any( feature = "rand" , test) ) ]
69
+ extern crate rand;
70
+
67
71
extern crate num_integer as integer;
68
72
extern crate num_traits as traits;
69
73
@@ -75,6 +79,7 @@ use std::num::ParseIntError;
75
79
use std:: ops:: { Add , BitAnd , BitOr , BitXor , Div , Mul , Neg , Rem , Shl , Shr , Sub } ;
76
80
use std:: str:: { self , FromStr } ;
77
81
use std:: fmt;
82
+ use std:: hash;
78
83
use std:: cmp:: Ordering :: { self , Less , Greater , Equal } ;
79
84
use std:: { f32, f64} ;
80
85
use std:: { u8, i64, u64} ;
@@ -1655,7 +1660,7 @@ impl BigUint {
1655
1660
/// # Examples
1656
1661
///
1657
1662
/// ```
1658
- /// use num::bigint ::BigUint;
1663
+ /// use num_bigint ::BigUint;
1659
1664
///
1660
1665
/// assert_eq!(BigUint::from_bytes_be(b"A"),
1661
1666
/// BigUint::parse_bytes(b"65", 10).unwrap());
@@ -1694,7 +1699,7 @@ impl BigUint {
1694
1699
/// # Examples
1695
1700
///
1696
1701
/// ```
1697
- /// use num::bigint ::BigUint;
1702
+ /// use num_bigint ::BigUint;
1698
1703
///
1699
1704
/// let i = BigUint::parse_bytes(b"1125", 10).unwrap();
1700
1705
/// assert_eq!(i.to_bytes_le(), vec![101, 4]);
@@ -1713,7 +1718,7 @@ impl BigUint {
1713
1718
/// # Examples
1714
1719
///
1715
1720
/// ```
1716
- /// use num::bigint ::BigUint;
1721
+ /// use num_bigint ::BigUint;
1717
1722
///
1718
1723
/// let i = BigUint::parse_bytes(b"1125", 10).unwrap();
1719
1724
/// assert_eq!(i.to_bytes_be(), vec![4, 101]);
@@ -1731,7 +1736,7 @@ impl BigUint {
1731
1736
/// # Examples
1732
1737
///
1733
1738
/// ```
1734
- /// use num::bigint ::BigUint;
1739
+ /// use num_bigint ::BigUint;
1735
1740
///
1736
1741
/// let i = BigUint::parse_bytes(b"ff", 16).unwrap();
1737
1742
/// assert_eq!(i.to_str_radix(16), "ff");
@@ -1748,7 +1753,7 @@ impl BigUint {
1748
1753
/// # Examples
1749
1754
///
1750
1755
/// ```
1751
- /// use num::bigint ::{BigUint, ToBigUint};
1756
+ /// use num_bigint ::{BigUint, ToBigUint};
1752
1757
///
1753
1758
/// assert_eq!(BigUint::parse_bytes(b"1234", 10), ToBigUint::to_biguint(&1234));
1754
1759
/// assert_eq!(BigUint::parse_bytes(b"ABCD", 16), ToBigUint::to_biguint(&0xABCD));
@@ -2764,7 +2769,7 @@ impl BigInt {
2764
2769
/// # Examples
2765
2770
///
2766
2771
/// ```
2767
- /// use num::bigint ::{BigInt, Sign};
2772
+ /// use num_bigint ::{BigInt, Sign};
2768
2773
///
2769
2774
/// assert_eq!(BigInt::from_bytes_be(Sign::Plus, b"A"),
2770
2775
/// BigInt::parse_bytes(b"65", 10).unwrap());
@@ -2793,7 +2798,7 @@ impl BigInt {
2793
2798
/// # Examples
2794
2799
///
2795
2800
/// ```
2796
- /// use num::bigint ::{ToBigInt, Sign};
2801
+ /// use num_bigint ::{ToBigInt, Sign};
2797
2802
///
2798
2803
/// let i = -1125.to_bigint().unwrap();
2799
2804
/// assert_eq!(i.to_bytes_le(), (Sign::Minus, vec![101, 4]));
@@ -2808,7 +2813,7 @@ impl BigInt {
2808
2813
/// # Examples
2809
2814
///
2810
2815
/// ```
2811
- /// use num::bigint ::{ToBigInt, Sign};
2816
+ /// use num_bigint ::{ToBigInt, Sign};
2812
2817
///
2813
2818
/// let i = -1125.to_bigint().unwrap();
2814
2819
/// assert_eq!(i.to_bytes_be(), (Sign::Minus, vec![4, 101]));
@@ -2824,7 +2829,7 @@ impl BigInt {
2824
2829
/// # Examples
2825
2830
///
2826
2831
/// ```
2827
- /// use num::bigint ::BigInt;
2832
+ /// use num_bigint ::BigInt;
2828
2833
///
2829
2834
/// let i = BigInt::parse_bytes(b"ff", 16).unwrap();
2830
2835
/// assert_eq!(i.to_str_radix(16), "ff");
@@ -2846,7 +2851,7 @@ impl BigInt {
2846
2851
/// # Examples
2847
2852
///
2848
2853
/// ```
2849
- /// use num::bigint ::{ToBigInt, Sign};
2854
+ /// use num_bigint ::{ToBigInt, Sign};
2850
2855
///
2851
2856
/// assert_eq!(ToBigInt::to_bigint(&1234).unwrap().sign(), Sign::Plus);
2852
2857
/// assert_eq!(ToBigInt::to_bigint(&-4321).unwrap().sign(), Sign::Minus);
@@ -2862,7 +2867,7 @@ impl BigInt {
2862
2867
/// # Examples
2863
2868
///
2864
2869
/// ```
2865
- /// use num::bigint ::{BigInt, ToBigInt};
2870
+ /// use num_bigint ::{BigInt, ToBigInt};
2866
2871
///
2867
2872
/// assert_eq!(BigInt::parse_bytes(b"1234", 10), ToBigInt::to_bigint(&1234));
2868
2873
/// assert_eq!(BigInt::parse_bytes(b"ABCD", 16), ToBigInt::to_bigint(&0xABCD));
@@ -2935,9 +2940,17 @@ impl From<ParseIntError> for ParseBigIntError {
2935
2940
}
2936
2941
}
2937
2942
2943
+ #[ cfg( test) ]
2944
+ fn hash < T : hash:: Hash > ( x : & T ) -> u64 {
2945
+ use std:: hash:: Hasher ;
2946
+ let mut hasher = hash:: SipHasher :: new ( ) ;
2947
+ x. hash ( & mut hasher) ;
2948
+ hasher. finish ( )
2949
+ }
2950
+
2938
2951
#[ cfg( test) ]
2939
2952
mod biguint_tests {
2940
- use Integer ;
2953
+ use integer :: Integer ;
2941
2954
use super :: { BigDigit , BigUint , ToBigUint , big_digit} ;
2942
2955
use super :: { BigInt , RandBigInt , ToBigInt } ;
2943
2956
use super :: Sign :: Plus ;
@@ -2950,9 +2963,9 @@ mod biguint_tests {
2950
2963
use std:: { u8, u16, u32, u64, usize} ;
2951
2964
2952
2965
use rand:: thread_rng;
2953
- use { Num , Zero , One , CheckedAdd , CheckedSub , CheckedMul , CheckedDiv } ;
2954
- use { ToPrimitive , FromPrimitive } ;
2955
- use Float ;
2966
+ use traits :: { Num , Zero , One , CheckedAdd , CheckedSub , CheckedMul , CheckedDiv , ToPrimitive ,
2967
+ FromPrimitive , Float } ;
2968
+
2956
2969
2957
2970
/// Assert that an op works for all val/ref combinations
2958
2971
macro_rules! assert_op {
@@ -3083,10 +3096,10 @@ mod biguint_tests {
3083
3096
let c = BigUint :: new ( vec ! [ 1 ] ) ;
3084
3097
let d = BigUint :: new ( vec ! [ 1 , 0 , 0 , 0 , 0 , 0 ] ) ;
3085
3098
let e = BigUint :: new ( vec ! [ 0 , 0 , 0 , 0 , 0 , 1 ] ) ;
3086
- assert ! ( :: hash( & a) == :: hash( & b) ) ;
3087
- assert ! ( :: hash( & b) != :: hash( & c) ) ;
3088
- assert ! ( :: hash( & c) == :: hash( & d) ) ;
3089
- assert ! ( :: hash( & d) != :: hash( & e) ) ;
3099
+ assert ! ( super :: hash( & a) == super :: hash( & b) ) ;
3100
+ assert ! ( super :: hash( & b) != super :: hash( & c) ) ;
3101
+ assert ! ( super :: hash( & c) == super :: hash( & d) ) ;
3102
+ assert ! ( super :: hash( & d) != super :: hash( & e) ) ;
3090
3103
}
3091
3104
3092
3105
const BIT_TESTS : & ' static [ ( & ' static [ BigDigit ] ,
@@ -4173,7 +4186,6 @@ mod biguint_tests {
4173
4186
4174
4187
#[ cfg( test) ]
4175
4188
mod bigint_tests {
4176
- use Integer ;
4177
4189
use super :: { BigDigit , BigUint , ToBigUint } ;
4178
4190
use super :: { Sign , BigInt , RandBigInt , ToBigInt , big_digit} ;
4179
4191
use super :: Sign :: { Minus , NoSign , Plus } ;
@@ -4187,8 +4199,8 @@ mod bigint_tests {
4187
4199
4188
4200
use rand:: thread_rng;
4189
4201
4190
- use { Zero , One , Signed , ToPrimitive , FromPrimitive , Num } ;
4191
- use Float ;
4202
+ use integer :: Integer ;
4203
+ use traits :: { Zero , One , Signed , ToPrimitive , FromPrimitive , Num , Float } ;
4192
4204
4193
4205
/// Assert that an op works for all val/ref combinations
4194
4206
macro_rules! assert_op {
@@ -4334,11 +4346,11 @@ mod bigint_tests {
4334
4346
let d = BigInt :: new ( Plus , vec ! [ 1 , 0 , 0 , 0 , 0 , 0 ] ) ;
4335
4347
let e = BigInt :: new ( Plus , vec ! [ 0 , 0 , 0 , 0 , 0 , 1 ] ) ;
4336
4348
let f = BigInt :: new ( Minus , vec ! [ 1 ] ) ;
4337
- assert ! ( :: hash( & a) == :: hash( & b) ) ;
4338
- assert ! ( :: hash( & b) != :: hash( & c) ) ;
4339
- assert ! ( :: hash( & c) == :: hash( & d) ) ;
4340
- assert ! ( :: hash( & d) != :: hash( & e) ) ;
4341
- assert ! ( :: hash( & c) != :: hash( & f) ) ;
4349
+ assert ! ( super :: hash( & a) == super :: hash( & b) ) ;
4350
+ assert ! ( super :: hash( & b) != super :: hash( & c) ) ;
4351
+ assert ! ( super :: hash( & c) == super :: hash( & d) ) ;
4352
+ assert ! ( super :: hash( & d) != super :: hash( & e) ) ;
4353
+ assert ! ( super :: hash( & c) != super :: hash( & f) ) ;
4342
4354
}
4343
4355
4344
4356
#[ test]
0 commit comments