use std::fmt::Debug;
use std::hash::Hash;
use std::sync::Arc;
use neptune_locks::tokio::AtomicRw;
use serde::de::DeserializeOwned;
use serde::Serialize;
use super::super::storage_vec::Index;
use super::traits::*;
use super::PendingWrites;
use super::SimpleRustyReader;
use crate::storage::storage_schema::dbtmap_private::DbtMapPrivate;
#[derive(Debug)]
pub struct DbtMap<K, V> {
inner: DbtMapPrivate<K, V>,
}
impl<K, V> DbtMap<K, V>
where
K: Clone + Debug + Serialize + DeserializeOwned + Eq + Hash + Send + Sync,
V: Clone + Debug + Serialize + DeserializeOwned,
{
#[inline]
pub(super) async fn new(
pending_writes: AtomicRw<PendingWrites>,
reader: Arc<SimpleRustyReader>,
key_prefixes: [u8; 2],
name: &str,
) -> Self {
let map = DbtMapPrivate::new(pending_writes, reader, key_prefixes, name).await;
Self { inner: map }
}
#[inline]
pub async fn is_empty(&self) -> bool {
self.inner.is_empty().await
}
#[inline]
pub async fn len(&self) -> Index {
self.inner.len().await
}
pub async fn get(&self, key: &K) -> Option<V> {
self.inner.get(key).await
}
pub async fn contains_key(&self, key: &K) -> bool {
self.inner.contains_key(key).await
}
pub async fn insert(&mut self, key: K, value: V) -> Option<V> {
self.inner.insert(key, value).await
}
pub async fn all_keys(&self) -> Vec<K> {
self.inner.all_keys().await
}
pub async fn clear(&mut self) {
self.inner.clear().await
}
}
#[async_trait::async_trait]
impl<K, V> DbTable for DbtMap<K, V>
where
K: Clone + Debug + Serialize + DeserializeOwned + Eq + Hash + Send + Sync,
V: Clone + Serialize + DeserializeOwned + Send + Sync,
{
#[inline]
async fn restore_or_new(&mut self) {}
}