pub struct ShardedAccess<'a, const SHARDS: usize> { /* private fields */ }Expand description
A sharded collection that distributes entries across multiple accounts.
Each shard is an account containing a FixedVec<T>. The shard index
is determined by a key hash.
This enables collections that exceed single-account size limits.
Implementations§
Source§impl<'a, const SHARDS: usize> ShardedAccess<'a, SHARDS>
impl<'a, const SHARDS: usize> ShardedAccess<'a, SHARDS>
Sourcepub fn new(
accounts: &'a [AccountView],
shard_indices: &[u8],
) -> Result<Self, ProgramError>
pub fn new( accounts: &'a [AccountView], shard_indices: &[u8], ) -> Result<Self, ProgramError>
Create a sharded access from account indices.
Sourcepub fn shard_for_key(&self, key: &[u8]) -> usize
pub fn shard_for_key(&self, key: &[u8]) -> usize
Determine which shard a key maps to (simple modular hashing).
Sourcepub fn shard_account(
&self,
shard: usize,
) -> Result<&'a AccountView, ProgramError>
pub fn shard_account( &self, shard: usize, ) -> Result<&'a AccountView, ProgramError>
Get the account for a given shard index.
Sourcepub fn data_for_key(&self, key: &[u8]) -> Result<Ref<'a, [u8]>, ProgramError>
pub fn data_for_key(&self, key: &[u8]) -> Result<Ref<'a, [u8]>, ProgramError>
Get the account data for the shard that owns a given key.
Sourcepub fn shard_count(&self) -> usize
pub fn shard_count(&self) -> usize
Number of shards.
Auto Trait Implementations§
impl<'a, const SHARDS: usize> Freeze for ShardedAccess<'a, SHARDS>
impl<'a, const SHARDS: usize> RefUnwindSafe for ShardedAccess<'a, SHARDS>
impl<'a, const SHARDS: usize> Send for ShardedAccess<'a, SHARDS>
impl<'a, const SHARDS: usize> Sync for ShardedAccess<'a, SHARDS>
impl<'a, const SHARDS: usize> Unpin for ShardedAccess<'a, SHARDS>
impl<'a, const SHARDS: usize> UnsafeUnpin for ShardedAccess<'a, SHARDS>
impl<'a, const SHARDS: usize> UnwindSafe for ShardedAccess<'a, SHARDS>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more