Skip to content

Commit 404724b

Browse files
committed
stage0 split for stats.rs
1 parent e20e455 commit 404724b

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/libtest/stats.rs

+20
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212

1313
use std::cmp::Ordering::{self, Less, Greater, Equal};
1414
use std::collections::hash_map::Entry::{Occupied, Vacant};
15+
#[cfg(not(stage0))]
1516
use std::collections::hash_map;
17+
#[cfg(stage0)]
18+
use std::collections::hash_map::{self, Hasher};
1619
use std::hash::Hash;
1720
use std::mem;
1821
use std::num::{Float, FromPrimitive};
@@ -332,6 +335,7 @@ pub fn winsorize<T: Float + FromPrimitive>(samples: &mut [T], pct: T) {
332335

333336
/// Returns a HashMap with the number of occurrences of every element in the
334337
/// sequence that the iterator exposes.
338+
#[cfg(not(stage0))]
335339
pub fn freq_count<T, U>(iter: T) -> hash_map::HashMap<U, uint>
336340
where T: Iterator<Item=U>, U: Eq + Clone + Hash
337341
{
@@ -345,6 +349,22 @@ pub fn freq_count<T, U>(iter: T) -> hash_map::HashMap<U, uint>
345349
map
346350
}
347351

352+
/// Returns a HashMap with the number of occurrences of every element in the
353+
/// sequence that the iterator exposes.
354+
#[cfg(stage0)]
355+
pub fn freq_count<T, U>(iter: T) -> hash_map::HashMap<U, uint>
356+
where T: Iterator<Item=U>, U: Eq + Clone + Hash<Hasher>
357+
{
358+
let mut map: hash_map::HashMap<U,uint> = hash_map::HashMap::new();
359+
for elem in iter {
360+
match map.entry(elem) {
361+
Occupied(mut entry) => { *entry.get_mut() += 1; },
362+
Vacant(entry) => { entry.insert(1); },
363+
}
364+
}
365+
map
366+
}
367+
348368
// Test vectors generated from R, using the script src/etc/stat-test-vectors.r.
349369

350370
#[cfg(test)]

0 commit comments

Comments
 (0)