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:
Alex Chi Z
2024-01-25 10:59:08 +08:00
committed by GitHub
parent 2fefe3e505
commit a3a92359e1
42 changed files with 824 additions and 281 deletions

View File

@@ -7,7 +7,7 @@ use std::sync::Arc;
use anyhow::Result;
use super::{BlockMeta, SsTable};
use crate::{block::BlockBuilder, lsm_storage::BlockCache};
use crate::{block::BlockBuilder, key::KeySlice, lsm_storage::BlockCache};
/// Builds an SSTable from key-value pairs.
pub struct SsTableBuilder {
@@ -29,7 +29,7 @@ impl SsTableBuilder {
///
/// Note: You should split a new block when the current block is full.(`std::mem::replace` may
/// be helpful here)
pub fn add(&mut self, key: &[u8], value: &[u8]) {
pub fn add(&mut self, key: KeySlice, value: &[u8]) {
unimplemented!()
}

View File

@@ -6,7 +6,7 @@ use std::sync::Arc;
use anyhow::Result;
use super::SsTable;
use crate::{block::BlockIterator, iterators::StorageIterator};
use crate::{block::BlockIterator, iterators::StorageIterator, key::KeySlice};
/// An iterator over the contents of an SSTable.
pub struct SsTableIterator {
@@ -27,21 +27,23 @@ impl SsTableIterator {
}
/// Create a new iterator and seek to the first key-value pair which >= `key`.
pub fn create_and_seek_to_key(table: Arc<SsTable>, key: &[u8]) -> Result<Self> {
pub fn create_and_seek_to_key(table: Arc<SsTable>, key: KeySlice) -> Result<Self> {
unimplemented!()
}
/// Seek to the first key-value pair which >= `key`.
/// Note: You probably want to review the handout for detailed explanation when implementing
/// this function.
pub fn seek_to_key(&mut self, key: &[u8]) -> Result<()> {
pub fn seek_to_key(&mut self, key: KeySlice) -> Result<()> {
unimplemented!()
}
}
impl StorageIterator for SsTableIterator {
type KeyType<'a> = KeySlice<'a>;
/// Return the `key` that's held by the underlying block iterator.
fn key(&self) -> &[u8] {
fn key(&self) -> KeySlice {
unimplemented!()
}