@@ -1 +1,85 @@
|
||||
#![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, sync::Arc};
|
||||
|
||||
pub use builder::SsTableBuilder;
|
||||
use bytes::{Buf, Bytes};
|
||||
pub use iterator::SsTableIterator;
|
||||
|
||||
use crate::block::Block;
|
||||
use anyhow::Result;
|
||||
|
||||
#[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)] buf: &mut Vec<u8>,
|
||||
) {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
/// Decode block meta from a buffer.
|
||||
pub fn decode_block_meta(buf: impl Buf) -> Vec<BlockMeta> {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
||||
/// A file object.
|
||||
pub struct FileObject(Bytes);
|
||||
|
||||
impl FileObject {
|
||||
pub fn read(&self, offset: u64, len: u64) -> Result<Vec<u8>> {
|
||||
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<u8>) -> Result<Self> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn open(path: &Path) -> Result<Self> {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
||||
pub struct SsTable {}
|
||||
|
||||
impl SsTable {
|
||||
/// Open SSTable from a file.
|
||||
pub fn open(file: FileObject) -> Result<Self> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
/// Read a block from the disk.
|
||||
pub fn read_block(&self, block_idx: usize) -> Result<Arc<Block>> {
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user