Mass rename uint/int to usize/isize

Now that support has been removed, all lingering use cases are renamed.
This commit is contained in:
Alex Crichton 2015-03-25 17:06:52 -07:00
parent 54f16b818b
commit 43bfaa4a33
1391 changed files with 5180 additions and 5238 deletions

View file

@ -15,9 +15,9 @@ use core::num::Int;
use core::num::wrapping::WrappingOps;
use {Rng, SeedableRng, Rand};
const KEY_WORDS : uint = 8; // 8 words for the 256-bit key
const STATE_WORDS : uint = 16;
const CHACHA_ROUNDS: uint = 20; // Cryptographically secure from 8 upwards as of this writing
const KEY_WORDS : usize = 8; // 8 words for the 256-bit key
const STATE_WORDS : usize = 16;
const CHACHA_ROUNDS: usize = 20; // Cryptographically secure from 8 upwards as of this writing
/// A random number generator that uses the ChaCha20 algorithm [1].
///
@ -32,7 +32,7 @@ const CHACHA_ROUNDS: uint = 20; // Cryptographically secure from 8 upwards as of
pub struct ChaChaRng {
buffer: [u32; STATE_WORDS], // Internal buffer of output
state: [u32; STATE_WORDS], // Initial state
index: uint, // Index into state
index: usize, // Index into state
}
static EMPTY: ChaChaRng = ChaChaRng {

View file

@ -76,7 +76,7 @@ impl<Sup: Rand> IndependentSample<Sup> for RandSample<Sup> {
/// A value with a particular weight for use with `WeightedChoice`.
pub struct Weighted<T> {
/// The numerical weight of this item
pub weight: uint,
pub weight: usize,
/// The actual item which is being weighted
pub item: T,
}
@ -88,7 +88,7 @@ pub struct Weighted<T> {
///
/// The `Clone` restriction is a limitation of the `Sample` and
/// `IndependentSample` traits. Note that `&T` is (cheaply) `Clone` for
/// all `T`, as is `uint`, so one can store references or indices into
/// all `T`, as is `usize`, so one can store references or indices into
/// another vector.
///
/// # Examples
@ -110,7 +110,7 @@ pub struct Weighted<T> {
/// ```
pub struct WeightedChoice<'a, T:'a> {
items: &'a mut [Weighted<T>],
weight_range: Range<uint>
weight_range: Range<usize>
}
impl<'a, T: Clone> WeightedChoice<'a, T> {
@ -119,7 +119,7 @@ impl<'a, T: Clone> WeightedChoice<'a, T> {
/// Panics if:
/// - `v` is empty
/// - the total weight is 0
/// - the total weight is larger than a `uint` can contain.
/// - the total weight is larger than a `usize` can contain.
pub fn new(items: &'a mut [Weighted<T>]) -> WeightedChoice<'a, T> {
// strictly speaking, this is subsumed by the total weight == 0 case
assert!(!items.is_empty(), "WeightedChoice::new called with no items");
@ -133,7 +133,7 @@ impl<'a, T: Clone> WeightedChoice<'a, T> {
running_total = match running_total.checked_add(item.weight) {
Some(n) => n,
None => panic!("WeightedChoice::new called with a total weight \
larger than a uint can contain")
larger than a usize can contain")
};
item.weight = running_total;
@ -238,7 +238,7 @@ fn ziggurat<R: Rng, P, Z>(
// this may be slower than it would be otherwise.)
// FIXME: investigate/optimise for the above.
let bits: u64 = rng.gen();
let i = (bits & 0xff) as uint;
let i = (bits & 0xff) as usize;
let f = (bits >> 11) as f64 / SCALE;
// u is either U(-1, 1) or U(0, 1) depending on if this is a
@ -270,7 +270,7 @@ mod tests {
use super::{RandSample, WeightedChoice, Weighted, Sample, IndependentSample};
#[derive(PartialEq, Debug)]
struct ConstRand(uint);
struct ConstRand(usize);
impl Rand for ConstRand {
fn rand<R: Rng>(_: &mut R) -> ConstRand {
ConstRand(0)
@ -352,7 +352,7 @@ mod tests {
#[test] #[should_panic]
fn test_weighted_choice_no_items() {
WeightedChoice::<int>::new(&mut []);
WeightedChoice::<isize>::new(&mut []);
}
#[test] #[should_panic]
fn test_weighted_choice_zero_weight() {
@ -361,7 +361,7 @@ mod tests {
}
#[test] #[should_panic]
fn test_weighted_choice_weight_overflows() {
let x = (-1) as uint / 2; // x + x + 2 is the overflow
let x = (-1) as usize / 2; // x + x + 2 is the overflow
WeightedChoice::new(&mut [Weighted { weight: x, item: 0 },
Weighted { weight: 1, item: 1 },
Weighted { weight: x, item: 2 },

View file

@ -138,12 +138,12 @@ integer_impl! { i8, u8 }
integer_impl! { i16, u16 }
integer_impl! { i32, u32 }
integer_impl! { i64, u64 }
integer_impl! { int, uint }
integer_impl! { isize, usize }
integer_impl! { u8, u8 }
integer_impl! { u16, u16 }
integer_impl! { u32, u32 }
integer_impl! { u64, u64 }
integer_impl! { uint, uint }
integer_impl! { usize, usize }
macro_rules! float_impl {
($ty:ty) => {
@ -204,8 +204,8 @@ mod tests {
)*
}}
}
t!(i8, i16, i32, i64, int,
u8, u16, u32, u64, uint)
t!(i8, i16, i32, i64, isize,
u8, u16, u32, u64, usize)
}
#[test]

View file

@ -24,7 +24,6 @@
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
html_root_url = "http://doc.rust-lang.org/nightly/",
html_playground_url = "http://play.rust-lang.org/")]
#![feature(int_uint)]
#![feature(no_std)]
#![no_std]
#![unstable(feature = "rand")]
@ -99,8 +98,8 @@ pub trait Rng : Sized {
/// See `Closed01` for the closed interval `[0,1]`, and
/// `Open01` for the open interval `(0,1)`.
fn next_f32(&mut self) -> f32 {
const MANTISSA_BITS: uint = 24;
const IGNORED_BITS: uint = 8;
const MANTISSA_BITS: usize = 24;
const IGNORED_BITS: usize = 8;
const SCALE: f32 = (1u64 << MANTISSA_BITS) as f32;
// using any more than `MANTISSA_BITS` bits will
@ -121,8 +120,8 @@ pub trait Rng : Sized {
/// See `Closed01` for the closed interval `[0,1]`, and
/// `Open01` for the open interval `(0,1)`.
fn next_f64(&mut self) -> f64 {
const MANTISSA_BITS: uint = 53;
const IGNORED_BITS: uint = 11;
const MANTISSA_BITS: usize = 53;
const IGNORED_BITS: usize = 11;
const SCALE: f64 = (1u64 << MANTISSA_BITS) as f64;
(self.next_u64() >> IGNORED_BITS) as f64 / SCALE
@ -189,7 +188,7 @@ pub trait Rng : Sized {
/// use std::rand::{thread_rng, Rng};
///
/// let mut rng = thread_rng();
/// let x: uint = rng.gen();
/// let x: usize = rng.gen();
/// println!("{}", x);
/// println!("{:?}", rng.gen::<(f64, bool)>());
/// ```
@ -208,7 +207,7 @@ pub trait Rng : Sized {
/// use std::rand::{thread_rng, Rng};
///
/// let mut rng = thread_rng();
/// let x = rng.gen_iter::<uint>().take(10).collect::<Vec<uint>>();
/// let x = rng.gen_iter::<usize>().take(10).collect::<Vec<usize>>();
/// println!("{:?}", x);
/// println!("{:?}", rng.gen_iter::<(f64, bool)>().take(5)
/// .collect::<Vec<(f64, bool)>>());
@ -236,7 +235,7 @@ pub trait Rng : Sized {
/// use std::rand::{thread_rng, Rng};
///
/// let mut rng = thread_rng();
/// let n: uint = rng.gen_range(0, 10);
/// let n: usize = rng.gen_range(0, 10);
/// println!("{}", n);
/// let m: f64 = rng.gen_range(-40.0f64, 1.3e5f64);
/// println!("{}", m);
@ -257,7 +256,7 @@ pub trait Rng : Sized {
/// let mut rng = thread_rng();
/// println!("{}", rng.gen_weighted_bool(3));
/// ```
fn gen_weighted_bool(&mut self, n: uint) -> bool {
fn gen_weighted_bool(&mut self, n: usize) -> bool {
n <= 1 || self.gen_range(0, n) == 0
}

View file

@ -18,14 +18,14 @@ use core::default::Default;
/// How many bytes of entropy the underling RNG is allowed to generate
/// before it is reseeded.
const DEFAULT_GENERATION_THRESHOLD: uint = 32 * 1024;
const DEFAULT_GENERATION_THRESHOLD: usize = 32 * 1024;
/// A wrapper around any RNG which reseeds the underlying RNG after it
/// has generated a certain number of random bytes.
pub struct ReseedingRng<R, Rsdr> {
rng: R,
generation_threshold: uint,
bytes_generated: uint,
generation_threshold: usize,
bytes_generated: usize,
/// Controls the behaviour when reseeding the RNG.
pub reseeder: Rsdr,
}
@ -38,7 +38,7 @@ impl<R: Rng, Rsdr: Reseeder<R>> ReseedingRng<R, Rsdr> {
/// * `rng`: the random number generator to use.
/// * `generation_threshold`: the number of bytes of entropy at which to reseed the RNG.
/// * `reseeder`: the reseeding object to use.
pub fn new(rng: R, generation_threshold: uint, reseeder: Rsdr) -> ReseedingRng<R,Rsdr> {
pub fn new(rng: R, generation_threshold: usize, reseeder: Rsdr) -> ReseedingRng<R,Rsdr> {
ReseedingRng {
rng: rng,
generation_threshold: generation_threshold,
@ -213,7 +213,7 @@ mod test {
assert_eq!(string1, string2);
}
const FILL_BYTES_V_LEN: uint = 13579;
const FILL_BYTES_V_LEN: usize = 13579;
#[test]
fn test_rng_fill_bytes() {
let mut v = repeat(0).take(FILL_BYTES_V_LEN).collect::<Vec<_>>();