add key abstraction and prepare for MVCC (#28)
* add key abstraction and prepare for MVCC Signed-off-by: Alex Chi <iskyzh@gmail.com> * a little bit type exercise Signed-off-by: Alex Chi <iskyzh@gmail.com> * refactor tests Signed-off-by: Alex Chi <iskyzh@gmail.com> * fix clippy warnings Signed-off-by: Alex Chi <iskyzh@gmail.com> * refactor starter code Signed-off-by: Alex Chi <iskyzh@gmail.com> * final touch docs Signed-off-by: Alex Chi <iskyzh@gmail.com> --------- Signed-off-by: Alex Chi <iskyzh@gmail.com>
This commit is contained in:
@@ -6,7 +6,10 @@ use std::sync::Arc;
|
||||
use anyhow::Result;
|
||||
|
||||
use super::StorageIterator;
|
||||
use crate::table::{SsTable, SsTableIterator};
|
||||
use crate::{
|
||||
key::KeySlice,
|
||||
table::{SsTable, SsTableIterator},
|
||||
};
|
||||
|
||||
/// Concat multiple iterators ordered in key order and their key ranges do not overlap. We do not want to create the
|
||||
/// iterators when initializing this iterator to reduce the overhead of seeking.
|
||||
@@ -21,13 +24,15 @@ impl SstConcatIterator {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn create_and_seek_to_key(sstables: Vec<Arc<SsTable>>, key: &[u8]) -> Result<Self> {
|
||||
pub fn create_and_seek_to_key(sstables: Vec<Arc<SsTable>>, key: KeySlice) -> Result<Self> {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
||||
impl StorageIterator for SstConcatIterator {
|
||||
fn key(&self) -> &[u8] {
|
||||
type KeyType<'a> = KeySlice<'a>;
|
||||
|
||||
fn key(&self) -> KeySlice {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,8 @@ use std::collections::BinaryHeap;
|
||||
|
||||
use anyhow::Result;
|
||||
|
||||
use crate::key::KeySlice;
|
||||
|
||||
use super::StorageIterator;
|
||||
|
||||
struct HeapWrapper<I: StorageIterator>(pub usize, pub Box<I>);
|
||||
@@ -21,7 +23,7 @@ impl<I: StorageIterator> Eq for HeapWrapper<I> {}
|
||||
impl<I: StorageIterator> PartialOrd for HeapWrapper<I> {
|
||||
#[allow(clippy::non_canonical_partial_ord_impl)]
|
||||
fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> {
|
||||
match self.1.key().cmp(other.1.key()) {
|
||||
match self.1.key().cmp(&other.1.key()) {
|
||||
cmp::Ordering::Greater => Some(cmp::Ordering::Greater),
|
||||
cmp::Ordering::Less => Some(cmp::Ordering::Less),
|
||||
cmp::Ordering::Equal => self.0.partial_cmp(&other.0),
|
||||
@@ -49,8 +51,12 @@ impl<I: StorageIterator> MergeIterator<I> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<I: StorageIterator> StorageIterator for MergeIterator<I> {
|
||||
fn key(&self) -> &[u8] {
|
||||
impl<I: 'static + for<'a> StorageIterator<KeyType<'a> = KeySlice<'a>>> StorageIterator
|
||||
for MergeIterator<I>
|
||||
{
|
||||
type KeyType<'a> = KeySlice<'a>;
|
||||
|
||||
fn key(&self) -> KeySlice {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
|
||||
use anyhow::Result;
|
||||
|
||||
use crate::key::KeySlice;
|
||||
|
||||
use super::StorageIterator;
|
||||
|
||||
/// Merges two iterators of different types into one. If the two iterators have the same key, only
|
||||
@@ -13,14 +15,24 @@ pub struct TwoMergeIterator<A: StorageIterator, B: StorageIterator> {
|
||||
// Add fields as need
|
||||
}
|
||||
|
||||
impl<A: StorageIterator, B: StorageIterator> TwoMergeIterator<A, B> {
|
||||
impl<
|
||||
A: 'static + for<'a> StorageIterator<KeyType<'a> = KeySlice<'a>>,
|
||||
B: 'static + for<'a> StorageIterator<KeyType<'a> = KeySlice<'a>>,
|
||||
> TwoMergeIterator<A, B>
|
||||
{
|
||||
pub fn create(a: A, b: B) -> Result<Self> {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
||||
impl<A: StorageIterator, B: StorageIterator> StorageIterator for TwoMergeIterator<A, B> {
|
||||
fn key(&self) -> &[u8] {
|
||||
impl<
|
||||
A: 'static + for<'a> StorageIterator<KeyType<'a> = KeySlice<'a>>,
|
||||
B: 'static + for<'a> StorageIterator<KeyType<'a> = KeySlice<'a>>,
|
||||
> StorageIterator for TwoMergeIterator<A, B>
|
||||
{
|
||||
type KeyType<'a> = KeySlice<'a>;
|
||||
|
||||
fn key(&self) -> KeySlice {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user