Struct Cache

Source
pub struct Cache<DK, DV> { /* private fields */ }
Expand description

A cache, mapping [u8] keys to [u8] values.

This cache wraps generic byte storage that implements AsRef<[u8]>. This is most commonly a memory-mapped file, Mmap.

For serializing a stream of (key, value) pairs, see Builder.

Implementations§

Source§

impl<DK, DV> Cache<DK, DV>
where DK: AsRef<[u8]>, DV: AsRef<[u8]>,

Source

pub fn new(index_bytes: DK, value_bytes: DV) -> Result<Self, Error>

Source

pub fn index(&self) -> &Map<DK>

Access the internal fst::Map used for mapping keys to value offsets.

Source

pub fn value_bytes(&self) -> &[u8]

The entire byte slice storing all values.

Source

pub fn get_value_offset(&self, key: &[u8]) -> Option<u64>

Returns the byte offset of the value for key, if it exists.

The returned offset can be used with the value_at_offset method.

Source

pub unsafe fn offset_transmuted_value<T>(&self, offset: usize) -> &T

Transmutes the bytes starting at offset into a T reference.

§Safety

offset must point to a valid representation of T in the value_bytes region of memory.

Source

pub unsafe fn get_transmuted_value<T>(&self, key: &[u8]) -> Option<&T>

Transmutes the bytes pointed to by key (if any) into a T reference.

§Safety

key must point to a valid representation of T in the value_bytes region of memory.

Source

pub fn range<K, R>(&self, key_range: R) -> StreamBuilder<'_>
where K: AsRef<[u8]>, R: RangeBounds<K>,

Returns a streaming iterator over (key, value offset) pairs.

The offset is a byte offset pointing to the start of the value for that key.

Source

pub fn first<const N: usize>(&self) -> Option<([u8; N], u64)>

Returns the (lexicographical) first (key, value) pair.

§Panics

If the actual first key is longer than N.

Source

pub fn last<const N: usize>(&self) -> Option<([u8; N], u64)>

Returns the (lexicographical) last (key, value) pair.

§Panics

If the actual last key is longer than N.

Source

pub fn last_le<const N: usize>( &self, upper_bound: &[u8], ) -> Option<([u8; N], u64)>

Finds the (lexicographical) greatest key k such that k <= upper_bound.

§Panics

If the found key is longer than N.

Source§

impl Cache<Mmap, Mmap>

Source

pub unsafe fn map_paths( index_path: impl AsRef<Path>, value_path: impl AsRef<Path>, ) -> Result<Self, Error>

Maps the files at index_path and value_path to read-only virtual memory ranges.

§Safety

See Mmap.

Source

pub unsafe fn map_files( index_file: &File, value_file: &File, ) -> Result<Self, Error>

Mapsindex_file and value_file to read-only virtual memory ranges.

§Safety

See Mmap.

Auto Trait Implementations§

§

impl<DK, DV> Freeze for Cache<DK, DV>
where DV: Freeze, DK: Freeze,

§

impl<DK, DV> RefUnwindSafe for Cache<DK, DV>

§

impl<DK, DV> Send for Cache<DK, DV>
where DV: Send, DK: Send,

§

impl<DK, DV> Sync for Cache<DK, DV>
where DV: Sync, DK: Sync,

§

impl<DK, DV> Unpin for Cache<DK, DV>
where DV: Unpin, DK: Unpin,

§

impl<DK, DV> UnwindSafe for Cache<DK, DV>
where DV: UnwindSafe, DK: UnwindSafe,

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.