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
impl MapxRaw
Sourcepub unsafe fn shadow(&self) -> MapxRaw
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.
Sourcepub fn contains_key(&self, key: impl AsRef<[u8]>) -> bool
pub fn contains_key(&self, key: impl AsRef<[u8]>) -> bool
Sourcepub fn iter(&self) -> MapxIter<'_>
pub fn iter(&self) -> MapxIter<'_>
Returns an iterator over the map’s entries.
§Returns
A MapxRawIter that iterates over the key-value pairs.
Sourcepub fn range_detached<'a, R>(&self, bounds: R) -> MapxIter<'a>
pub fn range_detached<'a, R>(&self, bounds: R) -> MapxIter<'a>
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.
Sourcepub fn iter_mut(&mut self) -> MapxIterMut<'_>
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.
Sourcepub fn last(&self) -> Option<(Vec<u8>, Vec<u8>)>
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.
Sourcepub fn insert(&mut self, key: impl AsRef<[u8]>, value: impl AsRef<[u8]>)
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.
Sourcepub fn remove(&mut self, key: impl AsRef<[u8]>)
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.
Sourcepub fn batch_entry(&mut self) -> Box<dyn BatchTrait + '_>
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]));Sourcepub unsafe fn from_bytes(s: impl AsRef<[u8]>) -> MapxRaw
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.
Sourcepub unsafe fn from_prefix_slice(s: impl AsRef<[u8]>) -> MapxRaw
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.
Sourcepub fn as_bytes(&self) -> &[u8] ⓘ
pub fn as_bytes(&self) -> &[u8] ⓘ
Returns the byte representation of the MapxRaw.
§Returns
A byte slice &[u8] representing the MapxRaw.
Sourcepub fn as_prefix_slice(&self) -> &[u8; 8]
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.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for MapxRaw
impl<'de> Deserialize<'de> for MapxRaw
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<MapxRaw, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<MapxRaw, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl Serialize for MapxRaw
impl Serialize for MapxRaw
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl Eq for MapxRaw
impl StructuralPartialEq for MapxRaw
Auto Trait Implementations§
impl !Freeze for MapxRaw
impl RefUnwindSafe for MapxRaw
impl Send for MapxRaw
impl Sync for MapxRaw
impl Unpin for MapxRaw
impl UnsafeUnpin for MapxRaw
impl UnwindSafe for MapxRaw
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.