Skip to content

Commit 347128a

Browse files
committed
Merge pull request #4 from nagisa/purge-ints
Cleanup int and uint
2 parents 8cdf2a4 + 396e02a commit 347128a

File tree

12 files changed

+133
-134
lines changed

12 files changed

+133
-134
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
@@ -68,7 +68,7 @@ impl<Sup: Rand> IndependentSample<Sup> for RandSample<Sup> {
6868
/// A value with a particular weight for use with `WeightedChoice`.
6969
pub struct Weighted<T> {
7070
/// The numerical weight of this item
71-
pub weight: uint,
71+
pub weight: usize,
7272
/// The actual item which is being weighted
7373
pub item: T,
7474
}
@@ -80,7 +80,7 @@ pub struct Weighted<T> {
8080
///
8181
/// The `Clone` restriction is a limitation of the `Sample` and
8282
/// `IndependentSample` traits. Note that `&T` is (cheaply) `Clone` for
83-
/// all `T`, as is `uint`, so one can store references or indices into
83+
/// all `T`, as is `usize`, so one can store references or indices into
8484
/// another vector.
8585
///
8686
/// # Example
@@ -93,14 +93,14 @@ pub struct Weighted<T> {
9393
/// Weighted { weight: 1, item: 'c' });
9494
/// let wc = WeightedChoice::new(items.as_mut_slice());
9595
/// let mut rng = rand::thread_rng();
96-
/// for _ in 0u..16 {
96+
/// for _ in 0..16 {
9797
/// // on average prints 'a' 4 times, 'b' 8 and 'c' twice.
9898
/// println!("{}", wc.ind_sample(&mut rng));
9999
/// }
100100
/// ```
101101
pub struct WeightedChoice<'a, T:'a> {
102102
items: &'a mut [Weighted<T>],
103-
weight_range: Range<uint>
103+
weight_range: Range<usize>
104104
}
105105

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

117-
let mut running_total = 0u;
117+
let mut running_total = 0;
118118

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

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

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

262262
#[derive(PartialEq, Debug)]
263-
struct ConstRand(uint);
263+
struct ConstRand(usize);
264264
impl Rand for ConstRand {
265265
fn rand<R: Rng>(_: &mut R) -> ConstRand {
266266
ConstRand(0)
@@ -342,7 +342,7 @@ mod tests {
342342

343343
#[test] #[should_fail]
344344
fn test_weighted_choice_no_items() {
345-
WeightedChoice::<int>::new(&mut []);
345+
WeightedChoice::<isize>::new(&mut []);
346346
}
347347
#[test] #[should_fail]
348348
fn test_weighted_choice_zero_weight() {
@@ -351,7 +351,7 @@ mod tests {
351351
}
352352
#[test] #[should_fail]
353353
fn test_weighted_choice_weight_overflows() {
354-
let x = (-1) as uint / 2; // x + x + 2 is the overflow
354+
let x = !0us / 2; // x + x + 2 is the overflow
355355
WeightedChoice::new(&mut [Weighted { weight: x, item: 0 },
356356
Weighted { weight: 1, item: 1 },
357357
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)