add week 1 day 2 tutorial

Signed-off-by: Alex Chi <iskyzh@gmail.com>
This commit is contained in:
Alex Chi
2024-01-21 11:56:09 +08:00
parent df35a954c9
commit 892e6ab8f7
11 changed files with 605 additions and 15 deletions

View File

@@ -11,7 +11,7 @@ bytes = "1"
crossbeam-epoch = "0.9"
crossbeam-skiplist = "0.1"
parking_lot = "0.12"
ouroboros = "0.15"
ouroboros = "0.18"
moka = "0.9"
clap = { version = "4.4.17", features = ["derive"] }
rand = "0.8.5"

View File

@@ -3,9 +3,23 @@
use anyhow::Result;
use crate::iterators::StorageIterator;
use crate::{
iterators::{merge_iterator::MergeIterator, StorageIterator},
mem_table::MemTableIterator,
};
pub struct LsmIterator {}
/// 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 })
}
}
impl StorageIterator for LsmIterator {
fn is_valid(&self) -> bool {
@@ -26,7 +40,8 @@ impl StorageIterator for LsmIterator {
}
/// A wrapper around existing iterator, will prevent users from calling `next` when the iterator is
/// invalid.
/// 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.
pub struct FusedIterator<I: StorageIterator> {
iter: I,
}