Struct DiskHashMap

Source
pub struct DiskHashMap<K, V, BS, S = FxBuildHasher>
where BS: ByteStore, S: BuildHasher + Default,
{ /* private fields */ }
Expand description

This is an open address hash map implementation with trait-based encoding/decoding. It takes any types that implement BytesEncode/BytesDecode as key and value. It is designed to be used with a backing store that implements ByteStore trait, allowing for flexible storage options (in-memory with VecStore or persistent with MMapFile). The ByteStore is not used directly; instead we rely on Buffers which is technically a Vec<Box<[u8]>> but backed by a ByteStore trait.

Implementations§

Source§

impl<K, V, BS, S> DiskHashMap<K, V, BS, S>
where BS: ByteStore, S: BuildHasher + Default,

Source

pub fn with_stores(entry_store: BS, keys_store: BS, values_store: BS) -> Self

Creates a new HashMap with the given backing stores

Source

pub fn len(&self) -> usize

Returns the number of key-value pairs in the map

Source

pub fn is_empty(&self) -> bool

Returns true if the map contains no elements

Source

pub fn capacity(&self) -> usize

Returns the current capacity of the map

Source

pub fn load_factor(&self) -> f64

Returns the load factor of the map (size / capacity)

Source

pub fn stats(&self) -> (u64, u64, u64)

Source§

impl<K: for<'a> BytesEncode<'a>, V: for<'a> BytesEncode<'a> + for<'a> BytesDecode<'a>, BS: ByteStore, S: BuildHasher + Default> DiskHashMap<K, V, BS, S>

Source

pub fn insert<'a>( &'a mut self, key: &'a <K as BytesEncode<'a>>::EItem, value: &'a <V as BytesEncode<'a>>::EItem, ) -> Result<Option<<V as BytesDecode<'a>>::DItem>, Box<dyn Error + Sync + Send>>

Insert a key-value pair into the map using the trait-based API

Source

pub fn get<'a>( &self, key: &'a <K as BytesEncode<'a>>::EItem, ) -> Result<Option<<V as BytesDecode<'_>>::DItem>, Box<dyn Error + Sync + Send>>

Get a value by key using the trait-based API

Source

pub fn entry<'a>( &'a mut self, key: &'a <K as BytesEncode<'a>>::EItem, ) -> Result<MapEntry<'a, K, V, BS, S>, Box<dyn Error + Sync + Send>>
where for<'b> K: BytesEncode<'b>, for<'b> V: BytesDecode<'b>,

Get an entry for the given key using trait-based API

Source§

impl<K, V> DiskHashMap<K, V, VecStore, FxBuildHasher>

Source

pub fn new() -> Self

Creates a new in-memory HashMap

Source§

impl<K, V, S> DiskHashMap<K, V, MMapFile, S>
where S: BuildHasher + Default,

Source

pub fn new_in(path: &Path) -> Result<Self>

Source

pub fn with_capacity( path: impl AsRef<Path>, num_entries: usize, keys_bytes: usize, values_bytes: usize, ) -> Result<Self>

Creates a new HashMap with specified capacities, rounding up to nearest power of 2

Source

pub fn load_from(path: &Path) -> Result<Self>

Trait Implementations§

Source§

impl<K, V> Default for DiskHashMap<K, V, VecStore, FxBuildHasher>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<K, V, BS, S> Freeze for DiskHashMap<K, V, BS, S>
where S: Freeze, BS: Freeze,

§

impl<K, V, BS, S> RefUnwindSafe for DiskHashMap<K, V, BS, S>

§

impl<K, V, BS, S> Send for DiskHashMap<K, V, BS, S>
where S: Send, BS: Send, K: Send, V: Send,

§

impl<K, V, BS, S> Sync for DiskHashMap<K, V, BS, S>
where S: Sync, BS: Sync, K: Sync, V: Sync,

§

impl<K, V, BS, S> Unpin for DiskHashMap<K, V, BS, S>
where S: Unpin, BS: Unpin, K: Unpin, V: Unpin,

§

impl<K, V, BS, S> UnwindSafe for DiskHashMap<K, V, BS, S>

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> ArchivePointee for T

Source§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
Source§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
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> LayoutRaw for T

Source§

fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>

Returns the layout of the type.
Source§

impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
where T: SharedNiching<N1, N2>, N1: Niching<T>, N2: Niching<T>,

Source§

unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool

Returns whether the given value has been niched. Read more
Source§

fn resolve_niched(out: Place<NichedOption<T, N1>>)

Writes data to out indicating that a T is niched.
Source§

impl<T> Pointee for T

Source§

type Metadata = ()

The metadata type for pointers and references to this type.
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.