Skip to content

Commit 1242772

Browse files
committed
auto merge of rust-lang#17005 : bjz/rust/bit-count, r=thestinger
Fixes rust-lang/rfcs#224
2 parents ee72e46 + 88bd646 commit 1242772

File tree

4 files changed

+17
-17
lines changed

4 files changed

+17
-17
lines changed

src/libcore/num/mod.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ pub trait Int: Primitive
406406
///
407407
/// assert_eq!(n.count_ones(), 3);
408408
/// ```
409-
fn count_ones(self) -> Self;
409+
fn count_ones(self) -> uint;
410410

411411
/// Returns the number of zeros in the binary representation of the integer.
412412
///
@@ -418,7 +418,7 @@ pub trait Int: Primitive
418418
/// assert_eq!(n.count_zeros(), 5);
419419
/// ```
420420
#[inline]
421-
fn count_zeros(self) -> Self {
421+
fn count_zeros(self) -> uint {
422422
(!self).count_ones()
423423
}
424424

@@ -432,7 +432,7 @@ pub trait Int: Primitive
432432
///
433433
/// assert_eq!(n.leading_zeros(), 10);
434434
/// ```
435-
fn leading_zeros(self) -> Self;
435+
fn leading_zeros(self) -> uint;
436436

437437
/// Returns the number of trailing zeros in the binary representation
438438
/// of the integer.
@@ -444,7 +444,7 @@ pub trait Int: Primitive
444444
///
445445
/// assert_eq!(n.trailing_zeros(), 3);
446446
/// ```
447-
fn trailing_zeros(self) -> Self;
447+
fn trailing_zeros(self) -> uint;
448448

449449
/// Shifts the bits to the left by a specified amount amount, `n`, wrapping
450450
/// the truncated bits to the end of the resulting integer.
@@ -569,13 +569,13 @@ macro_rules! int_impl {
569569
($T:ty, $BITS:expr, $ctpop:path, $ctlz:path, $cttz:path, $bswap:path) => {
570570
impl Int for $T {
571571
#[inline]
572-
fn count_ones(self) -> $T { unsafe { $ctpop(self) } }
572+
fn count_ones(self) -> uint { unsafe { $ctpop(self) as uint } }
573573

574574
#[inline]
575-
fn leading_zeros(self) -> $T { unsafe { $ctlz(self) } }
575+
fn leading_zeros(self) -> uint { unsafe { $ctlz(self) as uint } }
576576

577577
#[inline]
578-
fn trailing_zeros(self) -> $T { unsafe { $cttz(self) } }
578+
fn trailing_zeros(self) -> uint { unsafe { $cttz(self) as uint } }
579579

580580
#[inline]
581581
fn rotate_left(self, n: uint) -> $T {
@@ -629,13 +629,13 @@ macro_rules! int_cast_impl {
629629
($T:ty, $U:ty) => {
630630
impl Int for $T {
631631
#[inline]
632-
fn count_ones(self) -> $T { (self as $U).count_ones() as $T }
632+
fn count_ones(self) -> uint { (self as $U).count_ones() }
633633

634634
#[inline]
635-
fn leading_zeros(self) -> $T { (self as $U).leading_zeros() as $T }
635+
fn leading_zeros(self) -> uint { (self as $U).leading_zeros() }
636636

637637
#[inline]
638-
fn trailing_zeros(self) -> $T { (self as $U).trailing_zeros() as $T }
638+
fn trailing_zeros(self) -> uint { (self as $U).trailing_zeros() }
639639

640640
#[inline]
641641
fn rotate_left(self, n: uint) -> $T { (self as $U).rotate_left(n) as $T }

src/libcoretest/num/int_macros.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ mod tests {
9595

9696
#[test]
9797
fn test_count_zeros() {
98-
assert!(A.count_zeros() == BITS as $T - 3);
99-
assert!(B.count_zeros() == BITS as $T - 2);
100-
assert!(C.count_zeros() == BITS as $T - 5);
98+
assert!(A.count_zeros() == BITS - 3);
99+
assert!(B.count_zeros() == BITS - 2);
100+
assert!(C.count_zeros() == BITS - 5);
101101
}
102102

103103
#[test]

src/libcoretest/num/uint_macros.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ mod tests {
5555

5656
#[test]
5757
fn test_count_zeros() {
58-
assert!(A.count_zeros() == BITS as $T - 3);
59-
assert!(B.count_zeros() == BITS as $T - 2);
60-
assert!(C.count_zeros() == BITS as $T - 5);
58+
assert!(A.count_zeros() == BITS - 3);
59+
assert!(B.count_zeros() == BITS - 2);
60+
assert!(C.count_zeros() == BITS - 5);
6161
}
6262

6363
#[test]

src/libnum/bigint.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -807,7 +807,7 @@ impl BigUint {
807807
pub fn bits(&self) -> uint {
808808
if self.is_zero() { return 0; }
809809
let zeros = self.data.last().unwrap().leading_zeros();
810-
return self.data.len()*BigDigit::bits - (zeros as uint);
810+
return self.data.len()*BigDigit::bits - zeros;
811811
}
812812
}
813813

0 commit comments

Comments
 (0)