From aed52cef51284aa489f344464e4ca4a3598cc4e1 Mon Sep 17 00:00:00 2001 From: Christopher Berner Date: Sat, 3 Feb 2024 10:08:32 -0800 Subject: [PATCH 1/2] Rename RedbValue to Value --- examples/special_values.rs | 12 +++--- src/complex_types.rs | 4 +- src/db.rs | 16 +++---- src/lib.rs | 2 +- src/multimap_table.rs | 58 ++++++++++---------------- src/table.rs | 54 ++++++++++++------------ src/transaction_tracker.rs | 4 +- src/transactions.rs | 40 +++++++++--------- src/tree_store/btree.rs | 10 ++--- src/tree_store/btree_base.rs | 14 +++---- src/tree_store/btree_iters.rs | 42 +++++++++---------- src/tree_store/btree_mutator.rs | 8 ++-- src/tree_store/page_store/savepoint.rs | 4 +- src/tree_store/table_tree.rs | 16 +++---- src/tuple_types.rs | 6 +-- src/types.rs | 22 +++++----- tests/backward_compatibility.rs | 44 +++++++++---------- tests/basic_tests.rs | 4 +- 18 files changed, 173 insertions(+), 187 deletions(-) diff --git a/examples/special_values.rs b/examples/special_values.rs index fecbe7e5..f925b584 100644 --- a/examples/special_values.rs +++ b/examples/special_values.rs @@ -1,5 +1,5 @@ use redb::{ - Database, Error, ReadableTable, RedbKey, RedbValue, Table, TableDefinition, TableHandle, + Database, Error, ReadableTable, RedbKey, Table, TableDefinition, TableHandle, Value, WriteTransaction, }; use std::fs::{File, OpenOptions}; @@ -40,7 +40,7 @@ struct SpecialValuesTransaction<'db> { } impl<'db> SpecialValuesTransaction<'db> { - fn open_table( + fn open_table( &mut self, table: TableDefinition, ) -> SpecialValuesTable { @@ -58,13 +58,13 @@ impl<'db> SpecialValuesTransaction<'db> { } } -struct SpecialValuesTable<'txn, K: RedbKey + 'static, V: RedbValue + 'static> { +struct SpecialValuesTable<'txn, K: RedbKey + 'static, V: Value + 'static> { inner: Table<'txn, K, (u64, u64)>, file: &'txn mut File, _value_type: PhantomData, } -impl<'txn, K: RedbKey + 'static, V: RedbValue + 'static> SpecialValuesTable<'txn, K, V> { +impl<'txn, K: RedbKey + 'static, V: Value + 'static> SpecialValuesTable<'txn, K, V> { fn insert(&mut self, key: K::SelfType<'_>, value: V::SelfType<'_>) { // Append to end of file let offset = self.file.seek(SeekFrom::End(0)).unwrap(); @@ -87,12 +87,12 @@ impl<'txn, K: RedbKey + 'static, V: RedbValue + 'static> SpecialValuesTable<'txn } } -struct ValueAccessor { +struct ValueAccessor { data: Vec, _value_type: PhantomData, } -impl ValueAccessor { +impl ValueAccessor { fn value(&self) -> V::SelfType<'_> { V::from_bytes(&self.data) } diff --git a/src/complex_types.rs b/src/complex_types.rs index 39ed736a..47521b3d 100644 --- a/src/complex_types.rs +++ b/src/complex_types.rs @@ -1,4 +1,4 @@ -use crate::types::{RedbValue, TypeName}; +use crate::types::{TypeName, Value}; // Encode len as a varint and store it at the end of output fn encode_varint_len(len: usize, output: &mut Vec) { @@ -32,7 +32,7 @@ fn decode_varint_len(data: &[u8]) -> (usize, usize) { } } -impl RedbValue for Vec { +impl Value for Vec { type SelfType<'a> = Vec> where Self: 'a; diff --git a/src/db.rs b/src/db.rs index bab3f1e6..c21e939e 100644 --- a/src/db.rs +++ b/src/db.rs @@ -4,7 +4,7 @@ use crate::tree_store::{ InternalTableDefinition, PageHint, PageNumber, RawBtree, SerializedSavepoint, TableTreeMut, TableType, TransactionalMemory, PAGE_SIZE, }; -use crate::types::{RedbKey, RedbValue}; +use crate::types::{RedbKey, Value}; use crate::{ CompactionError, DatabaseError, Durability, ReadOnlyTable, SavepointError, StorageError, }; @@ -108,13 +108,13 @@ impl Sealed for UntypedMultimapTableHandle {} /// /// Note that the lifetime of the `K` and `V` type parameters does not impact the lifetimes of the data /// that is stored or retreived from the table -pub struct TableDefinition<'a, K: RedbKey + 'static, V: RedbValue + 'static> { +pub struct TableDefinition<'a, K: RedbKey + 'static, V: Value + 'static> { name: &'a str, _key_type: PhantomData, _value_type: PhantomData, } -impl<'a, K: RedbKey + 'static, V: RedbValue + 'static> TableDefinition<'a, K, V> { +impl<'a, K: RedbKey + 'static, V: Value + 'static> TableDefinition<'a, K, V> { /// Construct a new table with given `name` /// /// ## Invariant @@ -130,23 +130,23 @@ impl<'a, K: RedbKey + 'static, V: RedbValue + 'static> TableDefinition<'a, K, V> } } -impl<'a, K: RedbKey + 'static, V: RedbValue + 'static> TableHandle for TableDefinition<'a, K, V> { +impl<'a, K: RedbKey + 'static, V: Value + 'static> TableHandle for TableDefinition<'a, K, V> { fn name(&self) -> &str { self.name } } -impl Sealed for TableDefinition<'_, K, V> {} +impl Sealed for TableDefinition<'_, K, V> {} -impl<'a, K: RedbKey + 'static, V: RedbValue + 'static> Clone for TableDefinition<'a, K, V> { +impl<'a, K: RedbKey + 'static, V: Value + 'static> Clone for TableDefinition<'a, K, V> { fn clone(&self) -> Self { *self } } -impl<'a, K: RedbKey + 'static, V: RedbValue + 'static> Copy for TableDefinition<'a, K, V> {} +impl<'a, K: RedbKey + 'static, V: Value + 'static> Copy for TableDefinition<'a, K, V> {} -impl<'a, K: RedbKey + 'static, V: RedbValue + 'static> Display for TableDefinition<'a, K, V> { +impl<'a, K: RedbKey + 'static, V: Value + 'static> Display for TableDefinition<'a, K, V> { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { write!( f, diff --git a/src/lib.rs b/src/lib.rs index 219dcb8e..49f9863c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -71,7 +71,7 @@ pub use table::{ }; pub use transactions::{DatabaseStats, Durability, ReadTransaction, WriteTransaction}; pub use tree_store::{AccessGuard, AccessGuardMut, Savepoint}; -pub use types::{MutInPlaceValue, RedbKey, RedbValue, TypeName}; +pub use types::{MutInPlaceValue, RedbKey, TypeName, Value}; type Result = std::result::Result; diff --git a/src/multimap_table.rs b/src/multimap_table.rs index 61bd53f9..e9ab9982 100644 --- a/src/multimap_table.rs +++ b/src/multimap_table.rs @@ -7,7 +7,7 @@ use crate::tree_store::{ BtreeStats, CachePriority, Checksum, LeafAccessor, LeafMutator, Page, PageHint, PageNumber, RawBtree, RawLeafBuilder, TransactionalMemory, UntypedBtreeMut, BRANCH, LEAF, MAX_VALUE_LENGTH, }; -use crate::types::{RedbKey, RedbValue, TypeName}; +use crate::types::{RedbKey, TypeName, Value}; use crate::{AccessGuard, MultimapTableHandle, Result, StorageError, WriteTransaction}; use std::borrow::Borrow; use std::cmp::max; @@ -64,7 +64,7 @@ fn multimap_stats_helper( let inline_accessor = LeafAccessor::new( collection.as_inline(), fixed_value_size, - <() as RedbValue>::fixed_width(), + <() as Value>::fixed_width(), ); leaf_bytes += inline_accessor.length_of_pairs(0, inline_accessor.num_pairs()) as u64; @@ -93,7 +93,7 @@ fn multimap_stats_helper( Some(collection.as_subtree().0), mem, fixed_value_size, - <() as RedbValue>::fixed_width(), + <() as Value>::fixed_width(), )?; max_child_height = max(max_child_height, stats.tree_height); branch_pages += stats.branch_pages; @@ -397,7 +397,7 @@ impl std::fmt::Debug for DynamicCollection { } } -impl RedbValue for &DynamicCollection { +impl Value for &DynamicCollection { type SelfType<'a> = &'a DynamicCollection where Self: 'a; @@ -483,11 +483,8 @@ impl DynamicCollection { ) -> Result> { Ok(match collection.value().collection_type() { Inline => { - let leaf_iter = LeafKeyIter::new( - collection, - V::fixed_width(), - <() as RedbValue>::fixed_width(), - ); + let leaf_iter = + LeafKeyIter::new(collection, V::fixed_width(), <() as Value>::fixed_width()); MultimapValue::new_inline(leaf_iter, guard) } Subtree => { @@ -509,11 +506,8 @@ impl DynamicCollection { ) -> Result> { Ok(match collection.value().collection_type() { Inline => { - let leaf_iter = LeafKeyIter::new( - collection, - V::fixed_width(), - <() as RedbValue>::fixed_width(), - ); + let leaf_iter = + LeafKeyIter::new(collection, V::fixed_width(), <() as Value>::fixed_width()); MultimapValue::new_inline(leaf_iter, guard) } Subtree => { @@ -811,7 +805,7 @@ impl<'txn, K: RedbKey + 'static, V: RedbKey + 'static> MultimapTable<'txn, K, V> let accessor = LeafAccessor::new( leaf_data, V::fixed_width(), - <() as RedbValue>::fixed_width(), + <() as Value>::fixed_width(), ); let (position, found) = accessor.position::(value_bytes_ref); if found { @@ -827,7 +821,7 @@ impl<'txn, K: RedbKey + 'static, V: RedbKey + 'static> MultimapTable<'txn, K, V> new_pairs, new_pair_bytes, V::fixed_width(), - <() as RedbValue>::fixed_width(), + <() as Value>::fixed_width(), ); if required_inline_bytes < self.mem.get_page_size() / 2 { @@ -836,22 +830,19 @@ impl<'txn, K: RedbKey + 'static, V: RedbKey + 'static> MultimapTable<'txn, K, V> &mut data, new_pairs, V::fixed_width(), - <() as RedbValue>::fixed_width(), + <() as Value>::fixed_width(), new_key_bytes, ); for i in 0..accessor.num_pairs() { if i == position { - builder.append( - value_bytes_ref, - <() as RedbValue>::as_bytes(&()).as_ref(), - ); + builder + .append(value_bytes_ref, <() as Value>::as_bytes(&()).as_ref()); } let entry = accessor.entry(i).unwrap(); builder.append(entry.key(), entry.value()); } if position == accessor.num_pairs() { - builder - .append(value_bytes_ref, <() as RedbValue>::as_bytes(&()).as_ref()); + builder.append(value_bytes_ref, <() as Value>::as_bytes(&()).as_ref()); } drop(builder); drop(guard); @@ -908,7 +899,7 @@ impl<'txn, K: RedbKey + 'static, V: RedbKey + 'static> MultimapTable<'txn, K, V> 1, value_bytes_ref.len(), V::fixed_width(), - <() as RedbValue>::fixed_width(), + <() as Value>::fixed_width(), ); if required_inline_bytes < self.mem.get_page_size() / 2 { let mut data = vec![0; required_inline_bytes]; @@ -916,10 +907,10 @@ impl<'txn, K: RedbKey + 'static, V: RedbKey + 'static> MultimapTable<'txn, K, V> &mut data, 1, V::fixed_width(), - <() as RedbValue>::fixed_width(), + <() as Value>::fixed_width(), value_bytes_ref.len(), ); - builder.append(value_bytes_ref, <() as RedbValue>::as_bytes(&()).as_ref()); + builder.append(value_bytes_ref, <() as Value>::as_bytes(&()).as_ref()); drop(builder); let inline_data = DynamicCollection::::make_inline_data(&data); self.tree @@ -965,11 +956,8 @@ impl<'txn, K: RedbKey + 'static, V: RedbKey + 'static> MultimapTable<'txn, K, V> let existed = match v.collection_type() { Inline => { let leaf_data = v.as_inline(); - let accessor = LeafAccessor::new( - leaf_data, - V::fixed_width(), - <() as RedbValue>::fixed_width(), - ); + let accessor = + LeafAccessor::new(leaf_data, V::fixed_width(), <() as Value>::fixed_width()); if let Some(position) = accessor.find_key::(V::as_bytes(value.borrow()).as_ref()) { let old_num_pairs = accessor.num_pairs(); @@ -983,7 +971,7 @@ impl<'txn, K: RedbKey + 'static, V: RedbKey + 'static> MultimapTable<'txn, K, V> old_num_pairs - 1, old_pairs_len - removed_value_len, V::fixed_width(), - <() as RedbValue>::fixed_width(), + <() as Value>::fixed_width(), ); let mut new_data = vec![0; required]; let new_key_len = @@ -992,7 +980,7 @@ impl<'txn, K: RedbKey + 'static, V: RedbKey + 'static> MultimapTable<'txn, K, V> &mut new_data, old_num_pairs - 1, V::fixed_width(), - <() as RedbValue>::fixed_width(), + <() as Value>::fixed_width(), new_key_len, ); for i in 0..old_num_pairs { @@ -1031,7 +1019,7 @@ impl<'txn, K: RedbKey + 'static, V: RedbKey + 'static> MultimapTable<'txn, K, V> let accessor = LeafAccessor::new( page.memory(), V::fixed_width(), - <() as RedbValue>::fixed_width(), + <() as Value>::fixed_width(), ); let len = accessor.total_length(); if len < self.mem.get_page_size() / 2 { @@ -1088,7 +1076,7 @@ impl<'txn, K: RedbKey + 'static, V: RedbKey + 'static> MultimapTable<'txn, K, V> let all_pages = AllPageNumbersBtreeIter::new( root, V::fixed_width(), - <() as RedbValue>::fixed_width(), + <() as Value>::fixed_width(), self.mem.clone(), )?; for page in all_pages { diff --git a/src/table.rs b/src/table.rs index 329a34af..25ad414f 100644 --- a/src/table.rs +++ b/src/table.rs @@ -4,7 +4,7 @@ use crate::tree_store::{ AccessGuardMut, Btree, BtreeDrain, BtreeDrainFilter, BtreeMut, BtreeRangeIter, Checksum, PageHint, PageNumber, RawBtree, TransactionalMemory, MAX_VALUE_LENGTH, }; -use crate::types::{MutInPlaceValue, RedbKey, RedbValue}; +use crate::types::{MutInPlaceValue, RedbKey, Value}; use crate::{AccessGuard, StorageError, WriteTransaction}; use crate::{Result, TableHandle}; use std::borrow::Borrow; @@ -58,19 +58,19 @@ impl TableStats { } /// A table containing key-value mappings -pub struct Table<'txn, K: RedbKey + 'static, V: RedbValue + 'static> { +pub struct Table<'txn, K: RedbKey + 'static, V: Value + 'static> { name: String, transaction: &'txn WriteTransaction, tree: BtreeMut<'txn, K, V>, } -impl TableHandle for Table<'_, K, V> { +impl TableHandle for Table<'_, K, V> { fn name(&self) -> &str { &self.name } } -impl<'txn, K: RedbKey + 'static, V: RedbValue + 'static> Table<'txn, K, V> { +impl<'txn, K: RedbKey + 'static, V: Value + 'static> Table<'txn, K, V> { pub(crate) fn new( name: &str, table_root: Option<(PageNumber, Checksum)>, @@ -215,7 +215,7 @@ impl<'txn, K: RedbKey + 'static, V: MutInPlaceValue + 'static> Table<'txn, K, V> } } -impl<'txn, K: RedbKey + 'static, V: RedbValue + 'static> ReadableTable for Table<'txn, K, V> { +impl<'txn, K: RedbKey + 'static, V: Value + 'static> ReadableTable for Table<'txn, K, V> { fn get<'a>(&self, key: impl Borrow>) -> Result>> where K: 'a, @@ -255,15 +255,15 @@ impl<'txn, K: RedbKey + 'static, V: RedbValue + 'static> ReadableTable for } } -impl Sealed for Table<'_, K, V> {} +impl Sealed for Table<'_, K, V> {} -impl<'txn, K: RedbKey + 'static, V: RedbValue + 'static> Drop for Table<'txn, K, V> { +impl<'txn, K: RedbKey + 'static, V: Value + 'static> Drop for Table<'txn, K, V> { fn drop(&mut self) { self.transaction.close_table(&self.name, &self.tree); } } -fn debug_helper( +fn debug_helper( f: &mut Formatter<'_>, name: &str, len: Result, @@ -306,13 +306,13 @@ fn debug_helper( Ok(()) } -impl Debug for Table<'_, K, V> { +impl Debug for Table<'_, K, V> { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { debug_helper(f, &self.name, self.len(), self.first(), self.last()) } } -pub trait ReadableTable: Sealed { +pub trait ReadableTable: Sealed { /// Returns the value corresponding to the given key fn get<'a>(&self, key: impl Borrow>) -> Result>> where @@ -413,13 +413,13 @@ impl ReadOnlyUntypedTable { } /// A read-only table -pub struct ReadOnlyTable { +pub struct ReadOnlyTable { name: String, tree: Btree, transaction_guard: Arc, } -impl ReadOnlyTable { +impl ReadOnlyTable { pub(crate) fn new( name: String, root_page: Option<(PageNumber, Checksum)>, @@ -446,7 +446,7 @@ impl ReadOnlyTable { } } -impl ReadableTable for ReadOnlyTable { +impl ReadableTable for ReadOnlyTable { fn get<'a>(&self, key: impl Borrow>) -> Result>> where K: 'a, @@ -486,20 +486,20 @@ impl ReadableTable for ReadO } } -impl Sealed for ReadOnlyTable {} +impl Sealed for ReadOnlyTable {} -impl Debug for ReadOnlyTable { +impl Debug for ReadOnlyTable { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { debug_helper(f, &self.name, self.len(), self.first(), self.last()) } } -pub struct Drain<'a, K: RedbKey + 'static, V: RedbValue + 'static> { +pub struct Drain<'a, K: RedbKey + 'static, V: Value + 'static> { inner: BtreeDrain, _lifetime: PhantomData<&'a ()>, } -impl<'a, K: RedbKey + 'static, V: RedbValue + 'static> Drain<'a, K, V> { +impl<'a, K: RedbKey + 'static, V: Value + 'static> Drain<'a, K, V> { fn new(inner: BtreeDrain) -> Self { Self { inner, @@ -508,7 +508,7 @@ impl<'a, K: RedbKey + 'static, V: RedbValue + 'static> Drain<'a, K, V> { } } -impl<'a, K: RedbKey + 'static, V: RedbValue + 'static> Iterator for Drain<'a, K, V> { +impl<'a, K: RedbKey + 'static, V: Value + 'static> Iterator for Drain<'a, K, V> { type Item = Result<(AccessGuard<'a, K>, AccessGuard<'a, V>)>; fn next(&mut self) -> Option { @@ -522,7 +522,7 @@ impl<'a, K: RedbKey + 'static, V: RedbValue + 'static> Iterator for Drain<'a, K, } } -impl<'a, K: RedbKey + 'static, V: RedbValue + 'static> DoubleEndedIterator for Drain<'a, K, V> { +impl<'a, K: RedbKey + 'static, V: Value + 'static> DoubleEndedIterator for Drain<'a, K, V> { fn next_back(&mut self) -> Option { let entry = self.inner.next_back()?; Some(entry.map(|entry| { @@ -537,7 +537,7 @@ impl<'a, K: RedbKey + 'static, V: RedbValue + 'static> DoubleEndedIterator for D pub struct DrainFilter< 'a, K: RedbKey + 'static, - V: RedbValue + 'static, + V: Value + 'static, F: for<'f> FnMut(K::SelfType<'f>, V::SelfType<'f>) -> bool, > { inner: BtreeDrainFilter, @@ -547,7 +547,7 @@ pub struct DrainFilter< impl< 'a, K: RedbKey + 'static, - V: RedbValue + 'static, + V: Value + 'static, F: for<'f> FnMut(K::SelfType<'f>, V::SelfType<'f>) -> bool, > DrainFilter<'a, K, V, F> { @@ -562,7 +562,7 @@ impl< impl< 'a, K: RedbKey + 'static, - V: RedbValue + 'static, + V: Value + 'static, F: for<'f> FnMut(K::SelfType<'f>, V::SelfType<'f>) -> bool, > Iterator for DrainFilter<'a, K, V, F> { @@ -582,7 +582,7 @@ impl< impl< 'a, K: RedbKey + 'static, - V: RedbValue + 'static, + V: Value + 'static, F: for<'f> FnMut(K::SelfType<'f>, V::SelfType<'f>) -> bool, > DoubleEndedIterator for DrainFilter<'a, K, V, F> { @@ -598,14 +598,14 @@ impl< } #[derive(Clone)] -pub struct Range<'a, K: RedbKey + 'static, V: RedbValue + 'static> { +pub struct Range<'a, K: RedbKey + 'static, V: Value + 'static> { inner: BtreeRangeIter, _transaction_guard: Arc, // TODO: replace with TransactionGuard? _lifetime: PhantomData<&'a ()>, } -impl<'a, K: RedbKey + 'static, V: RedbValue + 'static> Range<'a, K, V> { +impl<'a, K: RedbKey + 'static, V: Value + 'static> Range<'a, K, V> { pub(super) fn new(inner: BtreeRangeIter, guard: Arc) -> Self { Self { inner, @@ -615,7 +615,7 @@ impl<'a, K: RedbKey + 'static, V: RedbValue + 'static> Range<'a, K, V> { } } -impl<'a, K: RedbKey + 'static, V: RedbValue + 'static> Iterator for Range<'a, K, V> { +impl<'a, K: RedbKey + 'static, V: Value + 'static> Iterator for Range<'a, K, V> { type Item = Result<(AccessGuard<'a, K>, AccessGuard<'a, V>)>; fn next(&mut self) -> Option { @@ -630,7 +630,7 @@ impl<'a, K: RedbKey + 'static, V: RedbValue + 'static> Iterator for Range<'a, K, } } -impl<'a, K: RedbKey + 'static, V: RedbValue + 'static> DoubleEndedIterator for Range<'a, K, V> { +impl<'a, K: RedbKey + 'static, V: Value + 'static> DoubleEndedIterator for Range<'a, K, V> { fn next_back(&mut self) -> Option { self.inner.next_back().map(|x| { x.map(|entry| { diff --git a/src/transaction_tracker.rs b/src/transaction_tracker.rs index b25f2d28..ea5fde24 100644 --- a/src/transaction_tracker.rs +++ b/src/transaction_tracker.rs @@ -1,5 +1,5 @@ use crate::tree_store::TransactionalMemory; -use crate::{RedbKey, RedbValue, Result, Savepoint, TypeName}; +use crate::{RedbKey, Result, Savepoint, TypeName, Value}; #[cfg(feature = "logging")] use log::info; use std::cmp::Ordering; @@ -48,7 +48,7 @@ impl SavepointId { } } -impl RedbValue for SavepointId { +impl Value for SavepointId { type SelfType<'a> = SavepointId; type AsBytes<'a> = [u8; size_of::()]; diff --git a/src/transactions.rs b/src/transactions.rs index 2657fd2c..1d81d906 100644 --- a/src/transactions.rs +++ b/src/transactions.rs @@ -9,7 +9,7 @@ use crate::tree_store::{ PageNumber, SerializedSavepoint, TableTree, TableTreeMut, TableType, TransactionalMemory, MAX_VALUE_LENGTH, }; -use crate::types::{RedbKey, RedbValue}; +use crate::types::{RedbKey, Value}; use crate::{ AccessGuard, MultimapTable, MultimapTableDefinition, MultimapTableHandle, Range, ReadOnlyMultimapTable, ReadOnlyTable, Result, Savepoint, SavepointError, StorageError, Table, @@ -33,13 +33,13 @@ const NEXT_SAVEPOINT_TABLE: SystemTableDefinition<(), SavepointId> = pub(crate) const SAVEPOINT_TABLE: SystemTableDefinition = SystemTableDefinition::new("persistent_savepoints"); -pub struct SystemTableDefinition<'a, K: RedbKey + 'static, V: RedbValue + 'static> { +pub struct SystemTableDefinition<'a, K: RedbKey + 'static, V: Value + 'static> { name: &'a str, _key_type: PhantomData, _value_type: PhantomData, } -impl<'a, K: RedbKey + 'static, V: RedbValue + 'static> SystemTableDefinition<'a, K, V> { +impl<'a, K: RedbKey + 'static, V: Value + 'static> SystemTableDefinition<'a, K, V> { pub const fn new(name: &'a str) -> Self { assert!(!name.is_empty()); Self { @@ -50,25 +50,23 @@ impl<'a, K: RedbKey + 'static, V: RedbValue + 'static> SystemTableDefinition<'a, } } -impl<'a, K: RedbKey + 'static, V: RedbValue + 'static> TableHandle - for SystemTableDefinition<'a, K, V> -{ +impl<'a, K: RedbKey + 'static, V: Value + 'static> TableHandle for SystemTableDefinition<'a, K, V> { fn name(&self) -> &str { self.name } } -impl Sealed for SystemTableDefinition<'_, K, V> {} +impl Sealed for SystemTableDefinition<'_, K, V> {} -impl<'a, K: RedbKey + 'static, V: RedbValue + 'static> Clone for SystemTableDefinition<'a, K, V> { +impl<'a, K: RedbKey + 'static, V: Value + 'static> Clone for SystemTableDefinition<'a, K, V> { fn clone(&self) -> Self { *self } } -impl<'a, K: RedbKey + 'static, V: RedbValue + 'static> Copy for SystemTableDefinition<'a, K, V> {} +impl<'a, K: RedbKey + 'static, V: Value + 'static> Copy for SystemTableDefinition<'a, K, V> {} -impl<'a, K: RedbKey + 'static, V: RedbValue + 'static> Display for SystemTableDefinition<'a, K, V> { +impl<'a, K: RedbKey + 'static, V: Value + 'static> Display for SystemTableDefinition<'a, K, V> { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { write!( f, @@ -192,14 +190,14 @@ pub enum Durability { } // Like a Table but only one may be open at a time to avoid possible races -pub struct SystemTable<'db, 's, K: RedbKey + 'static, V: RedbValue + 'static> { +pub struct SystemTable<'db, 's, K: RedbKey + 'static, V: Value + 'static> { name: String, namespace: &'s mut SystemNamespace<'db>, tree: BtreeMut<'s, K, V>, transaction_guard: Arc, } -impl<'db, 's, K: RedbKey + 'static, V: RedbValue + 'static> SystemTable<'db, 's, K, V> { +impl<'db, 's, K: RedbKey + 'static, V: Value + 'static> SystemTable<'db, 's, K, V> { fn new( name: &str, table_root: Option<(PageNumber, Checksum)>, @@ -260,7 +258,7 @@ impl<'db, 's, K: RedbKey + 'static, V: RedbValue + 'static> SystemTable<'db, 's, } } -impl<'db, 's, K: RedbKey + 'static, V: RedbValue + 'static> Drop for SystemTable<'db, 's, K, V> { +impl<'db, 's, K: RedbKey + 'static, V: Value + 'static> Drop for SystemTable<'db, 's, K, V> { fn drop(&mut self) { self.namespace.close_table(&self.name, &self.tree); } @@ -272,7 +270,7 @@ struct SystemNamespace<'db> { } impl<'db> SystemNamespace<'db> { - fn open_system_table<'txn, 's, K: RedbKey + 'static, V: RedbValue + 'static>( + fn open_system_table<'txn, 's, K: RedbKey + 'static, V: Value + 'static>( &'s mut self, transaction: &'txn WriteTransaction, definition: SystemTableDefinition, @@ -297,7 +295,7 @@ impl<'db> SystemNamespace<'db> { )) } - fn close_table( + fn close_table( &mut self, name: &str, table: &BtreeMut, @@ -314,7 +312,7 @@ struct TableNamespace<'db> { impl<'db> TableNamespace<'db> { #[track_caller] - fn inner_open( + fn inner_open( &mut self, name: &str, table_type: TableType, @@ -353,7 +351,7 @@ impl<'db> TableNamespace<'db> { } #[track_caller] - pub fn open_table<'txn, K: RedbKey + 'static, V: RedbValue + 'static>( + pub fn open_table<'txn, K: RedbKey + 'static, V: Value + 'static>( &mut self, transaction: &'txn WriteTransaction, definition: TableDefinition, @@ -405,7 +403,7 @@ impl<'db> TableNamespace<'db> { self.inner_delete(name, TableType::Multimap) } - pub(crate) fn close_table( + pub(crate) fn close_table( &mut self, name: &str, table: &BtreeMut, @@ -786,7 +784,7 @@ impl WriteTransaction { /// /// The table will be created if it does not exist #[track_caller] - pub fn open_table<'txn, K: RedbKey + 'static, V: RedbValue + 'static>( + pub fn open_table<'txn, K: RedbKey + 'static, V: Value + 'static>( &'txn self, definition: TableDefinition, ) -> Result, TableError> { @@ -807,7 +805,7 @@ impl WriteTransaction { .open_multimap_table(self, definition) } - pub(crate) fn close_table( + pub(crate) fn close_table( &self, name: &str, table: &BtreeMut, @@ -1202,7 +1200,7 @@ impl ReadTransaction { } /// Open the given table - pub fn open_table( + pub fn open_table( &self, definition: TableDefinition, ) -> Result, TableError> { diff --git a/src/tree_store/btree.rs b/src/tree_store/btree.rs index f82238a9..6ba729c8 100644 --- a/src/tree_store/btree.rs +++ b/src/tree_store/btree.rs @@ -9,7 +9,7 @@ use crate::tree_store::page_store::{CachePriority, Page, PageImpl, PageMut, Tran use crate::tree_store::{ AccessGuardMut, AllPageNumbersBtreeIter, BtreeDrainFilter, BtreeRangeIter, PageHint, PageNumber, }; -use crate::types::{MutInPlaceValue, RedbKey, RedbValue}; +use crate::types::{MutInPlaceValue, RedbKey, Value}; use crate::{AccessGuard, Result}; #[cfg(feature = "logging")] use log::trace; @@ -217,7 +217,7 @@ impl UntypedBtreeMut { } } -pub(crate) struct BtreeMut<'a, K: RedbKey + 'static, V: RedbValue + 'static> { +pub(crate) struct BtreeMut<'a, K: RedbKey + 'static, V: Value + 'static> { mem: Arc, transaction_guard: Arc, root: Arc>>, @@ -227,7 +227,7 @@ pub(crate) struct BtreeMut<'a, K: RedbKey + 'static, V: RedbValue + 'static> { _lifetime: PhantomData<&'a ()>, } -impl BtreeMut<'_, K, V> { +impl BtreeMut<'_, K, V> { pub(crate) fn new( root: Option<(PageNumber, Checksum)>, guard: Arc, @@ -552,7 +552,7 @@ impl RawBtree { } } -pub(crate) struct Btree { +pub(crate) struct Btree { mem: Arc, _transaction_guard: Arc, // Cache of the root page to avoid repeated lookups @@ -563,7 +563,7 @@ pub(crate) struct Btree { _value_type: PhantomData, } -impl Btree { +impl Btree { pub(crate) fn new( root: Option<(PageNumber, Checksum)>, hint: PageHint, diff --git a/src/tree_store/btree_base.rs b/src/tree_store/btree_base.rs index f5ba27e4..cabe36d0 100644 --- a/src/tree_store/btree_base.rs +++ b/src/tree_store/btree_base.rs @@ -2,7 +2,7 @@ use crate::tree_store::page_store::{ xxh3_checksum, CachePriority, Page, PageImpl, PageMut, TransactionalMemory, }; use crate::tree_store::PageNumber; -use crate::types::{MutInPlaceValue, RedbKey, RedbValue}; +use crate::types::{MutInPlaceValue, RedbKey, Value}; use crate::{Result, StorageError}; use std::cmp::Ordering; use std::marker::PhantomData; @@ -81,7 +81,7 @@ impl EitherPage { } } -pub struct AccessGuard<'a, V: RedbValue> { +pub struct AccessGuard<'a, V: Value> { page: EitherPage, offset: usize, len: usize, @@ -91,7 +91,7 @@ pub struct AccessGuard<'a, V: RedbValue> { _lifetime: PhantomData<&'a ()>, } -impl<'a, V: RedbValue> AccessGuard<'a, V> { +impl<'a, V: Value> AccessGuard<'a, V> { pub(crate) fn with_page(page: PageImpl, range: Range) -> Self { Self { page: EitherPage::Immutable(page), @@ -151,7 +151,7 @@ impl<'a, V: RedbValue> AccessGuard<'a, V> { } } -impl<'a, V: RedbValue> Drop for AccessGuard<'a, V> { +impl<'a, V: Value> Drop for AccessGuard<'a, V> { fn drop(&mut self) { match self.on_drop { OnDrop::None => {} @@ -170,7 +170,7 @@ impl<'a, V: RedbValue> Drop for AccessGuard<'a, V> { } } -pub struct AccessGuardMut<'a, V: RedbValue> { +pub struct AccessGuardMut<'a, V: Value> { page: PageMut, offset: usize, len: usize, @@ -179,7 +179,7 @@ pub struct AccessGuardMut<'a, V: RedbValue> { _lifetime: PhantomData<&'a ()>, } -impl<'a, V: RedbValue> AccessGuardMut<'a, V> { +impl<'a, V: Value> AccessGuardMut<'a, V> { pub(crate) fn new(page: PageMut, offset: usize, len: usize) -> Self { AccessGuardMut { page, @@ -243,7 +243,7 @@ impl<'a> LeafAccessor<'a> { } } - pub(super) fn print_node(&self, include_value: bool) { + pub(super) fn print_node(&self, include_value: bool) { let mut i = 0; while let Some(entry) = self.entry(i) { eprint!(" key_{}={:?}", i, K::from_bytes(entry.key())); diff --git a/src/tree_store/btree_iters.rs b/src/tree_store/btree_iters.rs index 00bb29f4..39ce4cd2 100644 --- a/src/tree_store/btree_iters.rs +++ b/src/tree_store/btree_iters.rs @@ -3,7 +3,7 @@ use crate::tree_store::btree_base::{BRANCH, LEAF}; use crate::tree_store::btree_iters::RangeIterState::{Internal, Leaf}; use crate::tree_store::page_store::{Page, PageImpl, TransactionalMemory}; use crate::tree_store::PageNumber; -use crate::types::{RedbKey, RedbValue}; +use crate::types::{RedbKey, Value}; use crate::Result; use std::borrow::Borrow; use std::collections::Bound; @@ -123,7 +123,7 @@ impl RangeIterState { } } - fn get_entry(&self) -> Option> { + fn get_entry(&self) -> Option> { match self { Leaf { page, @@ -142,7 +142,7 @@ impl RangeIterState { } } -pub(crate) struct EntryGuard { +pub(crate) struct EntryGuard { page: PageImpl, key_range: Range, value_range: Range, @@ -150,7 +150,7 @@ pub(crate) struct EntryGuard { _value_type: PhantomData, } -impl EntryGuard { +impl EntryGuard { fn new(page: PageImpl, key_range: Range, value_range: Range) -> Self { Self { page, @@ -243,14 +243,14 @@ impl Iterator for AllPageNumbersBtreeIter { } } -pub(crate) struct BtreeDrain { +pub(crate) struct BtreeDrain { inner: BtreeRangeIter, free_on_drop: Vec, master_free_list: Arc>>, mem: Arc, } -impl BtreeDrain { +impl BtreeDrain { pub(crate) fn new( inner: BtreeRangeIter, free_on_drop: Vec, @@ -266,7 +266,7 @@ impl BtreeDrain { } } -impl Iterator for BtreeDrain { +impl Iterator for BtreeDrain { type Item = Result>; fn next(&mut self) -> Option { @@ -274,13 +274,13 @@ impl Iterator for BtreeDrain { } } -impl DoubleEndedIterator for BtreeDrain { +impl DoubleEndedIterator for BtreeDrain { fn next_back(&mut self) -> Option { self.inner.next_back() } } -impl Drop for BtreeDrain { +impl Drop for BtreeDrain { fn drop(&mut self) { // Ensure that the iter is entirely consumed, so that it doesn't have any references to the pages // to be freed @@ -299,7 +299,7 @@ impl Drop for BtreeDrain { pub(crate) struct BtreeDrainFilter< K: RedbKey + 'static, - V: RedbValue + 'static, + V: Value + 'static, F: for<'f> FnMut(K::SelfType<'f>, V::SelfType<'f>) -> bool, > { inner: BtreeRangeIter, @@ -309,7 +309,7 @@ pub(crate) struct BtreeDrainFilter< mem: Arc, } -impl FnMut(K::SelfType<'f>, V::SelfType<'f>) -> bool> +impl FnMut(K::SelfType<'f>, V::SelfType<'f>) -> bool> BtreeDrainFilter { pub(crate) fn new( @@ -329,7 +329,7 @@ impl FnMut(K::SelfType<'f>, V::SelfType<'f> } } -impl FnMut(K::SelfType<'f>, V::SelfType<'f>) -> bool> Iterator +impl FnMut(K::SelfType<'f>, V::SelfType<'f>) -> bool> Iterator for BtreeDrainFilter { type Item = Result>; @@ -346,7 +346,7 @@ impl FnMut(K::SelfType<'f>, V::SelfType<'f> } } -impl FnMut(K::SelfType<'f>, V::SelfType<'f>) -> bool> +impl FnMut(K::SelfType<'f>, V::SelfType<'f>) -> bool> DoubleEndedIterator for BtreeDrainFilter { fn next_back(&mut self) -> Option { @@ -361,7 +361,7 @@ impl FnMut(K::SelfType<'f>, V::SelfType<'f> } } -impl FnMut(K::SelfType<'f>, V::SelfType<'f>) -> bool> Drop +impl FnMut(K::SelfType<'f>, V::SelfType<'f>) -> bool> Drop for BtreeDrainFilter { fn drop(&mut self) { @@ -381,7 +381,7 @@ impl FnMut(K::SelfType<'f>, V::SelfType<'f> } #[derive(Clone)] -pub(crate) struct BtreeRangeIter { +pub(crate) struct BtreeRangeIter { left: Option, // Exclusive. The previous element returned right: Option, // Exclusive. The previous element returned include_left: bool, // left is inclusive, instead of exclusive @@ -391,7 +391,7 @@ pub(crate) struct BtreeRangeIter { _value_type: PhantomData, } -impl BtreeRangeIter { +impl BtreeRangeIter { pub(crate) fn new<'a, T: RangeBounds, KR: Borrow>>( query_range: &'_ T, table_root: Option, @@ -467,7 +467,7 @@ impl BtreeRangeIter { } } -impl Iterator for BtreeRangeIter { +impl Iterator for BtreeRangeIter { type Item = Result>; fn next(&mut self) -> Option { @@ -535,7 +535,7 @@ impl Iterator for BtreeRangeIter { } } -impl DoubleEndedIterator for BtreeRangeIter { +impl DoubleEndedIterator for BtreeRangeIter { fn next_back(&mut self) -> Option { if let ( Some(Leaf { @@ -601,7 +601,7 @@ impl DoubleEndedIterator for BtreeRangeIter { } } -fn find_iter_unbounded( +fn find_iter_unbounded( page: PageImpl, mut parent: Option>, reverse: bool, @@ -647,7 +647,7 @@ fn find_iter_unbounded( // Returns a bool indicating whether the first entry pointed to by the state is included in the // queried range -fn find_iter_left( +fn find_iter_left( page: PageImpl, mut parent: Option>, query: &[u8], @@ -695,7 +695,7 @@ fn find_iter_left( } } -fn find_iter_right( +fn find_iter_right( page: PageImpl, mut parent: Option>, query: &[u8], diff --git a/src/tree_store/btree_mutator.rs b/src/tree_store/btree_mutator.rs index 4d9ad533..ec31037a 100644 --- a/src/tree_store/btree_mutator.rs +++ b/src/tree_store/btree_mutator.rs @@ -7,7 +7,7 @@ use crate::tree_store::btree_mutator::DeletionResult::{ }; use crate::tree_store::page_store::{Page, PageImpl}; use crate::tree_store::{AccessGuardMut, PageNumber, RawLeafBuilder, TransactionalMemory}; -use crate::types::{RedbKey, RedbValue}; +use crate::types::{RedbKey, Value}; use crate::{AccessGuard, Result}; use std::cmp::{max, min}; use std::marker::PhantomData; @@ -31,7 +31,7 @@ enum DeletionResult { DeletedBranch(PageNumber, Checksum), } -struct InsertionResult<'a, V: RedbValue> { +struct InsertionResult<'a, V: Value> { // the new root page new_root: PageNumber, // checksum of the root page @@ -44,7 +44,7 @@ struct InsertionResult<'a, V: RedbValue> { old_value: Option>, } -pub(crate) struct MutateHelper<'a, 'b, K: RedbKey, V: RedbValue> { +pub(crate) struct MutateHelper<'a, 'b, K: RedbKey, V: Value> { root: &'b mut Option<(PageNumber, Checksum)>, modify_uncommitted: bool, mem: Arc, @@ -54,7 +54,7 @@ pub(crate) struct MutateHelper<'a, 'b, K: RedbKey, V: RedbValue> { _lifetime: PhantomData<&'a ()>, } -impl<'a, 'b, K: RedbKey, V: RedbValue> MutateHelper<'a, 'b, K, V> { +impl<'a, 'b, K: RedbKey, V: Value> MutateHelper<'a, 'b, K, V> { pub(crate) fn new( root: &'b mut Option<(PageNumber, Checksum)>, mem: Arc, diff --git a/src/tree_store/page_store/savepoint.rs b/src/tree_store/page_store/savepoint.rs index 6425af3b..22dbf62b 100644 --- a/src/tree_store/page_store/savepoint.rs +++ b/src/tree_store/page_store/savepoint.rs @@ -1,6 +1,6 @@ use crate::transaction_tracker::{SavepointId, TransactionId, TransactionTracker}; use crate::tree_store::{Checksum, PageNumber, TransactionalMemory}; -use crate::{RedbValue, TypeName}; +use crate::{TypeName, Value}; use std::fmt::Debug; use std::mem::size_of; use std::sync::Arc; @@ -297,7 +297,7 @@ impl<'a> SerializedSavepoint<'a> { } } -impl<'data> RedbValue for SerializedSavepoint<'data> { +impl<'data> Value for SerializedSavepoint<'data> { type SelfType<'a> = SerializedSavepoint<'a> where Self: 'a; type AsBytes<'a> = &'a [u8] where Self: 'a; diff --git a/src/tree_store/table_tree.rs b/src/tree_store/table_tree.rs index c5de5eb6..a7d6cce9 100644 --- a/src/tree_store/table_tree.rs +++ b/src/tree_store/table_tree.rs @@ -9,7 +9,7 @@ use crate::tree_store::btree_iters::AllPageNumbersBtreeIter; use crate::tree_store::{ Btree, BtreeMut, BtreeRangeIter, PageHint, PageNumber, RawBtree, TransactionalMemory, }; -use crate::types::{MutInPlaceValue, RedbKey, RedbValue, TypeName}; +use crate::types::{MutInPlaceValue, RedbKey, TypeName, Value}; use crate::{DatabaseStats, Result}; use std::cmp::max; use std::collections::{HashMap, HashSet}; @@ -28,7 +28,7 @@ pub(crate) struct FreedTableKey { pub(crate) pagination_id: u64, } -impl RedbValue for FreedTableKey { +impl Value for FreedTableKey { type SelfType<'a> = FreedTableKey where Self: 'a; @@ -129,7 +129,7 @@ impl FreedPageListMut { } } -impl RedbValue for FreedPageList<'_> { +impl Value for FreedPageList<'_> { type SelfType<'a> = FreedPageList<'a> where Self: 'a; @@ -239,7 +239,7 @@ impl InternalTableDefinition { } } -impl RedbValue for InternalTableDefinition { +impl Value for InternalTableDefinition { type SelfType<'a> = InternalTableDefinition; type AsBytes<'a> = Vec; @@ -475,7 +475,7 @@ impl TableTree { } // root_page: the root of the master table - pub(crate) fn get_table( + pub(crate) fn get_table( &self, name: &str, table_type: TableType, @@ -697,7 +697,7 @@ impl<'txn> TableTreeMut<'txn> { } // root_page: the root of the master table - pub(crate) fn get_table( + pub(crate) fn get_table( &self, name: &str, table_type: TableType, @@ -750,7 +750,7 @@ impl<'txn> TableTreeMut<'txn> { // Returns a tuple of the table id and the new root page // root_page: the root of the master table - pub(crate) fn get_or_create_table( + pub(crate) fn get_or_create_table( &mut self, name: &str, table_type: TableType, @@ -869,7 +869,7 @@ impl<'txn> TableTreeMut<'txn> { mod test { use crate::tree_store::{InternalTableDefinition, TableType}; use crate::types::TypeName; - use crate::RedbValue; + use crate::Value; #[test] fn round_trip() { diff --git a/src/tuple_types.rs b/src/tuple_types.rs index aa8dedb7..499f16b4 100644 --- a/src/tuple_types.rs +++ b/src/tuple_types.rs @@ -1,4 +1,4 @@ -use crate::types::{RedbKey, RedbValue, TypeName}; +use crate::types::{RedbKey, TypeName, Value}; use std::borrow::Borrow; use std::cmp::Ordering; use std::mem::size_of; @@ -184,7 +184,7 @@ macro_rules! compare_fixed_impl { macro_rules! tuple_impl { ( $($t:ident, $v:ident, $i:tt ),+ | $t_last:ident, $v_last:ident, $i_last:tt ) => { - impl<$($t: RedbValue,)+ $t_last: RedbValue> RedbValue for ($($t,)+ $t_last) { + impl<$($t: Value,)+ $t_last: Value> Value for ($($t,)+ $t_last) { type SelfType<'a> = ( $(<$t>::SelfType<'a>,)+ <$t_last>::SelfType<'a>, @@ -347,7 +347,7 @@ tuple_impl! { #[cfg(test)] mod test { - use crate::types::RedbValue; + use crate::types::Value; #[test] fn width() { diff --git a/src/types.rs b/src/types.rs index 86156ef9..1b65b945 100644 --- a/src/types.rs +++ b/src/types.rs @@ -70,7 +70,7 @@ impl TypeName { } } -pub trait RedbValue: Debug { +pub trait Value: Debug { /// SelfType<'a> must be the same type as Self with all lifetimes replaced with 'a type SelfType<'a>: Debug + 'a where @@ -101,7 +101,7 @@ pub trait RedbValue: Debug { /// Implementing this trait indicates that the type can be mutated in-place as a &mut [u8]. /// This enables the .insert_reserve() method on Table -pub trait MutInPlaceValue: RedbValue { +pub trait MutInPlaceValue: Value { /// The base type such that &mut [u8] can be safely transmuted to &mut BaseRefType type BaseRefType: Debug + ?Sized; @@ -124,12 +124,12 @@ impl MutInPlaceValue for &[u8] { } } -pub trait RedbKey: RedbValue { +pub trait RedbKey: Value { /// Compare data1 with data2 fn compare(data1: &[u8], data2: &[u8]) -> Ordering; } -impl RedbValue for () { +impl Value for () { type SelfType<'a> = () where Self: 'a; @@ -168,7 +168,7 @@ impl RedbKey for () { } } -impl RedbValue for bool { +impl Value for bool { type SelfType<'a> = bool where Self: 'a; @@ -215,7 +215,7 @@ impl RedbKey for bool { } } -impl RedbValue for Option { +impl Value for Option { type SelfType<'a> = Option> where Self: 'a; @@ -277,7 +277,7 @@ impl RedbKey for Option { } } -impl RedbValue for &[u8] { +impl Value for &[u8] { type SelfType<'a> = &'a [u8] where Self: 'a; @@ -315,7 +315,7 @@ impl RedbKey for &[u8] { } } -impl RedbValue for &[u8; N] { +impl Value for &[u8; N] { type SelfType<'a> = &'a [u8; N] where Self: 'a; @@ -353,7 +353,7 @@ impl RedbKey for &[u8; N] { } } -impl RedbValue for &str { +impl Value for &str { type SelfType<'a> = &'a str where Self: 'a; @@ -393,7 +393,7 @@ impl RedbKey for &str { } } -impl RedbValue for char { +impl Value for char { type SelfType<'a> = char; type AsBytes<'a> = [u8; 3] where Self: 'a; @@ -430,7 +430,7 @@ impl RedbKey for char { macro_rules! le_value { ($t:ty) => { - impl RedbValue for $t { + impl Value for $t { type SelfType<'a> = $t; type AsBytes<'a> = [u8; std::mem::size_of::<$t>()] where Self: 'a; diff --git a/tests/backward_compatibility.rs b/tests/backward_compatibility.rs index 024b162a..f3852a33 100644 --- a/tests/backward_compatibility.rs +++ b/tests/backward_compatibility.rs @@ -2,10 +2,10 @@ use redb::ReadableTable; const ELEMENTS: usize = 3; -trait TestData: redb::RedbValue + redb1::RedbValue { +trait TestData: redb::Value + redb1::RedbValue { fn gen1() -> [::SelfType<'static>; ELEMENTS]; - fn gen() -> [::SelfType<'static>; ELEMENTS]; + fn gen() -> [::SelfType<'static>; ELEMENTS]; } impl TestData for u8 { @@ -13,7 +13,7 @@ impl TestData for u8 { [0, 1, 2] } - fn gen() -> [::SelfType<'static>; ELEMENTS] { + fn gen() -> [::SelfType<'static>; ELEMENTS] { [0, 1, 2] } } @@ -23,7 +23,7 @@ impl TestData for u16 { [0, 1, 2] } - fn gen() -> [::SelfType<'static>; ELEMENTS] { + fn gen() -> [::SelfType<'static>; ELEMENTS] { [0, 1, 2] } } @@ -33,7 +33,7 @@ impl TestData for u32 { [0, 1, 2] } - fn gen() -> [::SelfType<'static>; ELEMENTS] { + fn gen() -> [::SelfType<'static>; ELEMENTS] { [0, 1, 2] } } @@ -43,7 +43,7 @@ impl TestData for u64 { [0, 1, 2] } - fn gen() -> [::SelfType<'static>; ELEMENTS] { + fn gen() -> [::SelfType<'static>; ELEMENTS] { [0, 1, 2] } } @@ -53,7 +53,7 @@ impl TestData for u128 { [0, 1, 2] } - fn gen() -> [::SelfType<'static>; ELEMENTS] { + fn gen() -> [::SelfType<'static>; ELEMENTS] { [0, 1, 2] } } @@ -63,7 +63,7 @@ impl TestData for i8 { [-1, 1, 2] } - fn gen() -> [::SelfType<'static>; ELEMENTS] { + fn gen() -> [::SelfType<'static>; ELEMENTS] { [-1, 1, 2] } } @@ -73,7 +73,7 @@ impl TestData for i16 { [-1, 1, 2] } - fn gen() -> [::SelfType<'static>; ELEMENTS] { + fn gen() -> [::SelfType<'static>; ELEMENTS] { [-1, 1, 2] } } @@ -83,7 +83,7 @@ impl TestData for i32 { [-1, 1, 2] } - fn gen() -> [::SelfType<'static>; ELEMENTS] { + fn gen() -> [::SelfType<'static>; ELEMENTS] { [-1, 1, 2] } } @@ -93,7 +93,7 @@ impl TestData for i64 { [-1, 1, 2] } - fn gen() -> [::SelfType<'static>; ELEMENTS] { + fn gen() -> [::SelfType<'static>; ELEMENTS] { [-1, 1, 2] } } @@ -103,7 +103,7 @@ impl TestData for i128 { [-1, 1, 2] } - fn gen() -> [::SelfType<'static>; ELEMENTS] { + fn gen() -> [::SelfType<'static>; ELEMENTS] { [-1, 1, 2] } } @@ -113,7 +113,7 @@ impl TestData for f32 { [f32::NAN, f32::INFINITY, f32::MIN_POSITIVE] } - fn gen() -> [::SelfType<'static>; ELEMENTS] { + fn gen() -> [::SelfType<'static>; ELEMENTS] { [f32::NAN, f32::INFINITY, f32::MIN_POSITIVE] } } @@ -123,7 +123,7 @@ impl TestData for f64 { [f64::MIN, f64::NEG_INFINITY, f64::MAX] } - fn gen() -> [::SelfType<'static>; ELEMENTS] { + fn gen() -> [::SelfType<'static>; ELEMENTS] { [f64::MIN, f64::NEG_INFINITY, f64::MAX] } } @@ -133,7 +133,7 @@ impl TestData for () { [(), (), ()] } - fn gen() -> [::SelfType<'static>; ELEMENTS] { + fn gen() -> [::SelfType<'static>; ELEMENTS] { [(), (), ()] } } @@ -143,7 +143,7 @@ impl TestData for &'static str { ["hello", "world1", "hi"] } - fn gen() -> [::SelfType<'static>; ELEMENTS] { + fn gen() -> [::SelfType<'static>; ELEMENTS] { ["hello", "world1", "hi"] } } @@ -153,7 +153,7 @@ impl TestData for &'static [u8] { [b"test", b"bytes", b"now"] } - fn gen() -> [::SelfType<'static>; ELEMENTS] { + fn gen() -> [::SelfType<'static>; ELEMENTS] { [b"test", b"bytes", b"now"] } } @@ -163,7 +163,7 @@ impl TestData for &'static [u8; 5] { [b"test1", b"bytes", b"now12"] } - fn gen() -> [::SelfType<'static>; ELEMENTS] { + fn gen() -> [::SelfType<'static>; ELEMENTS] { [b"test1", b"bytes", b"now12"] } } @@ -173,7 +173,7 @@ impl TestData for Option { [None, Some(0), Some(7)] } - fn gen() -> [::SelfType<'static>; ELEMENTS] { + fn gen() -> [::SelfType<'static>; ELEMENTS] { [None, Some(0), Some(7)] } } @@ -183,7 +183,7 @@ impl TestData for (u64, &'static str) { [(0, "hi"), (1, "bye"), (2, "byte")] } - fn gen() -> [::SelfType<'static>; ELEMENTS] { + fn gen() -> [::SelfType<'static>; ELEMENTS] { [(0, "hi"), (1, "bye"), (2, "byte")] } } @@ -218,9 +218,9 @@ fn test_helper::as_bytes(&value); + let bytes = ::as_bytes(&value); let expected = &V::gen()[i]; - let expected_bytes = ::as_bytes(expected); + let expected_bytes = ::as_bytes(expected); assert_eq!(bytes.as_ref(), expected_bytes.as_ref()); } } diff --git a/tests/basic_tests.rs b/tests/basic_tests.rs index 2908b514..b622a78e 100644 --- a/tests/basic_tests.rs +++ b/tests/basic_tests.rs @@ -1,7 +1,7 @@ use redb::backends::InMemoryBackend; use redb::{ Database, MultimapTableDefinition, MultimapTableHandle, Range, ReadableTable, RedbKey, - RedbValue, TableDefinition, TableError, TableHandle, TypeName, + TableDefinition, TableError, TableHandle, TypeName, Value, }; use std::cmp::Ordering; #[cfg(not(target_os = "wasi"))] @@ -1346,7 +1346,7 @@ fn custom_ordering() { #[derive(Debug)] struct ReverseKey(Vec); - impl RedbValue for ReverseKey { + impl Value for ReverseKey { type SelfType<'a> = ReverseKey where Self: 'a; From 7b05023dfb9ae88b466d245deee3d8882034e978 Mon Sep 17 00:00:00 2001 From: Christopher Berner Date: Sat, 3 Feb 2024 10:09:12 -0800 Subject: [PATCH 2/2] Rename RedbKey to Key --- examples/special_values.rs | 8 ++--- src/db.rs | 30 +++++++++--------- src/lib.rs | 2 +- src/multimap_table.rs | 48 ++++++++++++++-------------- src/table.rs | 56 ++++++++++++++++----------------- src/transaction_tracker.rs | 4 +-- src/transactions.rs | 44 +++++++++++++------------- src/tree_store/btree.rs | 12 +++---- src/tree_store/btree_base.rs | 12 +++---- src/tree_store/btree_iters.rs | 42 ++++++++++++------------- src/tree_store/btree_mutator.rs | 6 ++-- src/tree_store/table_tree.rs | 10 +++--- src/tuple_types.rs | 6 ++-- src/types.rs | 18 +++++------ tests/backward_compatibility.rs | 2 +- tests/basic_tests.rs | 8 ++--- 16 files changed, 153 insertions(+), 155 deletions(-) diff --git a/examples/special_values.rs b/examples/special_values.rs index f925b584..9b5a1092 100644 --- a/examples/special_values.rs +++ b/examples/special_values.rs @@ -1,5 +1,5 @@ use redb::{ - Database, Error, ReadableTable, RedbKey, Table, TableDefinition, TableHandle, Value, + Database, Error, Key, ReadableTable, Table, TableDefinition, TableHandle, Value, WriteTransaction, }; use std::fs::{File, OpenOptions}; @@ -40,7 +40,7 @@ struct SpecialValuesTransaction<'db> { } impl<'db> SpecialValuesTransaction<'db> { - fn open_table( + fn open_table( &mut self, table: TableDefinition, ) -> SpecialValuesTable { @@ -58,13 +58,13 @@ impl<'db> SpecialValuesTransaction<'db> { } } -struct SpecialValuesTable<'txn, K: RedbKey + 'static, V: Value + 'static> { +struct SpecialValuesTable<'txn, K: Key + 'static, V: Value + 'static> { inner: Table<'txn, K, (u64, u64)>, file: &'txn mut File, _value_type: PhantomData, } -impl<'txn, K: RedbKey + 'static, V: Value + 'static> SpecialValuesTable<'txn, K, V> { +impl<'txn, K: Key + 'static, V: Value + 'static> SpecialValuesTable<'txn, K, V> { fn insert(&mut self, key: K::SelfType<'_>, value: V::SelfType<'_>) { // Append to end of file let offset = self.file.seek(SeekFrom::End(0)).unwrap(); diff --git a/src/db.rs b/src/db.rs index c21e939e..924d297f 100644 --- a/src/db.rs +++ b/src/db.rs @@ -4,7 +4,7 @@ use crate::tree_store::{ InternalTableDefinition, PageHint, PageNumber, RawBtree, SerializedSavepoint, TableTreeMut, TableType, TransactionalMemory, PAGE_SIZE, }; -use crate::types::{RedbKey, Value}; +use crate::types::{Key, Value}; use crate::{ CompactionError, DatabaseError, Durability, ReadOnlyTable, SavepointError, StorageError, }; @@ -108,13 +108,13 @@ impl Sealed for UntypedMultimapTableHandle {} /// /// Note that the lifetime of the `K` and `V` type parameters does not impact the lifetimes of the data /// that is stored or retreived from the table -pub struct TableDefinition<'a, K: RedbKey + 'static, V: Value + 'static> { +pub struct TableDefinition<'a, K: Key + 'static, V: Value + 'static> { name: &'a str, _key_type: PhantomData, _value_type: PhantomData, } -impl<'a, K: RedbKey + 'static, V: Value + 'static> TableDefinition<'a, K, V> { +impl<'a, K: Key + 'static, V: Value + 'static> TableDefinition<'a, K, V> { /// Construct a new table with given `name` /// /// ## Invariant @@ -130,23 +130,23 @@ impl<'a, K: RedbKey + 'static, V: Value + 'static> TableDefinition<'a, K, V> { } } -impl<'a, K: RedbKey + 'static, V: Value + 'static> TableHandle for TableDefinition<'a, K, V> { +impl<'a, K: Key + 'static, V: Value + 'static> TableHandle for TableDefinition<'a, K, V> { fn name(&self) -> &str { self.name } } -impl Sealed for TableDefinition<'_, K, V> {} +impl Sealed for TableDefinition<'_, K, V> {} -impl<'a, K: RedbKey + 'static, V: Value + 'static> Clone for TableDefinition<'a, K, V> { +impl<'a, K: Key + 'static, V: Value + 'static> Clone for TableDefinition<'a, K, V> { fn clone(&self) -> Self { *self } } -impl<'a, K: RedbKey + 'static, V: Value + 'static> Copy for TableDefinition<'a, K, V> {} +impl<'a, K: Key + 'static, V: Value + 'static> Copy for TableDefinition<'a, K, V> {} -impl<'a, K: RedbKey + 'static, V: Value + 'static> Display for TableDefinition<'a, K, V> { +impl<'a, K: Key + 'static, V: Value + 'static> Display for TableDefinition<'a, K, V> { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { write!( f, @@ -166,13 +166,13 @@ impl<'a, K: RedbKey + 'static, V: Value + 'static> Display for TableDefinition<' /// /// Note that the lifetime of the `K` and `V` type parameters does not impact the lifetimes of the data /// that is stored or retreived from the table -pub struct MultimapTableDefinition<'a, K: RedbKey + 'static, V: RedbKey + 'static> { +pub struct MultimapTableDefinition<'a, K: Key + 'static, V: Key + 'static> { name: &'a str, _key_type: PhantomData, _value_type: PhantomData, } -impl<'a, K: RedbKey + 'static, V: RedbKey + 'static> MultimapTableDefinition<'a, K, V> { +impl<'a, K: Key + 'static, V: Key + 'static> MultimapTableDefinition<'a, K, V> { pub const fn new(name: &'a str) -> Self { assert!(!name.is_empty()); Self { @@ -183,7 +183,7 @@ impl<'a, K: RedbKey + 'static, V: RedbKey + 'static> MultimapTableDefinition<'a, } } -impl<'a, K: RedbKey + 'static, V: RedbKey + 'static> MultimapTableHandle +impl<'a, K: Key + 'static, V: Key + 'static> MultimapTableHandle for MultimapTableDefinition<'a, K, V> { fn name(&self) -> &str { @@ -191,17 +191,17 @@ impl<'a, K: RedbKey + 'static, V: RedbKey + 'static> MultimapTableHandle } } -impl Sealed for MultimapTableDefinition<'_, K, V> {} +impl Sealed for MultimapTableDefinition<'_, K, V> {} -impl<'a, K: RedbKey + 'static, V: RedbKey + 'static> Clone for MultimapTableDefinition<'a, K, V> { +impl<'a, K: Key + 'static, V: Key + 'static> Clone for MultimapTableDefinition<'a, K, V> { fn clone(&self) -> Self { *self } } -impl<'a, K: RedbKey + 'static, V: RedbKey + 'static> Copy for MultimapTableDefinition<'a, K, V> {} +impl<'a, K: Key + 'static, V: Key + 'static> Copy for MultimapTableDefinition<'a, K, V> {} -impl<'a, K: RedbKey + 'static, V: RedbKey + 'static> Display for MultimapTableDefinition<'a, K, V> { +impl<'a, K: Key + 'static, V: Key + 'static> Display for MultimapTableDefinition<'a, K, V> { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { write!( f, diff --git a/src/lib.rs b/src/lib.rs index 49f9863c..65543649 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -71,7 +71,7 @@ pub use table::{ }; pub use transactions::{DatabaseStats, Durability, ReadTransaction, WriteTransaction}; pub use tree_store::{AccessGuard, AccessGuardMut, Savepoint}; -pub use types::{MutInPlaceValue, RedbKey, TypeName, Value}; +pub use types::{Key, MutInPlaceValue, TypeName, Value}; type Result = std::result::Result; diff --git a/src/multimap_table.rs b/src/multimap_table.rs index e9ab9982..cbb824d5 100644 --- a/src/multimap_table.rs +++ b/src/multimap_table.rs @@ -7,7 +7,7 @@ use crate::tree_store::{ BtreeStats, CachePriority, Checksum, LeafAccessor, LeafMutator, Page, PageHint, PageNumber, RawBtree, RawLeafBuilder, TransactionalMemory, UntypedBtreeMut, BRANCH, LEAF, MAX_VALUE_LENGTH, }; -use crate::types::{RedbKey, TypeName, Value}; +use crate::types::{Key, TypeName, Value}; use crate::{AccessGuard, MultimapTableHandle, Result, StorageError, WriteTransaction}; use std::borrow::Borrow; use std::cmp::max; @@ -475,7 +475,7 @@ impl DynamicCollection { } } -impl DynamicCollection { +impl DynamicCollection { fn iter<'a>( collection: AccessGuard<'a, &'static DynamicCollection>, guard: Arc, @@ -555,12 +555,12 @@ impl UntypedDynamicCollection { } } -enum ValueIterState<'a, V: RedbKey + 'static> { +enum ValueIterState<'a, V: Key + 'static> { Subtree(BtreeRangeIter), InlineLeaf(LeafKeyIter<'a, V>), } -pub struct MultimapValue<'a, V: RedbKey + 'static> { +pub struct MultimapValue<'a, V: Key + 'static> { inner: Option>, freed_pages: Option>>>, free_on_drop: Vec, @@ -569,7 +569,7 @@ pub struct MultimapValue<'a, V: RedbKey + 'static> { _value_type: PhantomData, } -impl<'a, V: RedbKey + 'static> MultimapValue<'a, V> { +impl<'a, V: Key + 'static> MultimapValue<'a, V> { fn new_subtree(inner: BtreeRangeIter, guard: Arc) -> Self { Self { inner: Some(ValueIterState::Subtree(inner)), @@ -610,7 +610,7 @@ impl<'a, V: RedbKey + 'static> MultimapValue<'a, V> { } } -impl<'a, V: RedbKey + 'static> Iterator for MultimapValue<'a, V> { +impl<'a, V: Key + 'static> Iterator for MultimapValue<'a, V> { type Item = Result>; fn next(&mut self) -> Option { @@ -628,7 +628,7 @@ impl<'a, V: RedbKey + 'static> Iterator for MultimapValue<'a, V> { } } -impl<'a, V: RedbKey + 'static> DoubleEndedIterator for MultimapValue<'a, V> { +impl<'a, V: Key + 'static> DoubleEndedIterator for MultimapValue<'a, V> { fn next_back(&mut self) -> Option { // TODO: optimize out this copy let bytes = match self.inner.as_mut().unwrap() { @@ -644,7 +644,7 @@ impl<'a, V: RedbKey + 'static> DoubleEndedIterator for MultimapValue<'a, V> { } } -impl<'a, V: RedbKey + 'static> Drop for MultimapValue<'a, V> { +impl<'a, V: Key + 'static> Drop for MultimapValue<'a, V> { fn drop(&mut self) { // Drop our references to the pages that are about to be freed drop(mem::take(&mut self.inner)); @@ -659,7 +659,7 @@ impl<'a, V: RedbKey + 'static> Drop for MultimapValue<'a, V> { } } -pub struct MultimapRange<'a, K: RedbKey + 'static, V: RedbKey + 'static> { +pub struct MultimapRange<'a, K: Key + 'static, V: Key + 'static> { inner: BtreeRangeIter>, mem: Arc, transaction_guard: Arc, @@ -668,7 +668,7 @@ pub struct MultimapRange<'a, K: RedbKey + 'static, V: RedbKey + 'static> { _lifetime: PhantomData<&'a ()>, } -impl<'a, K: RedbKey + 'static, V: RedbKey + 'static> MultimapRange<'a, K, V> { +impl<'a, K: Key + 'static, V: Key + 'static> MultimapRange<'a, K, V> { fn new( inner: BtreeRangeIter>, guard: Arc, @@ -685,7 +685,7 @@ impl<'a, K: RedbKey + 'static, V: RedbKey + 'static> MultimapRange<'a, K, V> { } } -impl<'a, K: RedbKey + 'static, V: RedbKey + 'static> Iterator for MultimapRange<'a, K, V> { +impl<'a, K: Key + 'static, V: Key + 'static> Iterator for MultimapRange<'a, K, V> { type Item = Result<(AccessGuard<'a, K>, MultimapValue<'a, V>)>; fn next(&mut self) -> Option { @@ -708,9 +708,7 @@ impl<'a, K: RedbKey + 'static, V: RedbKey + 'static> Iterator for MultimapRange< } } -impl<'a, K: RedbKey + 'static, V: RedbKey + 'static> DoubleEndedIterator - for MultimapRange<'a, K, V> -{ +impl<'a, K: Key + 'static, V: Key + 'static> DoubleEndedIterator for MultimapRange<'a, K, V> { fn next_back(&mut self) -> Option { match self.inner.next_back()? { Ok(entry) => { @@ -734,7 +732,7 @@ impl<'a, K: RedbKey + 'static, V: RedbKey + 'static> DoubleEndedIterator /// A multimap table /// /// [Multimap tables](https://en.wikipedia.org/wiki/Multimap) may have multiple values associated with each key -pub struct MultimapTable<'txn, K: RedbKey + 'static, V: RedbKey + 'static> { +pub struct MultimapTable<'txn, K: Key + 'static, V: Key + 'static> { name: String, transaction: &'txn WriteTransaction, freed_pages: Arc>>, @@ -743,13 +741,13 @@ pub struct MultimapTable<'txn, K: RedbKey + 'static, V: RedbKey + 'static> { _value_type: PhantomData, } -impl MultimapTableHandle for MultimapTable<'_, K, V> { +impl MultimapTableHandle for MultimapTable<'_, K, V> { fn name(&self) -> &str { &self.name } } -impl<'txn, K: RedbKey + 'static, V: RedbKey + 'static> MultimapTable<'txn, K, V> { +impl<'txn, K: Key + 'static, V: Key + 'static> MultimapTable<'txn, K, V> { pub(crate) fn new( name: &str, table_root: Option<(PageNumber, Checksum)>, @@ -1101,7 +1099,7 @@ impl<'txn, K: RedbKey + 'static, V: RedbKey + 'static> MultimapTable<'txn, K, V> } } -impl<'txn, K: RedbKey + 'static, V: RedbKey + 'static> ReadableMultimapTable +impl<'txn, K: Key + 'static, V: Key + 'static> ReadableMultimapTable for MultimapTable<'txn, K, V> { /// Returns an iterator over all values for the given key. Values are in ascending order. @@ -1173,15 +1171,15 @@ impl<'txn, K: RedbKey + 'static, V: RedbKey + 'static> ReadableMultimapTable Sealed for MultimapTable<'_, K, V> {} +impl Sealed for MultimapTable<'_, K, V> {} -impl<'txn, K: RedbKey + 'static, V: RedbKey + 'static> Drop for MultimapTable<'txn, K, V> { +impl<'txn, K: Key + 'static, V: Key + 'static> Drop for MultimapTable<'txn, K, V> { fn drop(&mut self) { self.transaction.close_table(&self.name, &self.tree); } } -pub trait ReadableMultimapTable: Sealed { +pub trait ReadableMultimapTable: Sealed { /// Returns an iterator over all values for the given key. Values are in ascending order. fn get<'a>(&self, key: impl Borrow>) -> Result> where @@ -1255,14 +1253,14 @@ impl ReadOnlyUntypedMultimapTable { } /// A read-only multimap table -pub struct ReadOnlyMultimapTable { +pub struct ReadOnlyMultimapTable { tree: Btree>, mem: Arc, transaction_guard: Arc, _value_type: PhantomData, } -impl ReadOnlyMultimapTable { +impl ReadOnlyMultimapTable { pub(crate) fn new( root_page: Option<(PageNumber, Checksum)>, hint: PageHint, @@ -1307,7 +1305,7 @@ impl ReadOnlyMultimapTable { } } -impl ReadableMultimapTable +impl ReadableMultimapTable for ReadOnlyMultimapTable { /// Returns an iterator over all values for the given key. Values are in ascending order. @@ -1375,4 +1373,4 @@ impl ReadableMultimapTable } } -impl Sealed for ReadOnlyMultimapTable {} +impl Sealed for ReadOnlyMultimapTable {} diff --git a/src/table.rs b/src/table.rs index 25ad414f..0d243d17 100644 --- a/src/table.rs +++ b/src/table.rs @@ -4,7 +4,7 @@ use crate::tree_store::{ AccessGuardMut, Btree, BtreeDrain, BtreeDrainFilter, BtreeMut, BtreeRangeIter, Checksum, PageHint, PageNumber, RawBtree, TransactionalMemory, MAX_VALUE_LENGTH, }; -use crate::types::{MutInPlaceValue, RedbKey, Value}; +use crate::types::{Key, MutInPlaceValue, Value}; use crate::{AccessGuard, StorageError, WriteTransaction}; use crate::{Result, TableHandle}; use std::borrow::Borrow; @@ -58,19 +58,19 @@ impl TableStats { } /// A table containing key-value mappings -pub struct Table<'txn, K: RedbKey + 'static, V: Value + 'static> { +pub struct Table<'txn, K: Key + 'static, V: Value + 'static> { name: String, transaction: &'txn WriteTransaction, tree: BtreeMut<'txn, K, V>, } -impl TableHandle for Table<'_, K, V> { +impl TableHandle for Table<'_, K, V> { fn name(&self) -> &str { &self.name } } -impl<'txn, K: RedbKey + 'static, V: Value + 'static> Table<'txn, K, V> { +impl<'txn, K: Key + 'static, V: Value + 'static> Table<'txn, K, V> { pub(crate) fn new( name: &str, table_root: Option<(PageNumber, Checksum)>, @@ -193,7 +193,7 @@ impl<'txn, K: RedbKey + 'static, V: Value + 'static> Table<'txn, K, V> { } } -impl<'txn, K: RedbKey + 'static, V: MutInPlaceValue + 'static> Table<'txn, K, V> { +impl<'txn, K: Key + 'static, V: MutInPlaceValue + 'static> Table<'txn, K, V> { /// Reserve space to insert a key-value pair /// The returned reference will have length equal to value_length pub fn insert_reserve<'a>( @@ -215,7 +215,7 @@ impl<'txn, K: RedbKey + 'static, V: MutInPlaceValue + 'static> Table<'txn, K, V> } } -impl<'txn, K: RedbKey + 'static, V: Value + 'static> ReadableTable for Table<'txn, K, V> { +impl<'txn, K: Key + 'static, V: Value + 'static> ReadableTable for Table<'txn, K, V> { fn get<'a>(&self, key: impl Borrow>) -> Result>> where K: 'a, @@ -255,15 +255,15 @@ impl<'txn, K: RedbKey + 'static, V: Value + 'static> ReadableTable for Tab } } -impl Sealed for Table<'_, K, V> {} +impl Sealed for Table<'_, K, V> {} -impl<'txn, K: RedbKey + 'static, V: Value + 'static> Drop for Table<'txn, K, V> { +impl<'txn, K: Key + 'static, V: Value + 'static> Drop for Table<'txn, K, V> { fn drop(&mut self) { self.transaction.close_table(&self.name, &self.tree); } } -fn debug_helper( +fn debug_helper( f: &mut Formatter<'_>, name: &str, len: Result, @@ -306,13 +306,13 @@ fn debug_helper( Ok(()) } -impl Debug for Table<'_, K, V> { +impl Debug for Table<'_, K, V> { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { debug_helper(f, &self.name, self.len(), self.first(), self.last()) } } -pub trait ReadableTable: Sealed { +pub trait ReadableTable: Sealed { /// Returns the value corresponding to the given key fn get<'a>(&self, key: impl Borrow>) -> Result>> where @@ -413,13 +413,13 @@ impl ReadOnlyUntypedTable { } /// A read-only table -pub struct ReadOnlyTable { +pub struct ReadOnlyTable { name: String, tree: Btree, transaction_guard: Arc, } -impl ReadOnlyTable { +impl ReadOnlyTable { pub(crate) fn new( name: String, root_page: Option<(PageNumber, Checksum)>, @@ -446,7 +446,7 @@ impl ReadOnlyTable { } } -impl ReadableTable for ReadOnlyTable { +impl ReadableTable for ReadOnlyTable { fn get<'a>(&self, key: impl Borrow>) -> Result>> where K: 'a, @@ -486,20 +486,20 @@ impl ReadableTable for ReadOnlyT } } -impl Sealed for ReadOnlyTable {} +impl Sealed for ReadOnlyTable {} -impl Debug for ReadOnlyTable { +impl Debug for ReadOnlyTable { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { debug_helper(f, &self.name, self.len(), self.first(), self.last()) } } -pub struct Drain<'a, K: RedbKey + 'static, V: Value + 'static> { +pub struct Drain<'a, K: Key + 'static, V: Value + 'static> { inner: BtreeDrain, _lifetime: PhantomData<&'a ()>, } -impl<'a, K: RedbKey + 'static, V: Value + 'static> Drain<'a, K, V> { +impl<'a, K: Key + 'static, V: Value + 'static> Drain<'a, K, V> { fn new(inner: BtreeDrain) -> Self { Self { inner, @@ -508,7 +508,7 @@ impl<'a, K: RedbKey + 'static, V: Value + 'static> Drain<'a, K, V> { } } -impl<'a, K: RedbKey + 'static, V: Value + 'static> Iterator for Drain<'a, K, V> { +impl<'a, K: Key + 'static, V: Value + 'static> Iterator for Drain<'a, K, V> { type Item = Result<(AccessGuard<'a, K>, AccessGuard<'a, V>)>; fn next(&mut self) -> Option { @@ -522,7 +522,7 @@ impl<'a, K: RedbKey + 'static, V: Value + 'static> Iterator for Drain<'a, K, V> } } -impl<'a, K: RedbKey + 'static, V: Value + 'static> DoubleEndedIterator for Drain<'a, K, V> { +impl<'a, K: Key + 'static, V: Value + 'static> DoubleEndedIterator for Drain<'a, K, V> { fn next_back(&mut self) -> Option { let entry = self.inner.next_back()?; Some(entry.map(|entry| { @@ -536,7 +536,7 @@ impl<'a, K: RedbKey + 'static, V: Value + 'static> DoubleEndedIterator for Drain pub struct DrainFilter< 'a, - K: RedbKey + 'static, + K: Key + 'static, V: Value + 'static, F: for<'f> FnMut(K::SelfType<'f>, V::SelfType<'f>) -> bool, > { @@ -546,7 +546,7 @@ pub struct DrainFilter< impl< 'a, - K: RedbKey + 'static, + K: Key + 'static, V: Value + 'static, F: for<'f> FnMut(K::SelfType<'f>, V::SelfType<'f>) -> bool, > DrainFilter<'a, K, V, F> @@ -561,7 +561,7 @@ impl< impl< 'a, - K: RedbKey + 'static, + K: Key + 'static, V: Value + 'static, F: for<'f> FnMut(K::SelfType<'f>, V::SelfType<'f>) -> bool, > Iterator for DrainFilter<'a, K, V, F> @@ -581,7 +581,7 @@ impl< impl< 'a, - K: RedbKey + 'static, + K: Key + 'static, V: Value + 'static, F: for<'f> FnMut(K::SelfType<'f>, V::SelfType<'f>) -> bool, > DoubleEndedIterator for DrainFilter<'a, K, V, F> @@ -598,14 +598,14 @@ impl< } #[derive(Clone)] -pub struct Range<'a, K: RedbKey + 'static, V: Value + 'static> { +pub struct Range<'a, K: Key + 'static, V: Value + 'static> { inner: BtreeRangeIter, _transaction_guard: Arc, // TODO: replace with TransactionGuard? _lifetime: PhantomData<&'a ()>, } -impl<'a, K: RedbKey + 'static, V: Value + 'static> Range<'a, K, V> { +impl<'a, K: Key + 'static, V: Value + 'static> Range<'a, K, V> { pub(super) fn new(inner: BtreeRangeIter, guard: Arc) -> Self { Self { inner, @@ -615,7 +615,7 @@ impl<'a, K: RedbKey + 'static, V: Value + 'static> Range<'a, K, V> { } } -impl<'a, K: RedbKey + 'static, V: Value + 'static> Iterator for Range<'a, K, V> { +impl<'a, K: Key + 'static, V: Value + 'static> Iterator for Range<'a, K, V> { type Item = Result<(AccessGuard<'a, K>, AccessGuard<'a, V>)>; fn next(&mut self) -> Option { @@ -630,7 +630,7 @@ impl<'a, K: RedbKey + 'static, V: Value + 'static> Iterator for Range<'a, K, V> } } -impl<'a, K: RedbKey + 'static, V: Value + 'static> DoubleEndedIterator for Range<'a, K, V> { +impl<'a, K: Key + 'static, V: Value + 'static> DoubleEndedIterator for Range<'a, K, V> { fn next_back(&mut self) -> Option { self.inner.next_back().map(|x| { x.map(|entry| { diff --git a/src/transaction_tracker.rs b/src/transaction_tracker.rs index ea5fde24..7dc2dd9c 100644 --- a/src/transaction_tracker.rs +++ b/src/transaction_tracker.rs @@ -1,5 +1,5 @@ use crate::tree_store::TransactionalMemory; -use crate::{RedbKey, Result, Savepoint, TypeName, Value}; +use crate::{Key, Result, Savepoint, TypeName, Value}; #[cfg(feature = "logging")] use log::info; use std::cmp::Ordering; @@ -76,7 +76,7 @@ impl Value for SavepointId { } } -impl RedbKey for SavepointId { +impl Key for SavepointId { fn compare(data1: &[u8], data2: &[u8]) -> Ordering { Self::from_bytes(data1).0.cmp(&Self::from_bytes(data2).0) } diff --git a/src/transactions.rs b/src/transactions.rs index 1d81d906..dd8915d0 100644 --- a/src/transactions.rs +++ b/src/transactions.rs @@ -9,7 +9,7 @@ use crate::tree_store::{ PageNumber, SerializedSavepoint, TableTree, TableTreeMut, TableType, TransactionalMemory, MAX_VALUE_LENGTH, }; -use crate::types::{RedbKey, Value}; +use crate::types::{Key, Value}; use crate::{ AccessGuard, MultimapTable, MultimapTableDefinition, MultimapTableHandle, Range, ReadOnlyMultimapTable, ReadOnlyTable, Result, Savepoint, SavepointError, StorageError, Table, @@ -33,13 +33,13 @@ const NEXT_SAVEPOINT_TABLE: SystemTableDefinition<(), SavepointId> = pub(crate) const SAVEPOINT_TABLE: SystemTableDefinition = SystemTableDefinition::new("persistent_savepoints"); -pub struct SystemTableDefinition<'a, K: RedbKey + 'static, V: Value + 'static> { +pub struct SystemTableDefinition<'a, K: Key + 'static, V: Value + 'static> { name: &'a str, _key_type: PhantomData, _value_type: PhantomData, } -impl<'a, K: RedbKey + 'static, V: Value + 'static> SystemTableDefinition<'a, K, V> { +impl<'a, K: Key + 'static, V: Value + 'static> SystemTableDefinition<'a, K, V> { pub const fn new(name: &'a str) -> Self { assert!(!name.is_empty()); Self { @@ -50,23 +50,23 @@ impl<'a, K: RedbKey + 'static, V: Value + 'static> SystemTableDefinition<'a, K, } } -impl<'a, K: RedbKey + 'static, V: Value + 'static> TableHandle for SystemTableDefinition<'a, K, V> { +impl<'a, K: Key + 'static, V: Value + 'static> TableHandle for SystemTableDefinition<'a, K, V> { fn name(&self) -> &str { self.name } } -impl Sealed for SystemTableDefinition<'_, K, V> {} +impl Sealed for SystemTableDefinition<'_, K, V> {} -impl<'a, K: RedbKey + 'static, V: Value + 'static> Clone for SystemTableDefinition<'a, K, V> { +impl<'a, K: Key + 'static, V: Value + 'static> Clone for SystemTableDefinition<'a, K, V> { fn clone(&self) -> Self { *self } } -impl<'a, K: RedbKey + 'static, V: Value + 'static> Copy for SystemTableDefinition<'a, K, V> {} +impl<'a, K: Key + 'static, V: Value + 'static> Copy for SystemTableDefinition<'a, K, V> {} -impl<'a, K: RedbKey + 'static, V: Value + 'static> Display for SystemTableDefinition<'a, K, V> { +impl<'a, K: Key + 'static, V: Value + 'static> Display for SystemTableDefinition<'a, K, V> { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { write!( f, @@ -190,14 +190,14 @@ pub enum Durability { } // Like a Table but only one may be open at a time to avoid possible races -pub struct SystemTable<'db, 's, K: RedbKey + 'static, V: Value + 'static> { +pub struct SystemTable<'db, 's, K: Key + 'static, V: Value + 'static> { name: String, namespace: &'s mut SystemNamespace<'db>, tree: BtreeMut<'s, K, V>, transaction_guard: Arc, } -impl<'db, 's, K: RedbKey + 'static, V: Value + 'static> SystemTable<'db, 's, K, V> { +impl<'db, 's, K: Key + 'static, V: Value + 'static> SystemTable<'db, 's, K, V> { fn new( name: &str, table_root: Option<(PageNumber, Checksum)>, @@ -258,7 +258,7 @@ impl<'db, 's, K: RedbKey + 'static, V: Value + 'static> SystemTable<'db, 's, K, } } -impl<'db, 's, K: RedbKey + 'static, V: Value + 'static> Drop for SystemTable<'db, 's, K, V> { +impl<'db, 's, K: Key + 'static, V: Value + 'static> Drop for SystemTable<'db, 's, K, V> { fn drop(&mut self) { self.namespace.close_table(&self.name, &self.tree); } @@ -270,7 +270,7 @@ struct SystemNamespace<'db> { } impl<'db> SystemNamespace<'db> { - fn open_system_table<'txn, 's, K: RedbKey + 'static, V: Value + 'static>( + fn open_system_table<'txn, 's, K: Key + 'static, V: Value + 'static>( &'s mut self, transaction: &'txn WriteTransaction, definition: SystemTableDefinition, @@ -295,7 +295,7 @@ impl<'db> SystemNamespace<'db> { )) } - fn close_table( + fn close_table( &mut self, name: &str, table: &BtreeMut, @@ -312,7 +312,7 @@ struct TableNamespace<'db> { impl<'db> TableNamespace<'db> { #[track_caller] - fn inner_open( + fn inner_open( &mut self, name: &str, table_type: TableType, @@ -331,7 +331,7 @@ impl<'db> TableNamespace<'db> { } #[track_caller] - pub fn open_multimap_table<'txn, K: RedbKey + 'static, V: RedbKey + 'static>( + pub fn open_multimap_table<'txn, K: Key + 'static, V: Key + 'static>( &mut self, transaction: &'txn WriteTransaction, definition: MultimapTableDefinition, @@ -351,7 +351,7 @@ impl<'db> TableNamespace<'db> { } #[track_caller] - pub fn open_table<'txn, K: RedbKey + 'static, V: Value + 'static>( + pub fn open_table<'txn, K: Key + 'static, V: Value + 'static>( &mut self, transaction: &'txn WriteTransaction, definition: TableDefinition, @@ -403,7 +403,7 @@ impl<'db> TableNamespace<'db> { self.inner_delete(name, TableType::Multimap) } - pub(crate) fn close_table( + pub(crate) fn close_table( &mut self, name: &str, table: &BtreeMut, @@ -784,7 +784,7 @@ impl WriteTransaction { /// /// The table will be created if it does not exist #[track_caller] - pub fn open_table<'txn, K: RedbKey + 'static, V: Value + 'static>( + pub fn open_table<'txn, K: Key + 'static, V: Value + 'static>( &'txn self, definition: TableDefinition, ) -> Result, TableError> { @@ -795,7 +795,7 @@ impl WriteTransaction { /// /// The table will be created if it does not exist #[track_caller] - pub fn open_multimap_table<'txn, K: RedbKey + 'static, V: RedbKey + 'static>( + pub fn open_multimap_table<'txn, K: Key + 'static, V: Key + 'static>( &'txn self, definition: MultimapTableDefinition, ) -> Result, TableError> { @@ -805,7 +805,7 @@ impl WriteTransaction { .open_multimap_table(self, definition) } - pub(crate) fn close_table( + pub(crate) fn close_table( &self, name: &str, table: &BtreeMut, @@ -1200,7 +1200,7 @@ impl ReadTransaction { } /// Open the given table - pub fn open_table( + pub fn open_table( &self, definition: TableDefinition, ) -> Result, TableError> { @@ -1237,7 +1237,7 @@ impl ReadTransaction { } /// Open the given table - pub fn open_multimap_table( + pub fn open_multimap_table( &self, definition: MultimapTableDefinition, ) -> Result, TableError> { diff --git a/src/tree_store/btree.rs b/src/tree_store/btree.rs index 6ba729c8..17ae9501 100644 --- a/src/tree_store/btree.rs +++ b/src/tree_store/btree.rs @@ -9,7 +9,7 @@ use crate::tree_store::page_store::{CachePriority, Page, PageImpl, PageMut, Tran use crate::tree_store::{ AccessGuardMut, AllPageNumbersBtreeIter, BtreeDrainFilter, BtreeRangeIter, PageHint, PageNumber, }; -use crate::types::{MutInPlaceValue, RedbKey, Value}; +use crate::types::{Key, MutInPlaceValue, Value}; use crate::{AccessGuard, Result}; #[cfg(feature = "logging")] use log::trace; @@ -217,7 +217,7 @@ impl UntypedBtreeMut { } } -pub(crate) struct BtreeMut<'a, K: RedbKey + 'static, V: Value + 'static> { +pub(crate) struct BtreeMut<'a, K: Key + 'static, V: Value + 'static> { mem: Arc, transaction_guard: Arc, root: Arc>>, @@ -227,7 +227,7 @@ pub(crate) struct BtreeMut<'a, K: RedbKey + 'static, V: Value + 'static> { _lifetime: PhantomData<&'a ()>, } -impl BtreeMut<'_, K, V> { +impl BtreeMut<'_, K, V> { pub(crate) fn new( root: Option<(PageNumber, Checksum)>, guard: Arc, @@ -440,7 +440,7 @@ impl BtreeMut<'_, K, V> { } } -impl<'a, K: RedbKey + 'a, V: MutInPlaceValue + 'a> BtreeMut<'a, K, V> { +impl<'a, K: Key + 'a, V: MutInPlaceValue + 'a> BtreeMut<'a, K, V> { /// Reserve space to insert a key-value pair /// The returned reference will have length equal to value_length // Return type has the same lifetime as &self, because the tree must not be modified until the mutable guard is dropped @@ -552,7 +552,7 @@ impl RawBtree { } } -pub(crate) struct Btree { +pub(crate) struct Btree { mem: Arc, _transaction_guard: Arc, // Cache of the root page to avoid repeated lookups @@ -563,7 +563,7 @@ pub(crate) struct Btree { _value_type: PhantomData, } -impl Btree { +impl Btree { pub(crate) fn new( root: Option<(PageNumber, Checksum)>, hint: PageHint, diff --git a/src/tree_store/btree_base.rs b/src/tree_store/btree_base.rs index cabe36d0..74f52322 100644 --- a/src/tree_store/btree_base.rs +++ b/src/tree_store/btree_base.rs @@ -2,7 +2,7 @@ use crate::tree_store::page_store::{ xxh3_checksum, CachePriority, Page, PageImpl, PageMut, TransactionalMemory, }; use crate::tree_store::PageNumber; -use crate::types::{MutInPlaceValue, RedbKey, Value}; +use crate::types::{Key, MutInPlaceValue, Value}; use crate::{Result, StorageError}; use std::cmp::Ordering; use std::marker::PhantomData; @@ -243,7 +243,7 @@ impl<'a> LeafAccessor<'a> { } } - pub(super) fn print_node(&self, include_value: bool) { + pub(super) fn print_node(&self, include_value: bool) { let mut i = 0; while let Some(entry) = self.entry(i) { eprint!(" key_{}={:?}", i, K::from_bytes(entry.key())); @@ -254,7 +254,7 @@ impl<'a> LeafAccessor<'a> { } } - pub(crate) fn position(&self, query: &[u8]) -> (usize, bool) { + pub(crate) fn position(&self, query: &[u8]) -> (usize, bool) { // inclusive let mut min_entry = 0; // inclusive. Start past end, since it might be positioned beyond the end of the leaf @@ -278,7 +278,7 @@ impl<'a> LeafAccessor<'a> { (min_entry, false) } - pub(crate) fn find_key(&self, query: &[u8]) -> Option { + pub(crate) fn find_key(&self, query: &[u8]) -> Option { let (entry, found) = self.position::(query); if found { Some(entry) @@ -1069,7 +1069,7 @@ impl<'a: 'b, 'b, T: Page + 'a> BranchAccessor<'a, 'b, T> { } } - pub(super) fn print_node(&self) { + pub(super) fn print_node(&self) { eprint!( "Internal[ (page={:?}), child_0={:?}", self.page.get_page_number(), @@ -1090,7 +1090,7 @@ impl<'a: 'b, 'b, T: Page + 'a> BranchAccessor<'a, 'b, T> { self.key_end(self.num_keys() - 1) } - pub(super) fn child_for_key(&self, query: &[u8]) -> (usize, PageNumber) { + pub(super) fn child_for_key(&self, query: &[u8]) -> (usize, PageNumber) { let mut min_child = 0; // inclusive let mut max_child = self.num_keys(); // inclusive while min_child < max_child { diff --git a/src/tree_store/btree_iters.rs b/src/tree_store/btree_iters.rs index 39ce4cd2..456a2a0b 100644 --- a/src/tree_store/btree_iters.rs +++ b/src/tree_store/btree_iters.rs @@ -3,7 +3,7 @@ use crate::tree_store::btree_base::{BRANCH, LEAF}; use crate::tree_store::btree_iters::RangeIterState::{Internal, Leaf}; use crate::tree_store::page_store::{Page, PageImpl, TransactionalMemory}; use crate::tree_store::PageNumber; -use crate::types::{RedbKey, Value}; +use crate::types::{Key, Value}; use crate::Result; use std::borrow::Borrow; use std::collections::Bound; @@ -123,7 +123,7 @@ impl RangeIterState { } } - fn get_entry(&self) -> Option> { + fn get_entry(&self) -> Option> { match self { Leaf { page, @@ -142,7 +142,7 @@ impl RangeIterState { } } -pub(crate) struct EntryGuard { +pub(crate) struct EntryGuard { page: PageImpl, key_range: Range, value_range: Range, @@ -150,7 +150,7 @@ pub(crate) struct EntryGuard { _value_type: PhantomData, } -impl EntryGuard { +impl EntryGuard { fn new(page: PageImpl, key_range: Range, value_range: Range) -> Self { Self { page, @@ -243,14 +243,14 @@ impl Iterator for AllPageNumbersBtreeIter { } } -pub(crate) struct BtreeDrain { +pub(crate) struct BtreeDrain { inner: BtreeRangeIter, free_on_drop: Vec, master_free_list: Arc>>, mem: Arc, } -impl BtreeDrain { +impl BtreeDrain { pub(crate) fn new( inner: BtreeRangeIter, free_on_drop: Vec, @@ -266,7 +266,7 @@ impl BtreeDrain { } } -impl Iterator for BtreeDrain { +impl Iterator for BtreeDrain { type Item = Result>; fn next(&mut self) -> Option { @@ -274,13 +274,13 @@ impl Iterator for BtreeDrain { } } -impl DoubleEndedIterator for BtreeDrain { +impl DoubleEndedIterator for BtreeDrain { fn next_back(&mut self) -> Option { self.inner.next_back() } } -impl Drop for BtreeDrain { +impl Drop for BtreeDrain { fn drop(&mut self) { // Ensure that the iter is entirely consumed, so that it doesn't have any references to the pages // to be freed @@ -298,7 +298,7 @@ impl Drop for BtreeDrain { } pub(crate) struct BtreeDrainFilter< - K: RedbKey + 'static, + K: Key + 'static, V: Value + 'static, F: for<'f> FnMut(K::SelfType<'f>, V::SelfType<'f>) -> bool, > { @@ -309,7 +309,7 @@ pub(crate) struct BtreeDrainFilter< mem: Arc, } -impl FnMut(K::SelfType<'f>, V::SelfType<'f>) -> bool> +impl FnMut(K::SelfType<'f>, V::SelfType<'f>) -> bool> BtreeDrainFilter { pub(crate) fn new( @@ -329,7 +329,7 @@ impl FnMut(K::SelfType<'f>, V::SelfType<'f>) -> } } -impl FnMut(K::SelfType<'f>, V::SelfType<'f>) -> bool> Iterator +impl FnMut(K::SelfType<'f>, V::SelfType<'f>) -> bool> Iterator for BtreeDrainFilter { type Item = Result>; @@ -346,7 +346,7 @@ impl FnMut(K::SelfType<'f>, V::SelfType<'f>) -> } } -impl FnMut(K::SelfType<'f>, V::SelfType<'f>) -> bool> +impl FnMut(K::SelfType<'f>, V::SelfType<'f>) -> bool> DoubleEndedIterator for BtreeDrainFilter { fn next_back(&mut self) -> Option { @@ -361,7 +361,7 @@ impl FnMut(K::SelfType<'f>, V::SelfType<'f>) -> } } -impl FnMut(K::SelfType<'f>, V::SelfType<'f>) -> bool> Drop +impl FnMut(K::SelfType<'f>, V::SelfType<'f>) -> bool> Drop for BtreeDrainFilter { fn drop(&mut self) { @@ -381,7 +381,7 @@ impl FnMut(K::SelfType<'f>, V::SelfType<'f>) -> } #[derive(Clone)] -pub(crate) struct BtreeRangeIter { +pub(crate) struct BtreeRangeIter { left: Option, // Exclusive. The previous element returned right: Option, // Exclusive. The previous element returned include_left: bool, // left is inclusive, instead of exclusive @@ -391,7 +391,7 @@ pub(crate) struct BtreeRangeIter { _value_type: PhantomData, } -impl BtreeRangeIter { +impl BtreeRangeIter { pub(crate) fn new<'a, T: RangeBounds, KR: Borrow>>( query_range: &'_ T, table_root: Option, @@ -467,7 +467,7 @@ impl BtreeRangeIter { } } -impl Iterator for BtreeRangeIter { +impl Iterator for BtreeRangeIter { type Item = Result>; fn next(&mut self) -> Option { @@ -535,7 +535,7 @@ impl Iterator for BtreeRangeIter { } } -impl DoubleEndedIterator for BtreeRangeIter { +impl DoubleEndedIterator for BtreeRangeIter { fn next_back(&mut self) -> Option { if let ( Some(Leaf { @@ -601,7 +601,7 @@ impl DoubleEndedIterator for BtreeRangeIter { } } -fn find_iter_unbounded( +fn find_iter_unbounded( page: PageImpl, mut parent: Option>, reverse: bool, @@ -647,7 +647,7 @@ fn find_iter_unbounded( // Returns a bool indicating whether the first entry pointed to by the state is included in the // queried range -fn find_iter_left( +fn find_iter_left( page: PageImpl, mut parent: Option>, query: &[u8], @@ -695,7 +695,7 @@ fn find_iter_left( } } -fn find_iter_right( +fn find_iter_right( page: PageImpl, mut parent: Option>, query: &[u8], diff --git a/src/tree_store/btree_mutator.rs b/src/tree_store/btree_mutator.rs index ec31037a..b1bdcfbd 100644 --- a/src/tree_store/btree_mutator.rs +++ b/src/tree_store/btree_mutator.rs @@ -7,7 +7,7 @@ use crate::tree_store::btree_mutator::DeletionResult::{ }; use crate::tree_store::page_store::{Page, PageImpl}; use crate::tree_store::{AccessGuardMut, PageNumber, RawLeafBuilder, TransactionalMemory}; -use crate::types::{RedbKey, Value}; +use crate::types::{Key, Value}; use crate::{AccessGuard, Result}; use std::cmp::{max, min}; use std::marker::PhantomData; @@ -44,7 +44,7 @@ struct InsertionResult<'a, V: Value> { old_value: Option>, } -pub(crate) struct MutateHelper<'a, 'b, K: RedbKey, V: Value> { +pub(crate) struct MutateHelper<'a, 'b, K: Key, V: Value> { root: &'b mut Option<(PageNumber, Checksum)>, modify_uncommitted: bool, mem: Arc, @@ -54,7 +54,7 @@ pub(crate) struct MutateHelper<'a, 'b, K: RedbKey, V: Value> { _lifetime: PhantomData<&'a ()>, } -impl<'a, 'b, K: RedbKey, V: Value> MutateHelper<'a, 'b, K, V> { +impl<'a, 'b, K: Key, V: Value> MutateHelper<'a, 'b, K, V> { pub(crate) fn new( root: &'b mut Option<(PageNumber, Checksum)>, mem: Arc, diff --git a/src/tree_store/table_tree.rs b/src/tree_store/table_tree.rs index a7d6cce9..7b33b7c3 100644 --- a/src/tree_store/table_tree.rs +++ b/src/tree_store/table_tree.rs @@ -9,7 +9,7 @@ use crate::tree_store::btree_iters::AllPageNumbersBtreeIter; use crate::tree_store::{ Btree, BtreeMut, BtreeRangeIter, PageHint, PageNumber, RawBtree, TransactionalMemory, }; -use crate::types::{MutInPlaceValue, RedbKey, TypeName, Value}; +use crate::types::{Key, MutInPlaceValue, TypeName, Value}; use crate::{DatabaseStats, Result}; use std::cmp::max; use std::collections::{HashMap, HashSet}; @@ -68,7 +68,7 @@ impl Value for FreedTableKey { } } -impl RedbKey for FreedTableKey { +impl Key for FreedTableKey { fn compare(data1: &[u8], data2: &[u8]) -> std::cmp::Ordering { let value1 = Self::from_bytes(data1); let value2 = Self::from_bytes(data2); @@ -475,7 +475,7 @@ impl TableTree { } // root_page: the root of the master table - pub(crate) fn get_table( + pub(crate) fn get_table( &self, name: &str, table_type: TableType, @@ -697,7 +697,7 @@ impl<'txn> TableTreeMut<'txn> { } // root_page: the root of the master table - pub(crate) fn get_table( + pub(crate) fn get_table( &self, name: &str, table_type: TableType, @@ -750,7 +750,7 @@ impl<'txn> TableTreeMut<'txn> { // Returns a tuple of the table id and the new root page // root_page: the root of the master table - pub(crate) fn get_or_create_table( + pub(crate) fn get_or_create_table( &mut self, name: &str, table_type: TableType, diff --git a/src/tuple_types.rs b/src/tuple_types.rs index 499f16b4..2838303c 100644 --- a/src/tuple_types.rs +++ b/src/tuple_types.rs @@ -1,4 +1,4 @@ -use crate::types::{RedbKey, TypeName, Value}; +use crate::types::{Key, TypeName, Value}; use std::borrow::Borrow; use std::cmp::Ordering; use std::mem::size_of; @@ -34,7 +34,7 @@ fn parse_lens(data: &[u8]) -> [usize; N] { result } -fn not_equal(data1: &[u8], data2: &[u8]) -> Option { +fn not_equal(data1: &[u8], data2: &[u8]) -> Option { match T::compare(data1, data2) { Ordering::Less => Some(Ordering::Less), Ordering::Equal => None, @@ -223,7 +223,7 @@ macro_rules! tuple_impl { } } - impl<$($t: RedbKey,)+ $t_last: RedbKey> RedbKey for ($($t,)+ $t_last) { + impl<$($t: Key,)+ $t_last: Key> Key for ($($t,)+ $t_last) { fn compare(data1: &[u8], data2: &[u8]) -> Ordering { if Self::fixed_width().is_some() { compare_fixed_impl!(data1, data2, $($t,)+ $t_last) diff --git a/src/types.rs b/src/types.rs index 1b65b945..9371bf14 100644 --- a/src/types.rs +++ b/src/types.rs @@ -124,7 +124,7 @@ impl MutInPlaceValue for &[u8] { } } -pub trait RedbKey: Value { +pub trait Key: Value { /// Compare data1 with data2 fn compare(data1: &[u8], data2: &[u8]) -> Ordering; } @@ -162,7 +162,7 @@ impl Value for () { } } -impl RedbKey for () { +impl Key for () { fn compare(_data1: &[u8], _data2: &[u8]) -> Ordering { Ordering::Equal } @@ -207,7 +207,7 @@ impl Value for bool { } } -impl RedbKey for bool { +impl Key for bool { fn compare(data1: &[u8], data2: &[u8]) -> Ordering { let value1 = Self::from_bytes(data1); let value2 = Self::from_bytes(data2); @@ -258,7 +258,7 @@ impl Value for Option { } } -impl RedbKey for Option { +impl Key for Option { #[allow(clippy::collapsible_else_if)] fn compare(data1: &[u8], data2: &[u8]) -> Ordering { if data1[0] == 0 { @@ -309,7 +309,7 @@ impl Value for &[u8] { } } -impl RedbKey for &[u8] { +impl Key for &[u8] { fn compare(data1: &[u8], data2: &[u8]) -> Ordering { data1.cmp(data2) } @@ -347,7 +347,7 @@ impl Value for &[u8; N] { } } -impl RedbKey for &[u8; N] { +impl Key for &[u8; N] { fn compare(data1: &[u8], data2: &[u8]) -> Ordering { data1.cmp(data2) } @@ -385,7 +385,7 @@ impl Value for &str { } } -impl RedbKey for &str { +impl Key for &str { fn compare(data1: &[u8], data2: &[u8]) -> Ordering { let str1 = Self::from_bytes(data1); let str2 = Self::from_bytes(data2); @@ -422,7 +422,7 @@ impl Value for char { } } -impl RedbKey for char { +impl Key for char { fn compare(data1: &[u8], data2: &[u8]) -> Ordering { Self::from_bytes(data1).cmp(&Self::from_bytes(data2)) } @@ -466,7 +466,7 @@ macro_rules! le_impl { ($t:ty) => { le_value!($t); - impl RedbKey for $t { + impl Key for $t { fn compare(data1: &[u8], data2: &[u8]) -> Ordering { Self::from_bytes(data1).cmp(&Self::from_bytes(data2)) } diff --git a/tests/backward_compatibility.rs b/tests/backward_compatibility.rs index f3852a33..cdb392c1 100644 --- a/tests/backward_compatibility.rs +++ b/tests/backward_compatibility.rs @@ -196,7 +196,7 @@ fn create_tempfile() -> tempfile::NamedTempFile { } } -fn test_helper() { +fn test_helper() { let tmpfile = create_tempfile(); let db = redb1::Database::create(tmpfile.path()).unwrap(); let table_def: redb1::TableDefinition = redb1::TableDefinition::new("table"); diff --git a/tests/basic_tests.rs b/tests/basic_tests.rs index b622a78e..97532c6f 100644 --- a/tests/basic_tests.rs +++ b/tests/basic_tests.rs @@ -1,6 +1,6 @@ use redb::backends::InMemoryBackend; use redb::{ - Database, MultimapTableDefinition, MultimapTableHandle, Range, ReadableTable, RedbKey, + Database, Key, MultimapTableDefinition, MultimapTableHandle, Range, ReadableTable, TableDefinition, TableError, TableHandle, TypeName, Value, }; use std::cmp::Ordering; @@ -1378,7 +1378,7 @@ fn custom_ordering() { } } - impl RedbKey for ReverseKey { + impl Key for ReverseKey { fn compare(data1: &[u8], data2: &[u8]) -> Ordering { data2.cmp(data1) } @@ -1632,7 +1632,7 @@ fn signature_lifetimes() { #[test] fn generic_signature_lifetimes() { - fn write_key_generic( + fn write_key_generic( table: TableDefinition, key: K::SelfType<'_>, db: &Database, @@ -1646,7 +1646,7 @@ fn generic_signature_lifetimes() { write_txn.commit().unwrap(); } - fn read_key_generic( + fn read_key_generic( table: TableDefinition, key: K::SelfType<'_>, db: &Database,