Skip to content

Commit f7ab9ce

Browse files
committed
Cleanup int and uint
1 parent 8a7b20b commit f7ab9ce

File tree

11 files changed

+132
-133
lines changed

11 files changed

+132
-133
lines changed

src/chacha.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ use core::prelude::*;
1414
use core::num::Int;
1515
use {Rng, SeedableRng, Rand};
1616

17-
const KEY_WORDS : uint = 8; // 8 words for the 256-bit key
18-
const STATE_WORDS : uint = 16;
19-
const CHACHA_ROUNDS: uint = 20; // Cryptographically secure from 8 upwards as of this writing
17+
const KEY_WORDS : usize = 8; // 8 words for the 256-bit key
18+
const STATE_WORDS : usize = 16;
19+
const CHACHA_ROUNDS: usize = 20; // Cryptographically secure from 8 upwards as of this writing
2020

2121
/// A random number generator that uses the ChaCha20 algorithm [1].
2222
///
@@ -31,7 +31,7 @@ const CHACHA_ROUNDS: uint = 20; // Cryptographically secure from 8 upwards as of
3131
pub struct ChaChaRng {
3232
buffer: [u32; STATE_WORDS], // Internal buffer of output
3333
state: [u32; STATE_WORDS], // Initial state
34-
index: uint, // Index into state
34+
index: usize, // Index into state
3535
}
3636

3737
static EMPTY: ChaChaRng = ChaChaRng {
@@ -268,9 +268,9 @@ mod test {
268268
// Store the 17*i-th 32-bit word,
269269
// i.e., the i-th word of the i-th 16-word block
270270
let mut v : Vec<u32> = Vec::new();
271-
for _ in 0u..16 {
271+
for _ in 0..16 {
272272
v.push(ra.next_u32());
273-
for _ in 0u..16 {
273+
for _ in 0..16 {
274274
ra.next_u32();
275275
}
276276
}
@@ -287,7 +287,7 @@ mod test {
287287
let seed : &[_] = &[0u32; 8];
288288
let mut rng: ChaChaRng = SeedableRng::from_seed(seed);
289289
let mut clone = rng.clone();
290-
for _ in 0u..16 {
290+
for _ in 0..16 {
291291
assert_eq!(rng.next_u64(), clone.next_u64());
292292
}
293293
}

src/distributions/exponential.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ mod test {
100100
fn test_exp() {
101101
let mut exp = Exp::new(10.0);
102102
let mut rng = ::test::rng();
103-
for _ in 0u..1000 {
103+
for _ in 0..1000 {
104104
assert!(exp.sample(&mut rng) >= 0.0);
105105
assert!(exp.ind_sample(&mut rng) >= 0.0);
106106
}

src/distributions/gamma.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ mod test {
326326
fn test_chi_squared_one() {
327327
let mut chi = ChiSquared::new(1.0);
328328
let mut rng = ::test::rng();
329-
for _ in 0u..1000 {
329+
for _ in 0..1000 {
330330
chi.sample(&mut rng);
331331
chi.ind_sample(&mut rng);
332332
}
@@ -335,7 +335,7 @@ mod test {
335335
fn test_chi_squared_small() {
336336
let mut chi = ChiSquared::new(0.5);
337337
let mut rng = ::test::rng();
338-
for _ in 0u..1000 {
338+
for _ in 0..1000 {
339339
chi.sample(&mut rng);
340340
chi.ind_sample(&mut rng);
341341
}
@@ -344,7 +344,7 @@ mod test {
344344
fn test_chi_squared_large() {
345345
let mut chi = ChiSquared::new(30.0);
346346
let mut rng = ::test::rng();
347-
for _ in 0u..1000 {
347+
for _ in 0..1000 {
348348
chi.sample(&mut rng);
349349
chi.ind_sample(&mut rng);
350350
}
@@ -359,7 +359,7 @@ mod test {
359359
fn test_f() {
360360
let mut f = FisherF::new(2.0, 32.0);
361361
let mut rng = ::test::rng();
362-
for _ in 0u..1000 {
362+
for _ in 0..1000 {
363363
f.sample(&mut rng);
364364
f.ind_sample(&mut rng);
365365
}
@@ -369,7 +369,7 @@ mod test {
369369
fn test_t() {
370370
let mut t = StudentT::new(11.0);
371371
let mut rng = ::test::rng();
372-
for _ in 0u..1000 {
372+
for _ in 0..1000 {
373373
t.sample(&mut rng);
374374
t.ind_sample(&mut rng);
375375
}

src/distributions/mod.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ impl<Sup: Rand> IndependentSample<Sup> for RandSample<Sup> {
7171
/// A value with a particular weight for use with `WeightedChoice`.
7272
pub struct Weighted<T> {
7373
/// The numerical weight of this item
74-
pub weight: uint,
74+
pub weight: usize,
7575
/// The actual item which is being weighted
7676
pub item: T,
7777
}
@@ -83,7 +83,7 @@ pub struct Weighted<T> {
8383
///
8484
/// The `Clone` restriction is a limitation of the `Sample` and
8585
/// `IndependentSample` traits. Note that `&T` is (cheaply) `Clone` for
86-
/// all `T`, as is `uint`, so one can store references or indices into
86+
/// all `T`, as is `usize`, so one can store references or indices into
8787
/// another vector.
8888
///
8989
/// # Example
@@ -96,14 +96,14 @@ pub struct Weighted<T> {
9696
/// Weighted { weight: 1, item: 'c' });
9797
/// let wc = WeightedChoice::new(items.as_mut_slice());
9898
/// let mut rng = rand::thread_rng();
99-
/// for _ in 0u..16 {
99+
/// for _ in 0..16 {
100100
/// // on average prints 'a' 4 times, 'b' 8 and 'c' twice.
101101
/// println!("{}", wc.ind_sample(&mut rng));
102102
/// }
103103
/// ```
104104
pub struct WeightedChoice<'a, T:'a> {
105105
items: &'a mut [Weighted<T>],
106-
weight_range: Range<uint>
106+
weight_range: Range<usize>
107107
}
108108

109109
impl<'a, T: Clone> WeightedChoice<'a, T> {
@@ -112,12 +112,12 @@ impl<'a, T: Clone> WeightedChoice<'a, T> {
112112
/// Panics if:
113113
/// - `v` is empty
114114
/// - the total weight is 0
115-
/// - the total weight is larger than a `uint` can contain.
115+
/// - the total weight is larger than a `usize` can contain.
116116
pub fn new(items: &'a mut [Weighted<T>]) -> WeightedChoice<'a, T> {
117117
// strictly speaking, this is subsumed by the total weight == 0 case
118118
assert!(!items.is_empty(), "WeightedChoice::new called with no items");
119119

120-
let mut running_total = 0u;
120+
let mut running_total = 0;
121121

122122
// we convert the list from individual weights to cumulative
123123
// weights so we can binary search. This *could* drop elements
@@ -126,7 +126,7 @@ impl<'a, T: Clone> WeightedChoice<'a, T> {
126126
running_total = match running_total.checked_add(item.weight) {
127127
Some(n) => n,
128128
None => panic!("WeightedChoice::new called with a total weight \
129-
larger than a uint can contain")
129+
larger than a usize can contain")
130130
};
131131

132132
item.weight = running_total;
@@ -231,7 +231,7 @@ fn ziggurat<R: Rng, P, Z>(
231231
// this may be slower than it would be otherwise.)
232232
// FIXME: investigate/optimise for the above.
233233
let bits: u64 = rng.gen();
234-
let i = (bits & 0xff) as uint;
234+
let i = (bits & 0xff) as usize;
235235
let f = (bits >> 11) as f64 / SCALE;
236236

237237
// u is either U(-1, 1) or U(0, 1) depending on if this is a
@@ -263,7 +263,7 @@ mod tests {
263263
use super::{RandSample, WeightedChoice, Weighted, Sample, IndependentSample};
264264

265265
#[derive(PartialEq, Debug)]
266-
struct ConstRand(uint);
266+
struct ConstRand(usize);
267267
impl Rand for ConstRand {
268268
fn rand<R: Rng>(_: &mut R) -> ConstRand {
269269
ConstRand(0)
@@ -345,7 +345,7 @@ mod tests {
345345

346346
#[test] #[should_fail]
347347
fn test_weighted_choice_no_items() {
348-
WeightedChoice::<int>::new(&mut []);
348+
WeightedChoice::<isize>::new(&mut []);
349349
}
350350
#[test] #[should_fail]
351351
fn test_weighted_choice_zero_weight() {
@@ -354,7 +354,7 @@ mod tests {
354354
}
355355
#[test] #[should_fail]
356356
fn test_weighted_choice_weight_overflows() {
357-
let x = (-1) as uint / 2; // x + x + 2 is the overflow
357+
let x = !0us / 2; // x + x + 2 is the overflow
358358
WeightedChoice::new(&mut [Weighted { weight: x, item: 0 },
359359
Weighted { weight: 1, item: 1 },
360360
Weighted { weight: x, item: 2 },

src/distributions/normal.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ mod tests {
165165
fn test_normal() {
166166
let mut norm = Normal::new(10.0, 10.0);
167167
let mut rng = ::test::rng();
168-
for _ in 0u..1000 {
168+
for _ in 0..1000 {
169169
norm.sample(&mut rng);
170170
norm.ind_sample(&mut rng);
171171
}
@@ -181,7 +181,7 @@ mod tests {
181181
fn test_log_normal() {
182182
let mut lnorm = LogNormal::new(10.0, 10.0);
183183
let mut rng = ::test::rng();
184-
for _ in 0u..1000 {
184+
for _ in 0..1000 {
185185
lnorm.sample(&mut rng);
186186
lnorm.ind_sample(&mut rng);
187187
}

src/distributions/range.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ use distributions::{Sample, IndependentSample};
3838
/// use rand::distributions::{IndependentSample, Range};
3939
///
4040
/// fn main() {
41-
/// let between = Range::new(10u, 10000u);
41+
/// let between = Range::new(10, 10000);
4242
/// let mut rng = rand::thread_rng();
4343
/// let mut sum = 0;
44-
/// for _ in 0u..1000 {
44+
/// for _ in 0..1000 {
4545
/// sum += between.ind_sample(&mut rng);
4646
/// }
4747
/// println!("{}", sum);
@@ -134,12 +134,12 @@ integer_impl! { i8, u8 }
134134
integer_impl! { i16, u16 }
135135
integer_impl! { i32, u32 }
136136
integer_impl! { i64, u64 }
137-
integer_impl! { int, uint }
137+
integer_impl! { isize, usize }
138138
integer_impl! { u8, u8 }
139139
integer_impl! { u16, u16 }
140140
integer_impl! { u32, u32 }
141141
integer_impl! { u64, u64 }
142-
integer_impl! { uint, uint }
142+
integer_impl! { usize, usize }
143143

144144
macro_rules! float_impl {
145145
($ty:ty) => {
@@ -190,7 +190,7 @@ mod tests {
190190
(Int::min_value(), Int::max_value())];
191191
for &(low, high) in v.iter() {
192192
let mut sampler: Range<$ty> = Range::new(low, high);
193-
for _ in 0u..1000 {
193+
for _ in 0..1000 {
194194
let v = sampler.sample(&mut rng);
195195
assert!(low <= v && v < high);
196196
let v = sampler.ind_sample(&mut rng);
@@ -200,8 +200,8 @@ mod tests {
200200
)*
201201
}}
202202
}
203-
t!(i8, i16, i32, i64, int,
204-
u8, u16, u32, u64, uint)
203+
t!(i8, i16, i32, i64, isize,
204+
u8, u16, u32, u64, usize)
205205
}
206206

207207
#[test]
@@ -216,7 +216,7 @@ mod tests {
216216
(-1e35, 1e35)];
217217
for &(low, high) in v.iter() {
218218
let mut sampler: Range<$ty> = Range::new(low, high);
219-
for _ in 0u..1000 {
219+
for _ in 0..1000 {
220220
let v = sampler.sample(&mut rng);
221221
assert!(low <= v && v < high);
222222
let v = sampler.ind_sample(&mut rng);

0 commit comments

Comments
 (0)