12
12
13
13
use std:: cmp:: Ordering :: { self , Less , Greater , Equal } ;
14
14
use std:: collections:: hash_map:: Entry :: { Occupied , Vacant } ;
15
+ #[ cfg( not( stage0) ) ]
15
16
use std:: collections:: hash_map;
17
+ #[ cfg( stage0) ]
18
+ use std:: collections:: hash_map:: { self , Hasher } ;
16
19
use std:: hash:: Hash ;
17
20
use std:: mem;
18
21
use std:: num:: { Float , FromPrimitive } ;
@@ -332,6 +335,7 @@ pub fn winsorize<T: Float + FromPrimitive>(samples: &mut [T], pct: T) {
332
335
333
336
/// Returns a HashMap with the number of occurrences of every element in the
334
337
/// sequence that the iterator exposes.
338
+ #[ cfg( not( stage0) ) ]
335
339
pub fn freq_count < T , U > ( iter : T ) -> hash_map:: HashMap < U , uint >
336
340
where T : Iterator < Item =U > , U : Eq + Clone + Hash
337
341
{
@@ -345,6 +349,22 @@ pub fn freq_count<T, U>(iter: T) -> hash_map::HashMap<U, uint>
345
349
map
346
350
}
347
351
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
+
348
368
// Test vectors generated from R, using the script src/etc/stat-test-vectors.r.
349
369
350
370
#[ cfg( test) ]
0 commit comments