Ancestors to HashSet: From(Vec) (#17447)
* ancestors.large_range_slots becomes HashSet * Ancestors to HashSet: From(Vec)
This commit is contained in:
committed by
GitHub
parent
d39a327138
commit
98f1b11edd
@@ -16,13 +16,13 @@ pub struct Ancestors {
|
||||
// that we prefer to implement them in a sparse HashMap
|
||||
const ANCESTORS_HASH_MAP_SIZE: u64 = 10_000;
|
||||
|
||||
impl From<Vec<(Slot, usize)>> for Ancestors {
|
||||
fn from(source: Vec<(Slot, usize)>) -> Ancestors {
|
||||
impl From<Vec<Slot>> for Ancestors {
|
||||
fn from(source: Vec<Slot>) -> Ancestors {
|
||||
let mut result = Ancestors::default();
|
||||
if !source.is_empty() {
|
||||
result.min = Slot::MAX;
|
||||
result.max = Slot::MIN;
|
||||
source.iter().for_each(|(slot, _)| {
|
||||
source.iter().for_each(|slot| {
|
||||
result.min = std::cmp::min(result.min, *slot);
|
||||
result.max = std::cmp::max(result.max, *slot + 1);
|
||||
});
|
||||
@@ -33,12 +33,12 @@ impl From<Vec<(Slot, usize)>> for Ancestors {
|
||||
result.max = 0;
|
||||
} else {
|
||||
result.slots = vec![None; range as usize];
|
||||
source.into_iter().for_each(|(slot, size)| {
|
||||
source.into_iter().for_each(|slot| {
|
||||
let slot = result.slot_index(&slot);
|
||||
if result.slots[slot].is_none() {
|
||||
result.count += 1;
|
||||
}
|
||||
result.slots[slot] = Some(size);
|
||||
result.slots[slot] = Some(0);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -181,6 +181,11 @@ pub mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Vec<(Slot, usize)>> for Ancestors {
|
||||
fn from(source: Vec<(Slot, usize)>) -> Ancestors {
|
||||
Ancestors::from(source.into_iter().map(|(slot, _)| slot).collect::<Vec<_>>())
|
||||
}
|
||||
}
|
||||
impl Ancestors {
|
||||
pub fn insert(&mut self, mut slot: Slot, size: usize) {
|
||||
if self.large_range_slots.is_empty() {
|
||||
|
@@ -1031,7 +1031,7 @@ impl Bank {
|
||||
accounts_db_caching_enabled: bool,
|
||||
) -> Self {
|
||||
let mut bank = Self::default();
|
||||
bank.ancestors = Ancestors::from(vec![(bank.slot(), 0)]);
|
||||
bank.ancestors = Ancestors::from(vec![bank.slot()]);
|
||||
bank.transaction_debug_keys = debug_keys;
|
||||
bank.cluster_type = Some(genesis_config.cluster_type);
|
||||
|
||||
@@ -1184,9 +1184,9 @@ impl Bank {
|
||||
);
|
||||
|
||||
let mut ancestors = Vec::with_capacity(1 + new.parents().len());
|
||||
ancestors.push((new.slot(), 0));
|
||||
ancestors.push(new.slot());
|
||||
new.parents().iter().for_each(|p| {
|
||||
ancestors.push((p.slot(), 0));
|
||||
ancestors.push(p.slot());
|
||||
});
|
||||
new.ancestors = Ancestors::from(ancestors);
|
||||
|
||||
@@ -4351,7 +4351,7 @@ impl Bank {
|
||||
&self,
|
||||
pubkey: &Pubkey,
|
||||
) -> Option<(AccountSharedData, Slot)> {
|
||||
let just_self: Ancestors = Ancestors::from(vec![(self.slot(), 0)]);
|
||||
let just_self: Ancestors = Ancestors::from(vec![self.slot()]);
|
||||
if let Some((account, slot)) = self.load_slow_with_fixed_root(&just_self, pubkey) {
|
||||
if slot == self.slot() {
|
||||
return Some((account, slot));
|
||||
|
Reference in New Issue
Block a user