From f24d3e9d7a64992d06abaef0ca3f6647a7eb2dd6 Mon Sep 17 00:00:00 2001 From: al8n Date: Sun, 3 Nov 2024 01:10:01 +0800 Subject: [PATCH] Rename some types --- Cargo.toml | 2 +- src/swmr.rs | 4 +-- src/types/multiple_version.rs | 18 +++++----- src/wal/multiple_version.rs | 58 ++++++++++++-------------------- src/wal/multiple_version/iter.rs | 34 +++++++++---------- 5 files changed, 50 insertions(+), 66 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 22318ca..f8e8366 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "orderwal" -version = "0.5.0" +version = "0.5.1" edition = "2021" repository = "https://github.com/al8n/orderwal" homepage = "https://github.com/al8n/orderwal" diff --git a/src/swmr.rs b/src/swmr.rs index 2993533..cbac855 100644 --- a/src/swmr.rs +++ b/src/swmr.rs @@ -88,9 +88,9 @@ pub mod multiple_version { pub use crate::{ memtable::arena::TableOptions as ArenaTableOptions, - types::multiple_version::{Entry, Key, MultipleVersionEntry, Value}, + types::multiple_version::{Entry, Key, Value, VersionedEntry}, wal::multiple_version::{ - Iter, Keys, MultipleVersionIter, MultipleVersionRange, RangeKeys, RangeValues, Reader, Writer, + Iter, IterAll, Keys, RangeAll, RangeKeys, RangeValues, Reader, Writer, }, }; diff --git a/src/types/multiple_version.rs b/src/types/multiple_version.rs index be36128..3f98e76 100644 --- a/src/types/multiple_version.rs +++ b/src/types/multiple_version.rs @@ -378,7 +378,7 @@ where } /// The reference to an entry in the generic WALs. -pub struct MultipleVersionEntry<'a, E> +pub struct VersionedEntry<'a, E> where E: VersionedMemtableEntry<'a>, E::Key: Type, @@ -391,14 +391,14 @@ where query_version: u64, } -impl<'a, E> core::fmt::Debug for MultipleVersionEntry<'a, E> +impl<'a, E> core::fmt::Debug for VersionedEntry<'a, E> where E: VersionedMemtableEntry<'a> + core::fmt::Debug, E::Key: Type, E::Value: Type, { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - f.debug_struct("MultipleVersionEntry") + f.debug_struct("VersionedEntry") .field("key", &self.key()) .field("value", &self.value()) .field("version", &self.version) @@ -406,7 +406,7 @@ where } } -impl<'a, E> Clone for MultipleVersionEntry<'a, E> +impl<'a, E> Clone for VersionedEntry<'a, E> where E: VersionedMemtableEntry<'a> + Clone, E::Key: Type, @@ -424,7 +424,7 @@ where } } -impl<'a, E> MultipleVersionEntry<'a, E> +impl<'a, E> VersionedEntry<'a, E> where E: VersionedMemtableEntry<'a>, E::Key: Type, @@ -447,7 +447,7 @@ where } } -impl<'a, E> MultipleVersionEntry<'a, E> +impl<'a, E> VersionedEntry<'a, E> where E: VersionedMemtableEntry<'a>, E::Key: Ord + Type, @@ -478,7 +478,7 @@ where } } -impl<'a, E> MultipleVersionEntry<'a, E> +impl<'a, E> VersionedEntry<'a, E> where E: VersionedMemtableEntry<'a>, E::Key: Type, @@ -502,7 +502,7 @@ where self .key .raw() - .expect("MultipleVersionEntry's raw key cannot be None") + .expect("VersionedEntry's raw key cannot be None") } /// Returns the value of the entry. @@ -518,7 +518,7 @@ where None => None, Some(v) => Some( v.raw() - .expect("MultipleVersionEntry's raw value cannot be None if value exists"), + .expect("VersionedEntry's raw value cannot be None if value exists"), ), } } diff --git a/src/wal/multiple_version.rs b/src/wal/multiple_version.rs index 111dd06..cabfd0f 100644 --- a/src/wal/multiple_version.rs +++ b/src/wal/multiple_version.rs @@ -18,7 +18,7 @@ use crate::{ memtable::{BaseTable, MultipleVersionMemtable, VersionedMemtableEntry}, sealed::{Constructable, MultipleVersionWalReader, Wal}, types::{ - multiple_version::{Entry, MultipleVersionEntry}, + multiple_version::{Entry, VersionedEntry}, BufWriter, KeyBuilder, ValueBuilder, }, Options, @@ -135,7 +135,7 @@ pub trait Reader: Constructable { fn iter_all_versions( &self, version: u64, - ) -> MultipleVersionIter< + ) -> IterAll< '_, <>::Memtable as MultipleVersionMemtable>::IterAll<'_>, Self::Memtable, @@ -148,7 +148,7 @@ pub trait Reader: Constructable { ::Value: Type, for<'a> ::Item<'a>: VersionedMemtableEntry<'a>, { - MultipleVersionIter::new(MultipleVersionBaseIter::new( + IterAll::new(MultipleVersionBaseIter::new( version, self.as_wal().iter_all_versions(version), )) @@ -185,7 +185,7 @@ pub trait Reader: Constructable { &'a self, version: u64, range: R, - ) -> MultipleVersionRange<'a, R, Q, >::Memtable> + ) -> RangeAll<'a, R, Q, >::Memtable> where R: RangeBounds + 'a, Q: ?Sized + Comparable<<::Key as Type>::Ref<'a>>, @@ -198,7 +198,7 @@ pub trait Reader: Constructable { for<'b> ::VersionedItem<'b>: VersionedMemtableEntry<'b>, { - MultipleVersionRange::new(MultipleVersionBaseIter::new( + RangeAll::new(MultipleVersionBaseIter::new( version, self .as_wal() @@ -329,9 +329,7 @@ pub trait Reader: Constructable { fn first_versioned( &self, version: u64, - ) -> Option< - MultipleVersionEntry<'_, ::VersionedItem<'_>>, - > + ) -> Option::VersionedItem<'_>>> where Self::Memtable: MultipleVersionMemtable, ::Key: Type + Ord, @@ -345,7 +343,7 @@ pub trait Reader: Constructable { self .as_wal() .first_versioned(version) - .map(|ent| MultipleVersionEntry::with_version(ent, version)) + .map(|ent| VersionedEntry::with_version(ent, version)) } /// Returns the last key-value pair in the map. The key in this pair is the maximum key in the wal. @@ -373,9 +371,7 @@ pub trait Reader: Constructable { fn last_versioned( &self, version: u64, - ) -> Option< - MultipleVersionEntry<'_, ::VersionedItem<'_>>, - > + ) -> Option::VersionedItem<'_>>> where Self::Memtable: MultipleVersionMemtable, ::Key: Type + Ord, @@ -389,7 +385,7 @@ pub trait Reader: Constructable { self .as_wal() .last_versioned(version) - .map(|ent| MultipleVersionEntry::with_version(ent, version)) + .map(|ent| VersionedEntry::with_version(ent, version)) } /// Returns `true` if the key exists in the WAL. @@ -507,9 +503,7 @@ pub trait Reader: Constructable { &'a self, version: u64, key: &Q, - ) -> Option< - MultipleVersionEntry<'a, ::VersionedItem<'a>>, - > + ) -> Option::VersionedItem<'a>>> where Q: ?Sized + Comparable<<::Key as Type>::Ref<'a>>, Self::Memtable: MultipleVersionMemtable, @@ -524,7 +518,7 @@ pub trait Reader: Constructable { self .as_wal() .get_versioned(version, Query::<_, Q>::ref_cast(key)) - .map(|ent| MultipleVersionEntry::with_version(ent, version)) + .map(|ent| VersionedEntry::with_version(ent, version)) } /// Gets the value associated with the key. @@ -565,9 +559,7 @@ pub trait Reader: Constructable { &self, version: u64, key: &[u8], - ) -> Option< - MultipleVersionEntry<'_, ::VersionedItem<'_>>, - > + ) -> Option::VersionedItem<'_>>> where Self::Memtable: MultipleVersionMemtable, ::Key: Type + Ord, @@ -581,7 +573,7 @@ pub trait Reader: Constructable { self .as_wal() .get_versioned(version, Slice::ref_cast(key)) - .map(|ent| MultipleVersionEntry::with_version(ent, version)) + .map(|ent| VersionedEntry::with_version(ent, version)) } /// Returns a value associated to the highest element whose key is below the given bound. @@ -618,9 +610,7 @@ pub trait Reader: Constructable { &'a self, version: u64, bound: Bound<&Q>, - ) -> Option< - MultipleVersionEntry<'a, ::VersionedItem<'a>>, - > + ) -> Option::VersionedItem<'a>>> where Q: ?Sized + Comparable<<::Key as Type>::Ref<'a>>, Self::Memtable: MultipleVersionMemtable, @@ -635,7 +625,7 @@ pub trait Reader: Constructable { self .as_wal() .upper_bound_versioned(version, bound.map(Query::ref_cast)) - .map(|ent| MultipleVersionEntry::with_version(ent, version)) + .map(|ent| VersionedEntry::with_version(ent, version)) } /// Returns a value associated to the highest element whose key is below the given bound. @@ -677,9 +667,7 @@ pub trait Reader: Constructable { &self, version: u64, bound: Bound<&[u8]>, - ) -> Option< - MultipleVersionEntry<'_, ::VersionedItem<'_>>, - > + ) -> Option::VersionedItem<'_>>> where Self::Memtable: MultipleVersionMemtable, ::Key: Type + Ord, @@ -693,7 +681,7 @@ pub trait Reader: Constructable { self .as_wal() .upper_bound_versioned(version, bound.map(Slice::ref_cast)) - .map(|ent| MultipleVersionEntry::with_version(ent, version)) + .map(|ent| VersionedEntry::with_version(ent, version)) } /// Returns a value associated to the lowest element whose key is above the given bound. @@ -731,9 +719,7 @@ pub trait Reader: Constructable { &'a self, version: u64, bound: Bound<&Q>, - ) -> Option< - MultipleVersionEntry<'a, ::VersionedItem<'a>>, - > + ) -> Option::VersionedItem<'a>>> where Q: ?Sized + Comparable<<::Key as Type>::Ref<'a>>, Self::Memtable: MultipleVersionMemtable, @@ -748,7 +734,7 @@ pub trait Reader: Constructable { self .as_wal() .lower_bound_versioned(version, bound.map(Query::ref_cast)) - .map(|ent| MultipleVersionEntry::with_version(ent, version)) + .map(|ent| VersionedEntry::with_version(ent, version)) } /// Returns a value associated to the lowest element whose key is above the given bound. @@ -791,9 +777,7 @@ pub trait Reader: Constructable { &self, version: u64, bound: Bound<&[u8]>, - ) -> Option< - MultipleVersionEntry<'_, ::VersionedItem<'_>>, - > + ) -> Option::VersionedItem<'_>>> where Self::Memtable: MultipleVersionMemtable, ::Key: Type + Ord, @@ -810,7 +794,7 @@ pub trait Reader: Constructable { version, bound.map(Slice::<::Key>::ref_cast), ) - .map(|ent| MultipleVersionEntry::with_version(ent, version)) + .map(|ent| VersionedEntry::with_version(ent, version)) } } diff --git a/src/wal/multiple_version/iter.rs b/src/wal/multiple_version/iter.rs index 82262c6..ea2bf71 100644 --- a/src/wal/multiple_version/iter.rs +++ b/src/wal/multiple_version/iter.rs @@ -4,7 +4,7 @@ use dbutils::{equivalent::Comparable, types::Type}; use crate::{ memtable::{BaseEntry, MultipleVersionMemtable, VersionedMemtableEntry}, - types::multiple_version::{Entry, Key, MultipleVersionEntry, Value}, + types::multiple_version::{Entry, Key, Value, VersionedEntry}, wal::{KeyPointer, ValuePointer}, }; @@ -694,7 +694,7 @@ where } /// Iterator over the entries in the WAL. -pub struct MultipleVersionIter<'a, I, M> +pub struct IterAll<'a, I, M> where M: MultipleVersionMemtable, for<'b> M::Item<'b>: VersionedMemtableEntry<'b>, @@ -704,7 +704,7 @@ where version: u64, } -impl<'a, I, M> MultipleVersionIter<'a, I, M> +impl<'a, I, M> IterAll<'a, I, M> where M: MultipleVersionMemtable, for<'b> M::Item<'b>: VersionedMemtableEntry<'b>, @@ -725,7 +725,7 @@ where } } -impl<'a, I, M> Iterator for MultipleVersionIter<'a, I, M> +impl<'a, I, M> Iterator for IterAll<'a, I, M> where M: MultipleVersionMemtable + 'a, M::Key: Type + Ord, @@ -734,18 +734,18 @@ where for<'b> M::VersionedItem<'b>: VersionedMemtableEntry<'b>, I: Iterator>, { - type Item = MultipleVersionEntry<'a, M::VersionedItem<'a>>; + type Item = VersionedEntry<'a, M::VersionedItem<'a>>; #[inline] fn next(&mut self) -> Option { self .iter .next() - .map(|ent| MultipleVersionEntry::with_version(ent, self.version)) + .map(|ent| VersionedEntry::with_version(ent, self.version)) } } -impl<'a, I, M> DoubleEndedIterator for MultipleVersionIter<'a, I, M> +impl<'a, I, M> DoubleEndedIterator for IterAll<'a, I, M> where M: MultipleVersionMemtable + 'a, M::Key: Type + Ord, @@ -759,11 +759,11 @@ where self .iter .next_back() - .map(|ent| MultipleVersionEntry::with_version(ent, self.version)) + .map(|ent| VersionedEntry::with_version(ent, self.version)) } } -impl<'a, I, M> FusedIterator for MultipleVersionIter<'a, I, M> +impl<'a, I, M> FusedIterator for IterAll<'a, I, M> where M: MultipleVersionMemtable + 'a, M::Key: Type + Ord, @@ -775,7 +775,7 @@ where } /// An iterator over a subset of the entries in the WAL. -pub struct MultipleVersionRange<'a, R, Q, B> +pub struct RangeAll<'a, R, Q, B> where R: RangeBounds + 'a, Q: ?Sized + Comparable<::Ref<'a>>, @@ -792,7 +792,7 @@ where version: u64, } -impl<'a, R, Q, B> MultipleVersionRange<'a, R, Q, B> +impl<'a, R, Q, B> RangeAll<'a, R, Q, B> where R: RangeBounds + 'a, Q: ?Sized + Comparable<::Ref<'a>>, @@ -822,7 +822,7 @@ where } } -impl<'a, R, Q, B> Iterator for MultipleVersionRange<'a, R, Q, B> +impl<'a, R, Q, B> Iterator for RangeAll<'a, R, Q, B> where R: RangeBounds + 'a, Q: ?Sized + Comparable<::Ref<'a>>, @@ -834,18 +834,18 @@ where for<'b> B::Item<'b>: VersionedMemtableEntry<'b>, for<'b> B::VersionedItem<'b>: VersionedMemtableEntry<'b>, { - type Item = MultipleVersionEntry<'a, B::VersionedItem<'a>>; + type Item = VersionedEntry<'a, B::VersionedItem<'a>>; #[inline] fn next(&mut self) -> Option { self .iter .next() - .map(|ent| MultipleVersionEntry::with_version(ent, self.version)) + .map(|ent| VersionedEntry::with_version(ent, self.version)) } } -impl<'a, R, Q, B> DoubleEndedIterator for MultipleVersionRange<'a, R, Q, B> +impl<'a, R, Q, B> DoubleEndedIterator for RangeAll<'a, R, Q, B> where R: RangeBounds + 'a, Q: ?Sized + Comparable<::Ref<'a>>, @@ -862,11 +862,11 @@ where self .iter .next_back() - .map(|ent| MultipleVersionEntry::with_version(ent, self.version)) + .map(|ent| VersionedEntry::with_version(ent, self.version)) } } -impl<'a, R, Q, B> FusedIterator for MultipleVersionRange<'a, R, Q, B> +impl<'a, R, Q, B> FusedIterator for RangeAll<'a, R, Q, B> where R: RangeBounds + 'a, Q: ?Sized + Comparable<::Ref<'a>>,