fix hash calc # storages, # slots (#20832)

This commit is contained in:
Jeff Washington (jwash)
2021-10-25 14:37:50 -05:00
committed by GitHub
parent f4f281e7c7
commit 9e85499d4c
3 changed files with 14 additions and 2 deletions

View File

@@ -8,6 +8,7 @@ pub struct SortedStorages<'a> {
range: Range<Slot>,
storages: Vec<Option<&'a SnapshotStorage>>,
slot_count: usize,
storage_count: usize,
}
impl<'a> SortedStorages<'a> {
@@ -32,6 +33,10 @@ impl<'a> SortedStorages<'a> {
self.slot_count
}
pub fn storage_count(&self) -> usize {
self.storage_count
}
// assumptions:
// 1. each SnapshotStorage.!is_empty()
// 2. SnapshotStorage.first().unwrap().get_slot() is unique from all other SnapshotStorage items.
@@ -79,7 +84,9 @@ impl<'a> SortedStorages<'a> {
let mut slot_count = 0;
let mut time = Measure::start("get slot");
let source_ = source.clone();
source_.for_each(|(_, slot)| {
let mut storage_count = 0;
source_.for_each(|(storages, slot)| {
storage_count += storages.len();
slot_count += 1;
adjust_min_max(*slot);
});
@@ -109,6 +116,7 @@ impl<'a> SortedStorages<'a> {
range,
storages,
slot_count,
storage_count,
}
}
}
@@ -132,6 +140,7 @@ pub mod tests {
range,
storages,
slot_count,
storage_count: 0,
}
}
}