ShardedMap

Struct ShardedMap 

Source
pub struct ShardedMap<K, V>
where K: OHash + Pod + Default + Debug + Send + Ord, V: Cmov + Pod + Default + Debug + Send + Eq, BatchBlock<K, V>: Ord + Send,
{ /* private fields */ }
Expand description

A sharded hashmap implementation. The map is split across multiple partitions and each partition is a separate hashmap. Queries are resolved in batches, to not leak the number of queries that go to each partition.

§Parameters

  • K: The type of the keys in the map.
  • V: The type of the values in the map.
  • P: The number of partitions in the map.
  • B: The maximum number of non-distinct keys in any partition in a batch.

Implementations§

Source§

impl<K, V> ShardedMap<K, V>
where K: OHash + Default + Debug + Send + Ord + Pod + Sized, V: Cmov + Pod + Default + Debug + Send + Eq, BatchBlock<K, V>: Ord + Send,

Source

pub fn new(capacity: usize) -> Self

Creates a new ShardedMap with the given number of partitions.

Source

pub const fn compute_safe_batch_size(&self, n: usize) -> usize

Computes a safe batch size B for a given number of distinct queries N.

§Preconditions
  • N >= P log P
Source

pub fn get_batch_distinct(&mut self, keys: &[K], b: usize) -> Vec<OOption<V>>

Reads N values from the map, leaking only N and B, but not any information about the keys (doesn’t leak the number of keys to each partition).

§Preconditions
  • No repeated keys in the input array.
  • There are at most b queries to each partition.
Source

pub fn get_batch(&mut self, keys: &[K], b: usize) -> Vec<OOption<V>>

Reads N values from the map, leaking only N and B, but not any information about the keys (doesn’t leak the number of keys to each partition).

§Preconditions
  • There are at most b queries to each partition (statistically likely).
Source

pub unsafe fn get_batch_leaky(&mut self, keys: &[K]) -> Vec<OOption<V>>

👎Deprecated: This function is unsafe because it can potentially leak information about keys to partition mapping. Use get_batch_distinct instead.

Leaky version of get_batch_distinct, which will return values for repeated keys and leak the size of the largest partition.

§Safety
  • This function will leak the size of the largest partition, which with repeated queries can be used to infer the mapping of keys to partitions.
Source

pub fn insert_batch_distinct(&mut self, keys: &[K], values: &[V], b: usize)

Inserts a batch of N distinct key-value pairs into the map, distributing them across partitions.

§Preconditions
  • No repeated keys in the input array.
  • All of the inserted keys are not already present in the map.
  • There is enough space in the map to insert all N keys.
  • There are at most b queries to each partition.
Source

pub fn insert_batch(&mut self, keys: &[K], values: &[V], b: usize)

Reads N values from the map, leaking only N and B, but not any information about the keys (doesn’t leak the number of keys to each partition).

§Preconditions
  • There are at most b queries to each partition (statistically likely).
§Behavior
  • If a key appears multiple times in the input array, only the value corresponding to its first occurrence is used.

Trait Implementations§

Source§

impl<K, V> Debug for ShardedMap<K, V>
where K: OHash + Pod + Default + Debug + Send + Ord + Debug, V: Cmov + Pod + Default + Debug + Send + Eq + Debug, BatchBlock<K, V>: Ord + Send,

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<K, V> Freeze for ShardedMap<K, V>

§

impl<K, V> !RefUnwindSafe for ShardedMap<K, V>

§

impl<K, V> Send for ShardedMap<K, V>

§

impl<K, V> Sync for ShardedMap<K, V>

§

impl<K, V> Unpin for ShardedMap<K, V>

§

impl<K, V> !UnwindSafe for ShardedMap<K, V>

Blanket Implementations§

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, 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, 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