Skip to main content

MapxRaw

Struct MapxRaw 

Source
pub struct MapxRaw { /* private fields */ }
Expand description

A raw, disk-based, key-value map.

MapxRaw provides a Map-like interface for storing and retrieving raw byte slices. It is unversioned and does not perform any encoding on keys or values.

Implementations§

Source§

impl MapxRaw

Source

pub unsafe fn shadow(&self) -> MapxRaw

Creates a “shadow” copy of the MapxRaw instance.

This method creates a new MapxRaw that shares the same underlying data source. It is a lightweight operation that can be used to create multiple references to the same map without the overhead of cloning the entire structure.

§Safety

This API breaks the semantic safety guarantees of Rust’s ownership and borrowing rules. It is safe to use in a race-free environment where you can guarantee that no two threads will access the same data concurrently.

Source

pub fn new() -> MapxRaw

Creates a new, empty MapxRaw.

§Returns

A new MapxRaw instance.

Source

pub fn get(&self, key: impl AsRef<[u8]>) -> Option<Vec<u8>>

Retrieves a value from the map corresponding to the given key.

§Arguments
  • key - The key to look up.
§Returns

An Option<RawValue> containing the value if the key exists, or None otherwise.

Source

pub fn get_mut(&mut self, key: impl AsRef<[u8]>) -> Option<ValueMut<'_>>

Retrieves a mutable reference to a value in the map.

§Arguments
  • key - The key to look up.
§Returns

An Option<ValueMut<'_>> containing a mutable reference to the value if the key exists, or None otherwise.

Source

pub fn mock_value_mut(&mut self, key: Vec<u8>, value: Vec<u8>) -> ValueMut<'_>

Mocks a mutable value, typically for use in scenarios where you need to create a ValueMut without actually inserting the value into the map yet.

§Arguments
  • key - The key associated with the value.
  • value - The value to be mocked.
§Returns

A ValueMut instance.

Source

pub fn contains_key(&self, key: impl AsRef<[u8]>) -> bool

Checks if the map contains a value for the specified key.

§Arguments
  • key - The key to check.
§Returns

true if the map contains the key, false otherwise.

Source

pub fn get_le(&self, key: impl AsRef<[u8]>) -> Option<(Vec<u8>, Vec<u8>)>

Retrieves the last entry with a key less than or equal to the given key.

§Arguments
  • key - The key to search for.
§Returns

An Option<(RawKey, RawValue)> containing the key-value pair if found, or None otherwise.

Source

pub fn get_ge(&self, key: impl AsRef<[u8]>) -> Option<(Vec<u8>, Vec<u8>)>

Retrieves the first entry with a key greater than or equal to the given key.

§Arguments
  • key - The key to search for.
§Returns

An Option<(RawKey, RawValue)> containing the key-value pair if found, or None otherwise.

Source

pub fn entry<'a>(&'a mut self, key: &'a [u8]) -> Entry<'a>

Gets an entry for the given key, allowing for in-place modification.

§Arguments
  • key - The key of the entry.
§Returns

An Entry that allows for operations on the value.

Source

pub fn iter(&self) -> MapxIter<'_>

Returns an iterator over the map’s entries.

§Returns

A MapxRawIter that iterates over the key-value pairs.

Source

pub fn range<'a, R>(&'a self, bounds: R) -> MapxIter<'a>
where R: RangeBounds<Cow<'a, [u8]>>,

Returns an iterator over a range of entries in the map.

§Arguments
  • bounds - The range of keys to iterate over.
§Returns

A MapxRawIter that iterates over the key-value pairs in the specified range.

Source

pub fn range_detached<'a, R>(&self, bounds: R) -> MapxIter<'a>
where R: RangeBounds<Cow<'a, [u8]>>,

Returns a detached iterator over a range of entries in the map.

This iterator is not tied to the lifetime of &self, allowing for concurrent modification of the map during iteration (though the iterator will see a snapshot).

§Arguments
  • bounds - The range of keys to iterate over.
§Returns

A MapxRawIter that iterates over the key-value pairs in the specified range.

Source

pub fn iter_mut(&mut self) -> MapxIterMut<'_>

Returns a mutable iterator over the map’s entries.

§Returns

A MapxRawIterMut that allows for mutable iteration over the key-value pairs.

Source

pub fn range_mut<'a, R>(&'a mut self, bounds: R) -> MapxIterMut<'a>
where R: RangeBounds<Cow<'a, [u8]>>,

Returns a mutable iterator over a range of entries in the map.

§Arguments
  • bounds - The range of keys to iterate over.
§Returns

A MapxRawIterMut that allows for mutable iteration over the key-value pairs in the specified range.

Source

pub fn last(&self) -> Option<(Vec<u8>, Vec<u8>)>

Retrieves the last entry in the map.

§Returns

An Option<(RawKey, RawValue)> containing the last key-value pair, or None if the map is empty.

Source

pub fn insert(&mut self, key: impl AsRef<[u8]>, value: impl AsRef<[u8]>)

Inserts a key-value pair into the map.

Does not return the old value for performance reasons.

§Arguments
  • key - The key to insert.
  • value - The value to associate with the key.
Source

pub fn remove(&mut self, key: impl AsRef<[u8]>)

Removes a key from the map.

Does not return the old value for performance reasons.

§Arguments
  • key - The key to remove.
Source

pub fn batch_entry(&mut self) -> Box<dyn BatchTrait + '_>

Start a batch operation.

This method allows you to perform multiple insert/remove operations and commit them atomically.

§Examples
use vsdb_core::basic::mapx_raw::MapxRaw;
use vsdb_core::vsdb_set_base_dir;

vsdb_set_base_dir("/tmp/vsdb_core_mapx_raw_batch_entry").unwrap();
let mut map = MapxRaw::new();

{
    let mut batch = map.batch_entry();
    batch.insert(&[1], &[10]);
    batch.insert(&[2], &[20]);
    batch.commit().unwrap();
}

assert_eq!(map.get(&[1]), Some(vec![10]));
assert_eq!(map.get(&[2]), Some(vec![20]));
Source

pub fn clear(&mut self)

Clears the map, removing all key-value pairs.

Source

pub unsafe fn from_bytes(s: impl AsRef<[u8]>) -> MapxRaw

Creates a MapxRaw from a byte slice.

§Safety

This function is unsafe because it assumes the byte slice is a valid representation of a MapxRaw. This function is unsafe because it assumes the byte slice is a valid representation of a MapxRaw. Do not use this API unless you know the internal details of the data structure extremely well.

Source

pub unsafe fn from_prefix_slice(s: impl AsRef<[u8]>) -> MapxRaw

Creates a MapxRaw from a prefix slice.

§Safety

This function is unsafe because it assumes the prefix slice is a valid representation of a MapxRaw. This function is unsafe because it assumes the byte slice is a valid representation of a MapxRaw. Do not use this API unless you know the internal details of the data structure extremely well.

Source

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

Returns the byte representation of the MapxRaw.

§Returns

A byte slice &[u8] representing the MapxRaw.

Source

pub fn as_prefix_slice(&self) -> &[u8; 8]

Returns the prefix slice of the MapxRaw.

§Returns

A &PreBytes slice representing the prefix of the MapxRaw.

Source

pub fn is_the_same_instance(&self, other_hdr: &MapxRaw) -> bool

Checks if this MapxRaw instance is the same as another.

§Arguments
  • other_hdr - The other MapxRaw to compare against.
§Returns

true if both instances refer to the same underlying data, false otherwise.

Trait Implementations§

Source§

impl Clone for MapxRaw

Source§

fn clone(&self) -> MapxRaw

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MapxRaw

Source§

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

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

impl Default for MapxRaw

Source§

fn default() -> MapxRaw

Creates a new, empty MapxRaw.

§Returns

A new MapxRaw instance.

Source§

impl<'de> Deserialize<'de> for MapxRaw

Source§

fn deserialize<__D>( __deserializer: __D, ) -> Result<MapxRaw, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for MapxRaw

Source§

fn eq(&self, other: &MapxRaw) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for MapxRaw

Source§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for MapxRaw

Source§

impl StructuralPartialEq for MapxRaw

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> KeyDe for T

Source§

fn decode_key(bytes: &[u8]) -> Result<T, Box<dyn RucError>>

Decodes a key from a byte slice.
Source§

impl<T> KeyEn for T
where T: Serialize,

Source§

fn try_encode_key(&self) -> Result<Vec<u8>, Box<dyn RucError>>

Tries to encode the key into a byte vector.
Source§

fn encode_key(&self) -> RawBytes

Encodes the key into a byte vector, panicking on failure.
Source§

impl<T> KeyEnDe for T
where T: KeyEn + KeyDe,

Source§

fn try_encode(&self) -> Result<Vec<u8>, Box<dyn RucError>>

Tries to encode the key into a byte vector.
Source§

fn encode(&self) -> Vec<u8>

Encodes the key into a byte vector, panicking on failure.
Source§

fn decode(bytes: &[u8]) -> Result<T, Box<dyn RucError>>

Decodes a key from a byte slice.
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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<T> ValueDe for T

Source§

fn decode_value(bytes: &[u8]) -> Result<T, Box<dyn RucError>>

Decodes a value from a byte slice.
Source§

impl<T> ValueEn for T
where T: Serialize,

Source§

fn try_encode_value(&self) -> Result<Vec<u8>, Box<dyn RucError>>

Tries to encode the value into a byte vector.
Source§

fn encode_value(&self) -> RawBytes

Encodes the value into a byte vector, panicking on failure.
Source§

impl<T> ValueEnDe for T
where T: ValueEn + ValueDe,

Source§

fn try_encode(&self) -> Result<Vec<u8>, Box<dyn RucError>>

Tries to encode the value into a byte vector.
Source§

fn encode(&self) -> Vec<u8>

Encodes the value into a byte vector, panicking on failure.
Source§

fn decode(bytes: &[u8]) -> Result<T, Box<dyn RucError>>

Decodes a value from a byte slice.
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
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,