Include map length in diagnostics

This commit is contained in:
Manish Goregaokar 2017-10-20 15:00:17 -07:00
parent f7f898b3b3
commit a10329f8ff
3 changed files with 11 additions and 2 deletions

View file

@ -166,7 +166,7 @@ impl<K: Hash + Eq, V, S: BuildHasher> DiagnosticHashMap<K, V, S>
canary: usize,
canary_addr: *const usize,
position: usize,
count: usize,
count: usize
) {
use ::std::ffi::CString;
let key = b"HashMapJournal\0";
@ -179,9 +179,10 @@ impl<K: Hash + Eq, V, S: BuildHasher> DiagnosticHashMap<K, V, S>
}
panic!(
concat!("HashMap Corruption (sz={}, cap={}, pairsz={}, hash={:#x}, cnry={:#x}, ",
concat!("HashMap Corruption (sz={}, buffer_hash_sz={}, cap={}, pairsz={}, hash={:#x}, cnry={:#x}, ",
"count={}, last_pos={}, base_addr={:?}, cnry_addr={:?}, jrnl_len={})"),
self.map.len(),
self.map.diagnostic_count_hashes(),
self.map.raw_capacity(),
::std::mem::size_of::<(K, (usize, V))>(),
hash,

View file

@ -1257,6 +1257,10 @@ impl<K, V, S> HashMap<K, V, S>
debug_assert!(elems_left == 0 || bucket.index() != start_index);
}
}
pub fn diagnostic_count_hashes(&self) -> usize {
self.table.diagnostic_count_hashes()
}
}
impl<K, V, S> PartialEq for HashMap<K, V, S>

View file

@ -896,6 +896,10 @@ impl<K, V> RawTable<K, V> {
}
}
pub fn diagnostic_count_hashes(&self) -> usize {
(0..self.capacity()).filter(|&i| unsafe { *self.raw_bucket_at(i).hash() != EMPTY_BUCKET }).count()
}
pub fn iter(&self) -> Iter<K, V> {
Iter {
iter: self.raw_buckets(),