@@ -275,11 +275,10 @@ pub impl BigUint {
275
275
276
276
static pub pure fn zero ( ) -> BigUint { BigUint :: from_at_vec ( @[ ] ) }
277
277
static pub pure fn one ( ) -> BigUint { BigUint :: from_at_vec ( @[ 1 ] ) }
278
-
279
- pure fn abs ( ) -> BigUint { self }
278
+ pure fn abs ( & self ) -> BigUint { * self }
280
279
281
280
/// Compare two BigUint value.
282
- pure fn cmp ( other : & BigUint ) -> int {
281
+ pure fn cmp ( & self , other : & BigUint ) -> int {
283
282
let s_len = self . data . len ( ) , o_len = other. data . len ( ) ;
284
283
if s_len < o_len { return -1 ; }
285
284
if s_len > o_len { return 1 ; }
@@ -294,13 +293,13 @@ pub impl BigUint {
294
293
return 0 ;
295
294
}
296
295
297
- pure fn divmod ( other : & BigUint ) -> ( BigUint , BigUint ) {
296
+ pure fn divmod ( & self , other : & BigUint ) -> ( BigUint , BigUint ) {
298
297
if other. is_zero ( ) { fail }
299
298
if self . is_zero ( ) { return ( BigUint :: zero ( ) , BigUint :: zero ( ) ) ; }
300
- if * other == BigUint :: one ( ) { return ( self , BigUint :: zero ( ) ) ; }
299
+ if * other == BigUint :: one ( ) { return ( * self , BigUint :: zero ( ) ) ; }
301
300
302
301
match self . cmp ( other) {
303
- s if s < 0 => return ( BigUint :: zero ( ) , self ) ,
302
+ s if s < 0 => return ( BigUint :: zero ( ) , * self ) ,
304
303
0 => return ( BigUint :: one ( ) , BigUint :: zero ( ) ) ,
305
304
_ => { } // Do nothing
306
305
}
@@ -363,20 +362,24 @@ pub impl BigUint {
363
362
}
364
363
}
365
364
366
- pure fn quot ( other : & BigUint ) -> BigUint { self . quotrem ( other) . first ( ) }
367
- pure fn rem ( other : & BigUint ) -> BigUint { self . quotrem ( other) . second ( ) }
368
- pure fn quotrem ( other : & BigUint ) -> ( BigUint , BigUint ) {
365
+ pure fn quot ( & self , other : & BigUint ) -> BigUint {
366
+ self . quotrem ( other) . first ( )
367
+ }
368
+ pure fn rem ( & self , other : & BigUint ) -> BigUint {
369
+ self . quotrem ( other) . second ( )
370
+ }
371
+ pure fn quotrem ( & self , other : & BigUint ) -> ( BigUint , BigUint ) {
369
372
self . divmod ( other)
370
373
}
371
374
372
- pure fn is_zero ( ) -> bool { self . data . is_empty ( ) }
373
- pure fn is_not_zero ( ) -> bool { self . data . is_not_empty ( ) }
374
- pure fn is_positive ( ) -> bool { self . is_not_zero ( ) }
375
- pure fn is_negative ( ) -> bool { false }
376
- pure fn is_nonpositive ( ) -> bool { self . is_zero ( ) }
377
- pure fn is_nonnegative ( ) -> bool { true }
375
+ pure fn is_zero ( & self ) -> bool { self . data . is_empty ( ) }
376
+ pure fn is_not_zero ( & self ) -> bool { self . data . is_not_empty ( ) }
377
+ pure fn is_positive ( & self ) -> bool { self . is_not_zero ( ) }
378
+ pure fn is_negative ( & self ) -> bool { false }
379
+ pure fn is_nonpositive ( & self ) -> bool { self . is_zero ( ) }
380
+ pure fn is_nonnegative ( & self ) -> bool { true }
378
381
379
- pure fn to_uint ( ) -> uint {
382
+ pure fn to_uint ( & self ) -> uint {
380
383
match self . data . len ( ) {
381
384
0 => 0 ,
382
385
1 => self . data [ 0 ] as uint ,
@@ -385,14 +388,14 @@ pub impl BigUint {
385
388
}
386
389
}
387
390
388
- pure fn to_str_radix ( radix : uint ) -> ~str {
391
+ pure fn to_str_radix ( & self , radix : uint ) -> ~str {
389
392
assert 1 < radix && radix <= 16 ;
390
393
391
- pure fn convert_base ( n : BigUint , base : uint ) -> @[ BigDigit ] {
394
+ pure fn convert_base ( n : & BigUint , base : uint ) -> @[ BigDigit ] {
392
395
if base == BigDigit :: base { return n. data ; }
393
396
let divider = BigUint :: from_uint ( base) ;
394
397
let mut result = @[ ] ;
395
- let mut r = n;
398
+ let mut r = * n;
396
399
while r > divider {
397
400
let ( d, r0) = r. divmod ( & divider) ;
398
401
result += [ r0. to_uint ( ) as BigDigit ] ;
@@ -416,14 +419,14 @@ pub impl BigUint {
416
419
return fill_concat ( convert_base ( self , base) , radix, max_len) ;
417
420
}
418
421
419
- priv pure fn shl_unit ( n_unit : uint ) -> BigUint {
420
- if n_unit == 0 || self . is_zero ( ) { return self ; }
422
+ priv pure fn shl_unit ( & self , n_unit : uint ) -> BigUint {
423
+ if n_unit == 0 || self . is_zero ( ) { return * self ; }
421
424
422
425
return BigUint :: from_at_vec ( at_vec:: from_elem ( n_unit, 0 ) + self . data ) ;
423
426
}
424
427
425
- priv pure fn shl_bits ( n_bits : uint ) -> BigUint {
426
- if n_bits == 0 || self . is_zero ( ) { return self ; }
428
+ priv pure fn shl_bits ( & self , n_bits : uint ) -> BigUint {
429
+ if n_bits == 0 || self . is_zero ( ) { return * self ; }
427
430
428
431
let mut carry = 0 ;
429
432
let shifted = do at_vec:: map ( self . data ) |elem| {
@@ -437,16 +440,16 @@ pub impl BigUint {
437
440
return BigUint :: from_at_vec ( shifted + [ carry] ) ;
438
441
}
439
442
440
- priv pure fn shr_unit ( n_unit : uint ) -> BigUint {
441
- if n_unit == 0 { return self ; }
443
+ priv pure fn shr_unit ( & self , n_unit : uint ) -> BigUint {
444
+ if n_unit == 0 { return * self ; }
442
445
if self . data . len ( ) < n_unit { return BigUint :: zero ( ) ; }
443
446
return BigUint :: from_slice (
444
447
vec:: view ( self . data , n_unit, self . data . len ( ) )
445
448
) ;
446
449
}
447
450
448
- priv pure fn shr_bits( n_bits : uint ) -> BigUint {
449
- if n_bits == 0 || self . data . is_empty ( ) { return self ; }
451
+ priv pure fn shr_bits( & self , n_bits : uint ) -> BigUint {
452
+ if n_bits == 0 || self . data . is_empty ( ) { return * self ; }
450
453
451
454
let mut borrow = 0 ;
452
455
let mut shifted = @[ ] ;
@@ -499,17 +502,17 @@ impl Sign : Ord {
499
502
500
503
pub impl Sign {
501
504
/// Compare two Sign.
502
- pure fn cmp ( other : & Sign ) -> int {
503
- match ( self , * other) {
505
+ pure fn cmp ( & self , other : & Sign ) -> int {
506
+ match ( * self , * other) {
504
507
( Minus , Minus ) | ( Zero , Zero ) | ( Plus , Plus ) => 0 ,
505
508
( Minus , Zero ) | ( Minus , Plus ) | ( Zero , Plus ) => -1 ,
506
509
_ => 1
507
510
}
508
511
}
509
512
510
513
/// Negate Sign value.
511
- pure fn neg ( ) -> Sign {
512
- match ( self ) {
514
+ pure fn neg ( & self ) -> Sign {
515
+ match * self {
513
516
Minus => Plus ,
514
517
Zero => Zero ,
515
518
Plus => Minus
@@ -682,9 +685,9 @@ pub impl BigInt {
682
685
BigInt :: from_biguint ( Plus , BigUint :: one ( ) )
683
686
}
684
687
685
- pure fn abs ( ) -> BigInt { BigInt :: from_biguint ( Plus , self . data ) }
688
+ pure fn abs ( & self ) -> BigInt { BigInt :: from_biguint ( Plus , self . data ) }
686
689
687
- pure fn cmp ( other : & BigInt ) -> int {
690
+ pure fn cmp ( & self , other : & BigInt ) -> int {
688
691
let ss = self . sign , os = other. sign ;
689
692
if ss < os { return -1 ; }
690
693
if ss > os { return 1 ; }
@@ -697,7 +700,7 @@ pub impl BigInt {
697
700
}
698
701
}
699
702
700
- pure fn divmod ( other : & BigInt ) -> ( BigInt , BigInt ) {
703
+ pure fn divmod ( & self , other : & BigInt ) -> ( BigInt , BigInt ) {
701
704
// m.sign == other.sign
702
705
let ( d_ui, m_ui) = self . data . divmod ( & other. data ) ;
703
706
let d = BigInt :: from_biguint ( Plus , d_ui) ,
@@ -719,10 +722,14 @@ pub impl BigInt {
719
722
}
720
723
}
721
724
722
- pure fn quot ( other : & BigInt ) -> BigInt { self . quotrem ( other) . first ( ) }
723
- pure fn rem ( other : & BigInt ) -> BigInt { self . quotrem ( other) . second ( ) }
725
+ pure fn quot ( & self , other : & BigInt ) -> BigInt {
726
+ self . quotrem ( other) . first ( )
727
+ }
728
+ pure fn rem ( & self , other : & BigInt ) -> BigInt {
729
+ self . quotrem ( other) . second ( )
730
+ }
724
731
725
- pure fn quotrem ( other : & BigInt ) -> ( BigInt , BigInt ) {
732
+ pure fn quotrem ( & self , other : & BigInt ) -> ( BigInt , BigInt ) {
726
733
// r.sign == self.sign
727
734
let ( q_ui, r_ui) = self . data . quotrem ( & other. data ) ;
728
735
let q = BigInt :: from_biguint ( Plus , q_ui) ;
@@ -736,22 +743,22 @@ pub impl BigInt {
736
743
}
737
744
}
738
745
739
- pure fn is_zero ( ) -> bool { self . sign == Zero }
740
- pure fn is_not_zero ( ) -> bool { self . sign != Zero }
741
- pure fn is_positive ( ) -> bool { self . sign == Plus }
742
- pure fn is_negative ( ) -> bool { self . sign == Minus }
743
- pure fn is_nonpositive ( ) -> bool { self . sign != Plus }
744
- pure fn is_nonnegative ( ) -> bool { self . sign != Minus }
746
+ pure fn is_zero ( & self ) -> bool { self . sign == Zero }
747
+ pure fn is_not_zero ( & self ) -> bool { self . sign != Zero }
748
+ pure fn is_positive ( & self ) -> bool { self . sign == Plus }
749
+ pure fn is_negative ( & self ) -> bool { self . sign == Minus }
750
+ pure fn is_nonpositive ( & self ) -> bool { self . sign != Plus }
751
+ pure fn is_nonnegative ( & self ) -> bool { self . sign != Minus }
745
752
746
- pure fn to_uint ( ) -> uint {
753
+ pure fn to_uint ( & self ) -> uint {
747
754
match self . sign {
748
755
Plus => self . data . to_uint ( ) ,
749
756
Zero => 0 ,
750
757
Minus => 0
751
758
}
752
759
}
753
760
754
- pure fn to_str_radix( radix : uint ) -> ~str {
761
+ pure fn to_str_radix( & self , radix : uint ) -> ~str {
755
762
match self . sign {
756
763
Plus => self . data . to_str_radix ( radix) ,
757
764
Zero => ~"0 ",
0 commit comments