1212
1313use std:: cmp:: Ordering :: { self , Less , Greater , Equal } ;
1414use std:: collections:: hash_map:: Entry :: { Occupied , Vacant } ;
15+ #[ cfg( not( stage0) ) ]
1516use std:: collections:: hash_map;
17+ #[ cfg( stage0) ]
18+ use std:: collections:: hash_map:: { self , Hasher } ;
1619use std:: hash:: Hash ;
1720use std:: mem;
1821use 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) ) ]
335339pub 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