push use of AccountMapEntry one level deeper (#19775)

This commit is contained in:
Jeff Washington (jwash)
2021-09-10 21:09:51 -05:00
committed by GitHub
parent b2bdd3e346
commit ed7a6c6732
2 changed files with 10 additions and 9 deletions

View File

@ -45,7 +45,7 @@ pub type SlotSlice<'s, T> = &'s [(Slot, T)];
pub type RefCount = u64; pub type RefCount = u64;
pub type AccountMap<V> = InMemAccountsIndex<V>; pub type AccountMap<V> = InMemAccountsIndex<V>;
type AccountMapEntry<T> = Arc<AccountMapEntryInner<T>>; pub(crate) type AccountMapEntry<T> = Arc<AccountMapEntryInner<T>>;
pub trait IsCached: 'static + Clone + Debug + PartialEq + ZeroLamport + Copy + Default { pub trait IsCached: 'static + Clone + Debug + PartialEq + ZeroLamport + Copy + Default {
fn is_cached(&self) -> bool; fn is_cached(&self) -> bool;
@ -756,7 +756,7 @@ pub trait ZeroLamport {
fn is_zero_lamport(&self) -> bool; fn is_zero_lamport(&self) -> bool;
} }
type MapType<T> = AccountMap<AccountMapEntry<T>>; type MapType<T> = AccountMap<T>;
type LockMapType<T> = Vec<RwLock<MapType<T>>>; type LockMapType<T> = Vec<RwLock<MapType<T>>>;
type LockMapTypeSlice<T> = [RwLock<MapType<T>>]; type LockMapTypeSlice<T> = [RwLock<MapType<T>>];
type AccountMapsWriteLock<'a, T> = RwLockWriteGuard<'a, MapType<T>>; type AccountMapsWriteLock<'a, T> = RwLockWriteGuard<'a, MapType<T>>;

View File

@ -1,3 +1,4 @@
use crate::accounts_index::{AccountMapEntry, IsCached};
use solana_sdk::pubkey::Pubkey; use solana_sdk::pubkey::Pubkey;
use std::collections::{ use std::collections::{
hash_map::{Entry, Iter, Keys}, hash_map::{Entry, Iter, Keys},
@ -9,31 +10,31 @@ type K = Pubkey;
// one instance of this represents one bin of the accounts index. // one instance of this represents one bin of the accounts index.
#[derive(Debug, Default)] #[derive(Debug, Default)]
pub struct InMemAccountsIndex<V> { pub struct InMemAccountsIndex<V: IsCached> {
// backing store // backing store
map: HashMap<Pubkey, V>, map: HashMap<Pubkey, AccountMapEntry<V>>,
} }
impl<V> InMemAccountsIndex<V> { impl<V: IsCached> InMemAccountsIndex<V> {
pub fn new() -> Self { pub fn new() -> Self {
Self { Self {
map: HashMap::new(), map: HashMap::new(),
} }
} }
pub fn entry(&mut self, pubkey: Pubkey) -> Entry<K, V> { pub fn entry(&mut self, pubkey: Pubkey) -> Entry<K, AccountMapEntry<V>> {
self.map.entry(pubkey) self.map.entry(pubkey)
} }
pub fn iter(&self) -> Iter<K, V> { pub fn iter(&self) -> Iter<K, AccountMapEntry<V>> {
self.map.iter() self.map.iter()
} }
pub fn keys(&self) -> Keys<K, V> { pub fn keys(&self) -> Keys<K, AccountMapEntry<V>> {
self.map.keys() self.map.keys()
} }
pub fn get(&self, key: &K) -> Option<&V> { pub fn get(&self, key: &K) -> Option<&AccountMapEntry<V>> {
self.map.get(key) self.map.get(key)
} }