@@ -16,9 +16,9 @@ A `BigUint` is represented as an array of `BigDigit`s.
16
16
A `BigInt` is a combination of `BigUint` and `Sign`.
17
17
*/
18
18
19
+ use std:: cmp;
19
20
use std:: cmp:: { Eq , Ord , TotalEq , TotalOrd , Ordering , Less , Equal , Greater } ;
20
- use std:: num;
21
- use std:: num:: { Zero , One , ToStrRadix , FromStrRadix , Orderable } ;
21
+ use std:: num:: { Zero , One , ToStrRadix , FromStrRadix } ;
22
22
use std:: num:: { Bitwise , ToPrimitive , FromPrimitive } ;
23
23
use std:: rand:: Rng ;
24
24
use std:: str;
@@ -133,27 +133,9 @@ impl FromStr for BigUint {
133
133
134
134
impl Num for BigUint { }
135
135
136
- impl Orderable for BigUint {
137
- #[ inline]
138
- fn min ( & self , other : & BigUint ) -> BigUint {
139
- if self < other { self . clone ( ) } else { other. clone ( ) }
140
- }
141
-
142
- #[ inline]
143
- fn max ( & self , other : & BigUint ) -> BigUint {
144
- if self > other { self . clone ( ) } else { other. clone ( ) }
145
- }
146
-
147
- #[ inline]
148
- fn clamp ( & self , mn : & BigUint , mx : & BigUint ) -> BigUint {
149
- if self > mx { mx. clone ( ) } else
150
- if self < mn { mn. clone ( ) } else { self . clone ( ) }
151
- }
152
- }
153
-
154
136
impl BitAnd < BigUint , BigUint > for BigUint {
155
137
fn bitand ( & self , other : & BigUint ) -> BigUint {
156
- let new_len = num :: min ( self . data . len ( ) , other. data . len ( ) ) ;
138
+ let new_len = cmp :: min ( self . data . len ( ) , other. data . len ( ) ) ;
157
139
let anded = vec:: from_fn ( new_len, |i| {
158
140
// i will never be less than the size of either data vector
159
141
let ai = self . data [ i] ;
@@ -166,7 +148,7 @@ impl BitAnd<BigUint, BigUint> for BigUint {
166
148
167
149
impl BitOr < BigUint , BigUint > for BigUint {
168
150
fn bitor ( & self , other : & BigUint ) -> BigUint {
169
- let new_len = num :: max ( self . data . len ( ) , other. data . len ( ) ) ;
151
+ let new_len = cmp :: max ( self . data . len ( ) , other. data . len ( ) ) ;
170
152
let ored = vec:: from_fn ( new_len, |i| {
171
153
let ai = if i < self . data . len ( ) { self . data [ i] } else { 0 } ;
172
154
let bi = if i < other. data . len ( ) { other. data [ i] } else { 0 } ;
@@ -178,7 +160,7 @@ impl BitOr<BigUint, BigUint> for BigUint {
178
160
179
161
impl BitXor < BigUint , BigUint > for BigUint {
180
162
fn bitxor ( & self , other : & BigUint ) -> BigUint {
181
- let new_len = num :: max ( self . data . len ( ) , other. data . len ( ) ) ;
163
+ let new_len = cmp :: max ( self . data . len ( ) , other. data . len ( ) ) ;
182
164
let xored = vec:: from_fn ( new_len, |i| {
183
165
let ai = if i < self . data . len ( ) { self . data [ i] } else { 0 } ;
184
166
let bi = if i < other. data . len ( ) { other. data [ i] } else { 0 } ;
@@ -223,7 +205,7 @@ impl Unsigned for BigUint {}
223
205
224
206
impl Add < BigUint , BigUint > for BigUint {
225
207
fn add ( & self , other : & BigUint ) -> BigUint {
226
- let new_len = num :: max ( self . data . len ( ) , other. data . len ( ) ) ;
208
+ let new_len = cmp :: max ( self . data . len ( ) , other. data . len ( ) ) ;
227
209
228
210
let mut carry = 0 ;
229
211
let mut sum = vec:: from_fn ( new_len, |i| {
@@ -242,7 +224,7 @@ impl Add<BigUint, BigUint> for BigUint {
242
224
243
225
impl Sub < BigUint , BigUint > for BigUint {
244
226
fn sub ( & self , other : & BigUint ) -> BigUint {
245
- let new_len = num :: max ( self . data . len ( ) , other. data . len ( ) ) ;
227
+ let new_len = cmp :: max ( self . data . len ( ) , other. data . len ( ) ) ;
246
228
247
229
let mut borrow = 0 ;
248
230
let diff = vec:: from_fn ( new_len, |i| {
@@ -278,7 +260,7 @@ impl Mul<BigUint, BigUint> for BigUint {
278
260
// = a1*b1 * base^2 +
279
261
// (a1*b1 + a0*b0 - (a1-b0)*(b1-a0)) * base +
280
262
// a0*b0
281
- let half_len = num :: max ( s_len, o_len) / 2 ;
263
+ let half_len = cmp :: max ( s_len, o_len) / 2 ;
282
264
let ( sHi, sLo) = cut_at ( self , half_len) ;
283
265
let ( oHi, oLo) = cut_at ( other, half_len) ;
284
266
@@ -315,7 +297,7 @@ impl Mul<BigUint, BigUint> for BigUint {
315
297
316
298
#[ inline]
317
299
fn cut_at ( a : & BigUint , n : uint ) -> ( BigUint , BigUint ) {
318
- let mid = num :: min ( a. data . len ( ) , n) ;
300
+ let mid = cmp :: min ( a. data . len ( ) , n) ;
319
301
return ( BigUint :: from_slice ( a. data . slice ( mid, a. data . len ( ) ) ) ,
320
302
BigUint :: from_slice ( a. data . slice ( 0 , mid) ) ) ;
321
303
}
@@ -720,7 +702,7 @@ impl BigUint {
720
702
let mut n: BigUint = Zero :: zero ( ) ;
721
703
let mut power: BigUint = One :: one ( ) ;
722
704
loop {
723
- let start = num :: max ( end, unit_len) - unit_len;
705
+ let start = cmp :: max ( end, unit_len) - unit_len;
724
706
match uint:: parse_bytes ( buf. slice ( start, end) , radix) {
725
707
Some ( d) => {
726
708
let d: Option < BigUint > = FromPrimitive :: from_uint ( d) ;
@@ -941,24 +923,6 @@ impl FromStr for BigInt {
941
923
942
924
impl Num for BigInt { }
943
925
944
- impl Orderable for BigInt {
945
- #[ inline]
946
- fn min ( & self , other : & BigInt ) -> BigInt {
947
- if self < other { self . clone ( ) } else { other. clone ( ) }
948
- }
949
-
950
- #[ inline]
951
- fn max ( & self , other : & BigInt ) -> BigInt {
952
- if self > other { self . clone ( ) } else { other. clone ( ) }
953
- }
954
-
955
- #[ inline]
956
- fn clamp ( & self , mn : & BigInt , mx : & BigInt ) -> BigInt {
957
- if self > mx { mx. clone ( ) } else
958
- if self < mn { mn. clone ( ) } else { self . clone ( ) }
959
- }
960
- }
961
-
962
926
impl Shl < uint , BigInt > for BigInt {
963
927
#[ inline]
964
928
fn shl ( & self , rhs : & uint ) -> BigInt {
0 commit comments