solana_accounts_db::accounts_cache

Struct SlotCacheInner

source
pub struct SlotCacheInner { /* private fields */ }

Implementations§

source§

impl SlotCacheInner

source

pub fn report_slot_store_metrics(&self)

source

pub fn get_all_pubkeys(&self) -> Vec<Pubkey>

source

pub fn insert( &self, pubkey: &Pubkey, account: AccountSharedData, ) -> CachedAccount

source

pub fn get_cloned(&self, pubkey: &Pubkey) -> Option<CachedAccount>

source

pub fn mark_slot_frozen(&self)

source

pub fn is_frozen(&self) -> bool

source

pub fn total_bytes(&self) -> u64

Methods from Deref<Target = DashMap<Pubkey, CachedAccount>>§

source

pub fn par_iter_mut(&self) -> IterMut<'_, K, V, S>

source

pub fn hash_usize<T>(&self, item: &T) -> usize
where T: Hash,

Hash a given item to produce a usize. Uses the provided or default HashBuilder.

source

pub fn shards(&self) -> &[RwLock<RawRwLock, HashMap<K, SharedValue<V>, S>>]

Allows you to peek at the inner shards that store your data. You should probably not use this unless you know what you are doing.

Requires the raw-api feature to be enabled.

§Examples
use dashmap::DashMap;

let map = DashMap::<(), ()>::new();
println!("Amount of shards: {}", map.shards().len());
source

pub fn determine_map<Q>(&self, key: &Q) -> usize
where K: Borrow<Q>, Q: Hash + Eq + ?Sized,

Finds which shard a certain key is stored in. You should probably not use this unless you know what you are doing. Note that shard selection is dependent on the default or provided HashBuilder.

Requires the raw-api feature to be enabled.

§Examples
use dashmap::DashMap;

let map = DashMap::new();
map.insert("coca-cola", 1.4);
println!("coca-cola is stored in shard: {}", map.determine_map("coca-cola"));
source

pub fn determine_shard(&self, hash: usize) -> usize

Finds which shard a certain hash is stored in.

Requires the raw-api feature to be enabled.

§Examples
use dashmap::DashMap;

let map: DashMap<i32, i32> = DashMap::new();
let key = "key";
let hash = map.hash_usize(&key);
println!("hash is stored in shard: {}", map.determine_shard(hash));
source

pub fn hasher(&self) -> &S

Returns a reference to the map’s BuildHasher.

§Examples
use dashmap::DashMap;
use std::collections::hash_map::RandomState;

let hasher = RandomState::new();
let map: DashMap<i32, i32> = DashMap::new();
let hasher: &RandomState = map.hasher();
source

pub fn insert(&self, key: K, value: V) -> Option<V>

Inserts a key and a value into the map. Returns the old value associated with the key if there was one.

Locking behaviour: May deadlock if called when holding any sort of reference into the map.

§Examples
use dashmap::DashMap;

let map = DashMap::new();
map.insert("I am the key!", "And I am the value!");
source

pub fn remove<Q>(&self, key: &Q) -> Option<(K, V)>
where K: Borrow<Q>, Q: Hash + Eq + ?Sized,

Removes an entry from the map, returning the key and value if they existed in the map.

Locking behaviour: May deadlock if called when holding any sort of reference into the map.

§Examples
use dashmap::DashMap;

let soccer_team = DashMap::new();
soccer_team.insert("Jack", "Goalie");
assert_eq!(soccer_team.remove("Jack").unwrap().1, "Goalie");
source

pub fn remove_if<Q>( &self, key: &Q, f: impl FnOnce(&K, &V) -> bool, ) -> Option<(K, V)>
where K: Borrow<Q>, Q: Hash + Eq + ?Sized,

Removes an entry from the map, returning the key and value if the entry existed and the provided conditional function returned true.

Locking behaviour: May deadlock if called when holding any sort of reference into the map.

use dashmap::DashMap;

let soccer_team = DashMap::new();
soccer_team.insert("Sam", "Forward");
soccer_team.remove_if("Sam", |_, position| position == &"Goalie");
assert!(soccer_team.contains_key("Sam"));
use dashmap::DashMap;

let soccer_team = DashMap::new();
soccer_team.insert("Sam", "Forward");
soccer_team.remove_if("Sam", |_, position| position == &"Forward");
assert!(!soccer_team.contains_key("Sam"));
source

pub fn remove_if_mut<Q>( &self, key: &Q, f: impl FnOnce(&K, &mut V) -> bool, ) -> Option<(K, V)>
where K: Borrow<Q>, Q: Hash + Eq + ?Sized,

source

pub fn iter(&'a self) -> Iter<'a, K, V, S>

Creates an iterator over a DashMap yielding immutable references.

Locking behaviour: May deadlock if called when holding a mutable reference into the map.

§Examples
use dashmap::DashMap;

let words = DashMap::new();
words.insert("hello", "world");
assert_eq!(words.iter().count(), 1);
source

pub fn iter_mut(&'a self) -> IterMut<'a, K, V, S>

Iterator over a DashMap yielding mutable references.

Locking behaviour: May deadlock if called when holding any sort of reference into the map.

§Examples
use dashmap::DashMap;

let map = DashMap::new();
map.insert("Johnny", 21);
map.iter_mut().for_each(|mut r| *r += 1);
assert_eq!(*map.get("Johnny").unwrap(), 22);
source

pub fn get<Q>(&'a self, key: &Q) -> Option<Ref<'a, K, V, S>>
where K: Borrow<Q>, Q: Hash + Eq + ?Sized,

Get an immutable reference to an entry in the map

Locking behaviour: May deadlock if called when holding a mutable reference into the map.

§Examples
use dashmap::DashMap;

let youtubers = DashMap::new();
youtubers.insert("Bosnian Bill", 457000);
assert_eq!(*youtubers.get("Bosnian Bill").unwrap(), 457000);
source

pub fn get_mut<Q>(&'a self, key: &Q) -> Option<RefMut<'a, K, V, S>>
where K: Borrow<Q>, Q: Hash + Eq + ?Sized,

Get a mutable reference to an entry in the map

Locking behaviour: May deadlock if called when holding any sort of reference into the map.

§Examples
use dashmap::DashMap;

let class = DashMap::new();
class.insert("Albin", 15);
*class.get_mut("Albin").unwrap() -= 1;
assert_eq!(*class.get("Albin").unwrap(), 14);
source

pub fn try_get<Q>(&'a self, key: &Q) -> TryResult<Ref<'a, K, V, S>>
where K: Borrow<Q>, Q: Hash + Eq + ?Sized,

Get an immutable reference to an entry in the map, if the shard is not locked. If the shard is locked, the function will return TryResult::Locked.

§Examples
use dashmap::DashMap;
use dashmap::try_result::TryResult;

let map = DashMap::new();
map.insert("Johnny", 21);

assert_eq!(*map.try_get("Johnny").unwrap(), 21);

let _result1_locking = map.get_mut("Johnny");

let result2 = map.try_get("Johnny");
assert!(result2.is_locked());
source

pub fn try_get_mut<Q>(&'a self, key: &Q) -> TryResult<RefMut<'a, K, V, S>>
where K: Borrow<Q>, Q: Hash + Eq + ?Sized,

Get a mutable reference to an entry in the map, if the shard is not locked. If the shard is locked, the function will return TryResult::Locked.

§Examples
use dashmap::DashMap;
use dashmap::try_result::TryResult;

let map = DashMap::new();
map.insert("Johnny", 21);

*map.try_get_mut("Johnny").unwrap() += 1;
assert_eq!(*map.get("Johnny").unwrap(), 22);

let _result1_locking = map.get("Johnny");

let result2 = map.try_get_mut("Johnny");
assert!(result2.is_locked());
source

pub fn shrink_to_fit(&self)

Remove excess capacity to reduce memory usage.

Locking behaviour: May deadlock if called when holding any sort of reference into the map.

source

pub fn retain(&self, f: impl FnMut(&K, &mut V) -> bool)

Retain elements that whose predicates return true and discard elements whose predicates return false.

Locking behaviour: May deadlock if called when holding any sort of reference into the map.

§Examples
use dashmap::DashMap;

let people = DashMap::new();
people.insert("Albin", 15);
people.insert("Jones", 22);
people.insert("Charlie", 27);
people.retain(|_, v| *v > 20);
assert_eq!(people.len(), 2);
source

pub fn len(&self) -> usize

Fetches the total number of key-value pairs stored in the map.

Locking behaviour: May deadlock if called when holding a mutable reference into the map.

§Examples
use dashmap::DashMap;

let people = DashMap::new();
people.insert("Albin", 15);
people.insert("Jones", 22);
people.insert("Charlie", 27);
assert_eq!(people.len(), 3);
source

pub fn is_empty(&self) -> bool

Checks if the map is empty or not.

Locking behaviour: May deadlock if called when holding a mutable reference into the map.

§Examples
use dashmap::DashMap;

let map = DashMap::<(), ()>::new();
assert!(map.is_empty());
source

pub fn clear(&self)

Removes all key-value pairs in the map.

Locking behaviour: May deadlock if called when holding any sort of reference into the map.

§Examples
use dashmap::DashMap;

let stats = DashMap::new();
stats.insert("Goals", 4);
assert!(!stats.is_empty());
stats.clear();
assert!(stats.is_empty());
source

pub fn capacity(&self) -> usize

Returns how many key-value pairs the map can store without reallocating.

Locking behaviour: May deadlock if called when holding a mutable reference into the map.

source

pub fn alter<Q>(&self, key: &Q, f: impl FnOnce(&K, V) -> V)
where K: Borrow<Q>, Q: Hash + Eq + ?Sized,

Modify a specific value according to a function.

Locking behaviour: May deadlock if called when holding any sort of reference into the map.

§Examples
use dashmap::DashMap;

let stats = DashMap::new();
stats.insert("Goals", 4);
stats.alter("Goals", |_, v| v * 2);
assert_eq!(*stats.get("Goals").unwrap(), 8);
§Panics

If the given closure panics, then alter will abort the process

source

pub fn alter_all(&self, f: impl FnMut(&K, V) -> V)

Modify every value in the map according to a function.

Locking behaviour: May deadlock if called when holding any sort of reference into the map.

§Examples
use dashmap::DashMap;

let stats = DashMap::new();
stats.insert("Wins", 4);
stats.insert("Losses", 2);
stats.alter_all(|_, v| v + 1);
assert_eq!(*stats.get("Wins").unwrap(), 5);
assert_eq!(*stats.get("Losses").unwrap(), 3);
§Panics

If the given closure panics, then alter_all will abort the process

source

pub fn view<Q, R>(&self, key: &Q, f: impl FnOnce(&K, &V) -> R) -> Option<R>
where K: Borrow<Q>, Q: Hash + Eq + ?Sized,

Scoped access into an item of the map according to a function.

Locking behaviour: May deadlock if called when holding any sort of reference into the map.

§Examples
use dashmap::DashMap;

let warehouse = DashMap::new();
warehouse.insert(4267, ("Banana", 100));
warehouse.insert(2359, ("Pear", 120));
let fruit = warehouse.view(&4267, |_k, v| *v);
assert_eq!(fruit, Some(("Banana", 100)));
§Panics

If the given closure panics, then view will abort the process

source

pub fn contains_key<Q>(&self, key: &Q) -> bool
where K: Borrow<Q>, Q: Hash + Eq + ?Sized,

Checks if the map contains a specific key.

Locking behaviour: May deadlock if called when holding a mutable reference into the map.

§Examples
use dashmap::DashMap;

let team_sizes = DashMap::new();
team_sizes.insert("Dakota Cherries", 23);
assert!(team_sizes.contains_key("Dakota Cherries"));
source

pub fn entry(&'a self, key: K) -> Entry<'a, K, V, S>

Advanced entry API that tries to mimic std::collections::HashMap. See the documentation on dashmap::mapref::entry for more details.

Locking behaviour: May deadlock if called when holding any sort of reference into the map.

source

pub fn try_entry(&'a self, key: K) -> Option<Entry<'a, K, V, S>>

Advanced entry API that tries to mimic std::collections::HashMap. See the documentation on dashmap::mapref::entry for more details.

Returns None if the shard is currently locked.

Trait Implementations§

source§

impl Debug for SlotCacheInner

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Drop for SlotCacheInner

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl Deref for SlotCacheInner

source§

type Target = DashMap<Pubkey, Arc<CachedAccountInner>>

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> AbiExample for T

source§

default fn example() -> T

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
source§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same for T

source§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more