#![allow(unused_variables)] // TODO(you): remove this lint after implementing this mod #![allow(dead_code)] // TODO(you): remove this lint after implementing this mod mod builder; mod iterator; use std::path::Path; use std::sync::Arc; use anyhow::Result; pub use builder::SsTableBuilder; use bytes::{Buf, Bytes}; pub use iterator::SsTableIterator; use crate::block::Block; #[derive(Clone, Debug, PartialEq, Eq)] pub struct BlockMeta { /// Offset of this data block. pub offset: usize, /// The first key of the data block. pub first_key: Bytes, } impl BlockMeta { /// Encode block meta to a buffer. pub fn encode_block_meta( block_meta: &[BlockMeta], #[allow(clippy::ptr_arg)] // remove this allow after you finish buf: &mut Vec, ) { unimplemented!() } /// Decode block meta from a buffer. pub fn decode_block_meta(buf: impl Buf) -> Vec { unimplemented!() } } /// A file object. pub struct FileObject(Bytes); impl FileObject { pub fn read(&self, offset: u64, len: u64) -> Result> { Ok(self.0[offset as usize..(offset + len) as usize].to_vec()) } pub fn size(&self) -> u64 { self.0.len() as u64 } pub fn create(path: &Path, data: Vec) -> Result { unimplemented!() } pub fn open(path: &Path) -> Result { unimplemented!() } } pub struct SsTable { file: FileObject, block_metas: Vec, block_meta_offset: usize, } impl SsTable { /// Open SSTable from a file. pub fn open(file: FileObject) -> Result { unimplemented!() } /// Read a block from the disk. pub fn read_block(&self, block_idx: usize) -> Result> { unimplemented!() } /// Find the block that may contain `key`. pub fn find_block_idx(&self, key: &[u8]) -> usize { unimplemented!() } /// Get number of data blocks. pub fn num_of_blocks(&self) -> usize { unimplemented!() } } #[cfg(test)] mod tests;