modernize smallintmap
* switch to explicit self * get rid of the @ box * replace DVec with ~[] (to get rid of the mutable field) * implement the new container::Map trait
This commit is contained in:
parent
348d770fed
commit
74b317ddc2
3 changed files with 109 additions and 148 deletions
|
|
@ -8,22 +8,21 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// Microbenchmark for the oldsmallintmap library
|
||||
// Microbenchmark for the smallintmap library
|
||||
|
||||
extern mod std;
|
||||
use std::oldsmallintmap;
|
||||
use std::oldsmallintmap::SmallIntMap;
|
||||
use std::smallintmap::SmallIntMap;
|
||||
use io::WriterUtil;
|
||||
|
||||
fn append_sequential(min: uint, max: uint, map: SmallIntMap<uint>) {
|
||||
fn append_sequential(min: uint, max: uint, map: &mut SmallIntMap<uint>) {
|
||||
for uint::range(min, max) |i| {
|
||||
map.insert(i, i + 22u);
|
||||
}
|
||||
}
|
||||
|
||||
fn check_sequential(min: uint, max: uint, map: SmallIntMap<uint>) {
|
||||
fn check_sequential(min: uint, max: uint, map: &SmallIntMap<uint>) {
|
||||
for uint::range(min, max) |i| {
|
||||
assert map.get(i) == i + 22u;
|
||||
assert *map.get(&i) == i + 22u;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -43,11 +42,11 @@ fn main() {
|
|||
let mut appendf = 0.0;
|
||||
|
||||
for uint::range(0u, rep) |_r| {
|
||||
let map = oldsmallintmap::mk();
|
||||
let mut map = SmallIntMap::new();
|
||||
let start = std::time::precise_time_s();
|
||||
append_sequential(0u, max, map);
|
||||
append_sequential(0u, max, &mut map);
|
||||
let mid = std::time::precise_time_s();
|
||||
check_sequential(0u, max, map);
|
||||
check_sequential(0u, max, &map);
|
||||
let end = std::time::precise_time_s();
|
||||
|
||||
checkf += (end - mid) as float;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue