pub struct BTree { /* private fields */ }Implementations§
Source§impl BTree
impl BTree
Sourcepub fn open<P: AsRef<Path>>(path: P) -> Result<Self>
pub fn open<P: AsRef<Path>>(path: P) -> Result<Self>
Open or create a btree database at the given path.
Sourcepub fn exec<F, R>(&self, bucket: &str, f: F) -> Result<R>
pub fn exec<F, R>(&self, bucket: &str, f: F) -> Result<R>
Executes a read-write transaction on the specified bucket. Creates the bucket on successful commit if it doesn’t exist.
The transaction is committed if the closure returns Ok, but the commit can still fail
(e.g., conflict or I/O error). On failure, changes are rolled back.
If the closure returns Err, the transaction is rolled back (allocated pages are reclaimed).
§Warning
Nested calls to exec or view on the same BTree instance are NOT supported
and may lead to deadlocks or undefined behavior.
Sourcepub fn exec_multi<F, R>(&self, f: F) -> Result<R>
pub fn exec_multi<F, R>(&self, f: F) -> Result<R>
Executes multiple operations across different buckets in a single atomic transaction.
This is more efficient than calling exec multiple times because on success it performs
a single superblock update and disk sync at the end.
Sourcepub fn view<F, R>(&self, bucket: &str, f: F) -> Result<R>
pub fn view<F, R>(&self, bucket: &str, f: F) -> Result<R>
Executes a read-only transaction on the specified bucket.
§Warning
Nested calls to exec or view on the same BTree instance are NOT supported
and may lead to deadlocks or undefined behavior.
Sourcepub fn del_bucket<N>(&self, name: N) -> Result<()>
pub fn del_bucket<N>(&self, name: N) -> Result<()>
Delete a bucket by name and persist the change.
Sourcepub fn compact(&self, target_bytes: u64) -> Result<CompactStats>
pub fn compact(&self, target_bytes: u64) -> Result<CompactStats>
run tail-window compaction
target_bytes is the desired amount to reclaim, 0 uses the default ratio this moves live pages out of the tail window and tries to truncate the file if low-address free pages exceed the threshold, the mover allocates only below the tail