1
0
Fork 0
mirror of https://forgejo.ellis.link/continuwuation/continuwuity.git synced 2025-07-31 04:08:30 +00:00

split remaining map suites

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2024-09-29 07:37:43 +00:00 committed by strawberry
parent 4496cf2d5b
commit 5192927a53
9 changed files with 205 additions and 180 deletions

View file

@ -0,0 +1,52 @@
use std::{convert::AsRef, fmt::Debug};
use conduit::implement;
use rocksdb::WriteBatchWithTransaction;
use crate::util::or_else;
#[implement(super::Map)]
#[tracing::instrument(skip(self, value), fields(%self), level = "trace")]
pub fn insert<K, V>(&self, key: &K, value: &V)
where
K: AsRef<[u8]> + ?Sized + Debug,
V: AsRef<[u8]> + ?Sized,
{
let write_options = &self.write_options;
self.db
.db
.put_cf_opt(&self.cf(), key, value, write_options)
.or_else(or_else)
.expect("database insert error");
if !self.db.corked() {
self.db.flush().expect("database flush error");
}
self.watchers.wake(key.as_ref());
}
#[implement(super::Map)]
#[tracing::instrument(skip(self, iter), fields(%self), level = "trace")]
pub fn insert_batch<'a, I, K, V>(&'a self, iter: I)
where
I: Iterator<Item = &'a (K, V)> + Send + Debug,
K: AsRef<[u8]> + Sized + Debug + 'a,
V: AsRef<[u8]> + Sized + 'a,
{
let mut batch = WriteBatchWithTransaction::<false>::default();
for (key, val) in iter {
batch.put_cf(&self.cf(), key.as_ref(), val.as_ref());
}
let write_options = &self.write_options;
self.db
.db
.write_opt(batch, write_options)
.or_else(or_else)
.expect("database insert batch error");
if !self.db.corked() {
self.db.flush().expect("database flush error");
}
}