add week 1 day 3 blocks

Signed-off-by: Alex Chi Z <iskyzh@gmail.com>
This commit is contained in:
Alex Chi Z
2024-01-21 13:55:49 +08:00
parent 71db0cc6a1
commit f88394a686
9 changed files with 220 additions and 28 deletions

View File

@@ -5,22 +5,13 @@ mod builder;
mod iterator;
pub use builder::BlockBuilder;
/// You may want to check `bytes::BufMut` out when manipulating continuous chunks of memory
use bytes::Bytes;
pub use iterator::BlockIterator;
/// A block is the smallest unit of read and caching in LSM tree.
/// It is a collection of sorted key-value pairs.
/// The `actual` storage format is as below (After `Block::encode`):
///
/// ----------------------------------------------------------------------------------------------------
/// | Data Section | Offset Section | Extra |
/// ----------------------------------------------------------------------------------------------------
/// | Entry #1 | Entry #2 | ... | Entry #N | Offset #1 | Offset #2 | ... | Offset #N | num_of_elements |
/// ----------------------------------------------------------------------------------------------------
/// A block is the smallest unit of read and caching in LSM tree. It is a collection of sorted key-value pairs.
pub struct Block {
data: Vec<u8>,
offsets: Vec<u16>,
pub(crate) data: Vec<u8>,
pub(crate) offsets: Vec<u16>,
}
impl Block {
@@ -35,6 +26,3 @@ impl Block {
unimplemented!()
}
}
#[cfg(test)]
mod tests;

View File

@@ -11,8 +11,8 @@ pub struct BlockIterator {
block: Arc<Block>,
/// The current key, empty represents the iterator is invalid
key: Vec<u8>,
/// The corresponding value, can be empty
value: Vec<u8>,
/// the value range from the block
value_range: (usize, usize),
/// Current index of the key-value pair, should be in range of [0, num_of_elements)
idx: usize,
}
@@ -22,7 +22,7 @@ impl BlockIterator {
Self {
block,
key: Vec::new(),
value: Vec::new(),
value_range: (0, 0),
idx: 0,
}
}

View File

@@ -1 +0,0 @@
//! Please copy `mini-lsm/src/block/tests.rs` here so that you can run tests.

View File

@@ -159,6 +159,3 @@ impl SsTable {
self.id
}
}
#[cfg(test)]
mod tests;

View File

@@ -1 +0,0 @@
//! Please copy `mini-lsm/src/table/tests.rs` here so that you can run tests.