Files
mini_lsm/mini-lsm-starter/src/block/iterator.rs
Xu de7f2ec263 docs: add comments & hints for day one starter and reference code (#18)
* feat(docs): Improve/Add comments & some hints for day one starter code

* feat(docs): Add comments for day one solution code

* feat(docs): Add figure for block storage format in starter code (block.rs)
2023-07-11 00:05:34 -04:00

72 lines
1.9 KiB
Rust

#![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 std::sync::Arc;
use super::Block;
/// Iterates on a block.
pub struct BlockIterator {
/// The internal `Block`, wrapped by an `Arc`
block: Arc<Block>,
/// The current key, empty represents the iterator is invalid
key: Vec<u8>,
/// The corresponding value, can be empty
value: Vec<u8>,
/// Current index of the key-value pair, should be in range of [0, num_of_elements)
idx: usize,
}
impl BlockIterator {
fn new(block: Arc<Block>) -> Self {
Self {
block,
key: Vec::new(),
value: Vec::new(),
idx: 0,
}
}
/// Creates a block iterator and seek to the first entry.
pub fn create_and_seek_to_first(block: Arc<Block>) -> Self {
unimplemented!()
}
/// Creates a block iterator and seek to the first key that >= `key`.
pub fn create_and_seek_to_key(block: Arc<Block>, key: &[u8]) -> Self {
unimplemented!()
}
/// Returns the key of the current entry.
pub fn key(&self) -> &[u8] {
unimplemented!()
}
/// Returns the value of the current entry.
pub fn value(&self) -> &[u8] {
unimplemented!()
}
/// Returns true if the iterator is valid.
/// Note: You may want to make use of `key`
pub fn is_valid(&self) -> bool {
unimplemented!()
}
/// Seeks to the first key in the block.
pub fn seek_to_first(&mut self) {
unimplemented!()
}
/// Move to the next key in the block.
pub fn next(&mut self) {
unimplemented!()
}
/// Seek to the first key that >= `key`.
/// Note: You should assume the key-value pairs in the block are sorted when being added by callers.
pub fn seek_to_key(&mut self, key: &[u8]) {
unimplemented!()
}
}