File tree Expand file tree Collapse file tree 2 files changed +29
-3
lines changed Expand file tree Collapse file tree 2 files changed +29
-3
lines changed Original file line number Diff line number Diff line change @@ -326,7 +326,7 @@ Convert a set into a vector.
326
326
fn vec_from_set < T : copy > ( s : set < T > ) -> [ T ] /~ {
327
327
let mut v = [ ] /~;
328
328
s. each_key ( ) { |k|
329
- v += [ k ] /~ ;
329
+ vec :: push ( v , k ) ;
330
330
true
331
331
} ;
332
332
v
Original file line number Diff line number Diff line change 3
3
use std;
4
4
5
5
import std:: time:: precise_time_s;
6
+ import std:: map;
7
+ import std:: map:: { map, hashmap} ;
6
8
7
9
import io:: { reader, reader_util} ;
8
10
9
- fn main ( ) {
11
+ fn main ( argv : [ str ] /~ ) {
10
12
#macro[
11
13
[ #bench[ id] ,
12
- run_test ( #stringify ( id) , id) ]
14
+ if tests. len ( ) == 0 || vec:: contains ( tests, #stringify ( id) ) {
15
+ run_test ( #stringify ( id) , id) ;
16
+ }
17
+ ]
13
18
] ;
14
19
20
+ let tests = vec:: view ( argv, 1 , argv. len ( ) ) ;
21
+
15
22
#bench[ shift_push] ;
16
23
#bench[ read_line] ;
24
+ #bench[ str_set] ;
17
25
}
18
26
19
27
fn run_test ( name : str , test : fn ( ) ) {
@@ -46,3 +54,21 @@ fn read_line() {
46
54
}
47
55
}
48
56
}
57
+
58
+ fn str_set ( ) {
59
+ let r = rand:: rng ( ) ;
60
+
61
+ let s = map:: hashmap ( str:: hash, str:: eq) ;
62
+
63
+ for int:: range( 0 , 1000 ) { |_i|
64
+ map:: set_add( s, r. gen_str( 10 ) ) ;
65
+ }
66
+
67
+ let mut found = 0 ;
68
+ for int:: range( 0 , 1000 ) { |_i|
69
+ alt s. find( r. gen_str( 10 ) ) {
70
+ some( _) { found += 1 ; }
71
+ none { }
72
+ }
73
+ }
74
+ }
You can’t perform that action at this time.
0 commit comments