//! Test trait implementations for the ordered Current QMDB. use super::{fixed, variable}; use crate::{ merkle::Graftable, qmdb::{ any::{ordered::variable::Operation as VariableOperation, FixedValue, VariableValue}, current::BitmapPrunedBits, operation::Key, }, translator::Translator, Context, }; use commonware_codec::Codec; use commonware_cryptography::Hasher; use commonware_utils::{bitmap::Readable as _, Array}; // ============================================================================= // Fixed variant test trait implementations // ============================================================================= crate::qmdb::any::traits::impl_db_any! { [F, E, K, V, H, T, const N: usize] fixed::Db where { F: Graftable, E: Context, K: Array, V: FixedValue + 'static, H: Hasher, T: Translator, } Family = F, Key = K, Value = V, Digest = H::Digest } // ============================================================================= // Variable variant test trait implementations // ============================================================================= crate::qmdb::any::traits::impl_db_any! { [F, E, K, V, H, T, const N: usize] variable::Db where { F: Graftable, E: Context, K: Key, V: VariableValue + 'static, H: Hasher, T: Translator, VariableOperation: Codec, } Family = F, Key = K, Value = V, Digest = H::Digest } // ============================================================================= // BitmapPrunedBits trait implementations // ============================================================================= impl< F: Graftable, E: Context, K: Array, V: FixedValue, H: Hasher, T: Translator, const N: usize, > BitmapPrunedBits for fixed::Db { fn pruned_bits(&self) -> u64 { self.status.pruned_bits() } fn get_bit(&self, index: u64) -> bool { self.status.get_bit(index) } async fn oldest_retained(&self) -> u64 { *self.any.bounds().await.start } } impl< F: Graftable, E: Context, K: Key, V: VariableValue, H: Hasher, T: Translator, const N: usize, > BitmapPrunedBits for variable::Db where VariableOperation: Codec, { fn pruned_bits(&self) -> u64 { self.status.pruned_bits() } fn get_bit(&self, index: u64) -> bool { self.status.get_bit(index) } async fn oldest_retained(&self) -> u64 { *self.any.bounds().await.start } } // ============================================================================= // Partitioned Fixed variant test trait implementations // ============================================================================= crate::qmdb::any::traits::impl_db_any! { [F, E, K, V, H, T, const P: usize, const N: usize] fixed::partitioned::Db where { F: Graftable, E: Context, K: Array, V: FixedValue + 'static, H: Hasher, T: Translator, } Family = F, Key = K, Value = V, Digest = H::Digest } impl< F: Graftable, E: Context, K: Array, V: FixedValue, H: Hasher, T: Translator, const P: usize, const N: usize, > BitmapPrunedBits for fixed::partitioned::Db { fn pruned_bits(&self) -> u64 { self.status.pruned_bits() } fn get_bit(&self, index: u64) -> bool { self.status.get_bit(index) } async fn oldest_retained(&self) -> u64 { *self.any.bounds().await.start } } // ============================================================================= // Partitioned Variable variant test trait implementations // ============================================================================= crate::qmdb::any::traits::impl_db_any! { [F, E, K, V, H, T, const P: usize, const N: usize] variable::partitioned::Db where { F: Graftable, E: Context, K: Key, V: VariableValue + 'static, H: Hasher, T: Translator, VariableOperation: Codec, } Family = F, Key = K, Value = V, Digest = H::Digest } impl< F: Graftable, E: Context, K: Key, V: VariableValue, H: Hasher, T: Translator, const P: usize, const N: usize, > BitmapPrunedBits for variable::partitioned::Db where VariableOperation: Codec, { fn pruned_bits(&self) -> u64 { self.status.pruned_bits() } fn get_bit(&self, index: u64) -> bool { self.status.get_bit(index) } async fn oldest_retained(&self) -> u64 { *self.any.bounds().await.start } }