73239573c9
Part of #653 This allows us to properly implement getrandom(), which unlocks the default HashMap type (e.g. HashMap<K, V>) with RandomState) This commit adds a new '-Zmiri-seed=<seed>' option. When present, this option takes a 64-bit hex value, which is used as the seed to an internal PRNG. This PRNG is used to implement the 'getrandom()' syscall. When '-Zmiri-seed' is not passed, 'getrandom()' will be disabled.
36 lines
1.1 KiB
Rust
36 lines
1.1 KiB
Rust
// compile-flags: -Zmiri-seed=0000000000000000
|
|
|
|
use std::collections::{self, HashMap};
|
|
use std::hash::{BuildHasherDefault, BuildHasher};
|
|
|
|
fn test_map<S: BuildHasher>(mut map: HashMap<i32, i32, S>) {
|
|
map.insert(0, 0);
|
|
assert_eq!(map.values().fold(0, |x, y| x+y), 0);
|
|
|
|
let table_base = map.get(&0).unwrap() as *const _;
|
|
|
|
let num = 22; // large enough to trigger a resize
|
|
for i in 1..num {
|
|
map.insert(i, i);
|
|
}
|
|
assert!(table_base != map.get(&0).unwrap() as *const _); // make sure relocation happened
|
|
assert_eq!(map.values().fold(0, |x, y| x+y), num*(num-1)/2); // check the right things are in the table now
|
|
|
|
// Inserting again replaces the existing entries
|
|
for i in 0..num {
|
|
map.insert(i, num-1-i);
|
|
}
|
|
assert_eq!(map.values().fold(0, |x, y| x+y), num*(num-1)/2);
|
|
|
|
// TODO: Test Entry API, Iterators, ...
|
|
|
|
}
|
|
|
|
fn main() {
|
|
let map : HashMap<i32, i32, BuildHasherDefault<collections::hash_map::DefaultHasher>> = Default::default();
|
|
let map_normal: HashMap<i32, i32> = HashMap::new();
|
|
|
|
test_map(map);
|
|
test_map(map_normal);
|
|
}
|