You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This code manipulates a HashMap using the new Entry API, checking for consistency after each step.
use std::collections::HashMap;use std::collections::hash_map::Entry::{Vacant,Occupied};use std::rand::Rng;fncheck(m:&HashMap<int,()>){for k in m.keys(){assert!(m.contains_key(k),"{} is in keys() but not in the map?", k);}}fnmain(){letmut m = HashMap::new();letmut rng = std::rand::weak_rng();// Populate the map with some items.for _ inrange(0u,50){let x = rng.gen_range(-10,10);
m.insert(x,());}for i inrange(0u,1000){let x = rng.gen_range(-10,10);match m.entry(x){Vacant(_) => {},Occupied(e) => {println!("{}: remove {}", i, x);
e.take();},}check(&m);}}
The assertion in check should never fail, but in my tests it does so reliably, almost always within the first 10 iterations of the second loop. When it does fail, the value of k is not one of the values previously removed during the loop (that is, keys is right to return this key, and contains_key is wrong to report it as absent).
I tested this with rustc 0.13.0-dev (377d7524a 2014-11-24 13:56:36 +0000) on 64-bit Linux.
The text was updated successfully, but these errors were encountered:
This code manipulates a HashMap using the new Entry API, checking for consistency after each step.
The assertion in
check
should never fail, but in my tests it does so reliably, almost always within the first 10 iterations of the second loop. When it does fail, the value ofk
is not one of the values previously removed during the loop (that is,keys
is right to return this key, andcontains_key
is wrong to report it as absent).I tested this with
rustc 0.13.0-dev (377d7524a 2014-11-24 13:56:36 +0000)
on 64-bit Linux.The text was updated successfully, but these errors were encountered: