pub struct MemoryStore { /* private fields */ }Expand description
An in-memory VersionStore backed by a hash map of version chains.
Each key maps to its versions in ascending commit-timestamp order, so a
snapshot read is a binary search for the newest version at or below the
snapshot timestamp. This is the default store of Db::new
and is well suited to caches, tests, and workloads that fit in memory.
MemoryStore is thread-safe and is meant to be shared: a Db
holds it behind an Arc and clones that handle to every thread. Versions
accumulate until garbage collection lands (a later roadmap phase), so a
long-lived store under heavy overwrite grows without bound for now.
§Examples
use txn_db::{Db, MemoryStore};
// `Db::new()` uses a `MemoryStore`; this is the explicit form.
let db = Db::with_store(MemoryStore::new());
let mut tx = db.begin();
tx.put(b"hello".to_vec(), b"world".to_vec());
tx.commit()?;Implementations§
Source§impl MemoryStore
impl MemoryStore
Sourcepub fn key_count(&self) -> usize
pub fn key_count(&self) -> usize
Number of distinct keys that have ever been written.
Counts keys, not versions, and includes keys whose latest version is a tombstone. Primarily useful in tests and diagnostics.
§Examples
use txn_db::{Db, MemoryStore};
let store = MemoryStore::new();
assert_eq!(store.key_count(), 0);