2022-12-24 14:48:57 -05:00
|
|
|
#![allow(unused_variables)] // TODO(you): remove this lint after implementing this mod
|
|
|
|
|
#![allow(dead_code)] // TODO(you): remove this lint after implementing this mod
|
|
|
|
|
|
|
|
|
|
use anyhow::Result;
|
|
|
|
|
|
2024-01-21 11:56:09 +08:00
|
|
|
use crate::{
|
|
|
|
|
iterators::{merge_iterator::MergeIterator, StorageIterator},
|
|
|
|
|
mem_table::MemTableIterator,
|
|
|
|
|
};
|
2022-12-24 15:34:34 -05:00
|
|
|
|
2024-01-21 11:56:09 +08:00
|
|
|
/// Represents the internal type for an LSM iterator. This type will be changed across the tutorial for multiple times.
|
|
|
|
|
type LsmIteratorInner = MergeIterator<MemTableIterator>;
|
|
|
|
|
|
|
|
|
|
pub struct LsmIterator {
|
|
|
|
|
inner: LsmIteratorInner,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl LsmIterator {
|
|
|
|
|
pub(crate) fn new(iter: LsmIteratorInner) -> Result<Self> {
|
|
|
|
|
Ok(Self { inner: iter })
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-12-24 14:48:57 -05:00
|
|
|
|
|
|
|
|
impl StorageIterator for LsmIterator {
|
2024-01-25 10:59:08 +08:00
|
|
|
type KeyType<'a> = &'a [u8];
|
|
|
|
|
|
2022-12-24 14:48:57 -05:00
|
|
|
fn is_valid(&self) -> bool {
|
|
|
|
|
unimplemented!()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn key(&self) -> &[u8] {
|
|
|
|
|
unimplemented!()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn value(&self) -> &[u8] {
|
|
|
|
|
unimplemented!()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn next(&mut self) -> Result<()> {
|
|
|
|
|
unimplemented!()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-24 15:34:34 -05:00
|
|
|
/// A wrapper around existing iterator, will prevent users from calling `next` when the iterator is
|
2024-01-21 11:56:09 +08:00
|
|
|
/// invalid. If an iterator is already invalid, `next` does not do anything. If `next` returns an error,
|
|
|
|
|
/// `is_valid` should return false, and `next` should always return an error.
|
2022-12-24 14:48:57 -05:00
|
|
|
pub struct FusedIterator<I: StorageIterator> {
|
|
|
|
|
iter: I,
|
2024-02-06 11:37:59 +08:00
|
|
|
has_errored: bool,
|
2022-12-24 14:48:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<I: StorageIterator> FusedIterator<I> {
|
|
|
|
|
pub fn new(iter: I) -> Self {
|
2024-02-06 11:37:59 +08:00
|
|
|
Self {
|
|
|
|
|
iter,
|
|
|
|
|
has_errored: false,
|
|
|
|
|
}
|
2022-12-24 14:48:57 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<I: StorageIterator> StorageIterator for FusedIterator<I> {
|
2024-12-09 00:23:03 -05:00
|
|
|
type KeyType<'a>
|
|
|
|
|
= I::KeyType<'a>
|
|
|
|
|
where
|
|
|
|
|
Self: 'a;
|
2024-01-25 10:59:08 +08:00
|
|
|
|
2022-12-24 14:48:57 -05:00
|
|
|
fn is_valid(&self) -> bool {
|
|
|
|
|
unimplemented!()
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-25 10:59:08 +08:00
|
|
|
fn key(&self) -> Self::KeyType<'_> {
|
2022-12-24 14:48:57 -05:00
|
|
|
unimplemented!()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn value(&self) -> &[u8] {
|
|
|
|
|
unimplemented!()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn next(&mut self) -> Result<()> {
|
|
|
|
|
unimplemented!()
|
|
|
|
|
}
|
|
|
|
|
}
|