Skip to main content

Module mapx

Module mapx 

Source
Expand description

A HashMap-like structure that stores data on disk.

Mapx provides a key-value store where both keys and values are encoded using serde-like methods before being persisted. This allows for storing complex data types while maintaining a familiar HashMap interface.

§Examples

use vsdb::{Mapx, vsdb_set_base_dir, vsdb_get_base_dir};
use std::fs;

// It's recommended to use a temporary directory for testing
let dir = format!("/tmp/vsdb_testing/{}", rand::random::<u128>());
vsdb_set_base_dir(&dir).unwrap();

let mut m: Mapx<i32, String> = Mapx::new();

// Insert key-value pairs
m.insert(&1, &"hello".to_string());
m.insert(&2, &"world".to_string());

// Retrieve a value
assert_eq!(m.get(&1), Some("hello".to_string()));

// Iterate over the map
for (k, v) in m.iter() {
    println!("key: {}, val: {}", k, v);
}

// Remove a key-value pair
m.remove(&2);

// Clear the entire map
m.clear();

// Clean up the directory
fs::remove_dir_all(vsdb_get_base_dir()).unwrap();

Structs§

Mapx
A disk-based, HashMap-like data structure with typed keys and values.
MapxBatchEntry
A batch entry for Mapx.
MapxIter
An iterator over the entries of a Mapx.
MapxIterMut
A mutable iterator over the entries of a Mapx.
ValueIterMut
A mutable reference to a value in a Mapx iterator.