diff --git a/src/db/db_format.rs b/src/db/db_format.rs index 1af9eefafc00903e21c6888f9e1b2c5ff486a6b2..7dccd9724fff4a2d3b5b801c642a76ddfea60711 100644 --- a/src/db/db_format.rs +++ b/src/db/db_format.rs @@ -41,11 +41,9 @@ pub enum ValueType { K_TYPE_VALUE, } -// typedef uint64_t SequenceNumber; - pub struct ParsedInternalKey { user_key: Slice, - // sequence: SequenceNumber, + sequence: u64, value_type: ValueType } @@ -93,6 +91,7 @@ impl Default for ParsedInternalKey { fn default() -> Self { ParsedInternalKey { user_key: Default::default(), + sequence: 0, value_type: K_TYPE_DELETION, } } @@ -102,6 +101,7 @@ impl ParsedInternalKey { fn new(u: Slice, /* seq: SequenceNumber, */ t: ValueType) -> ParsedInternalKey { ParsedInternalKey { user_key: u, + sequence: 0, value_type: t, } } diff --git a/src/db/table_cache.rs b/src/db/table_cache.rs index 5713d1962b09728a421f7314c0e71c1961c6b7b8..ad6079bddebb55f87430bf04a6d0f08f777b0e91 100644 --- a/src/db/table_cache.rs +++ b/src/db/table_cache.rs @@ -45,7 +45,7 @@ impl TableCache { /// ``` /// /// ``` - fn evict(&self, _file_number: u64) { + fn evict(&mut self, _file_number: u64) { todo!() } diff --git a/src/table/block.rs b/src/table/block.rs index 3aa9b0c2bdb80b3c9e382f38c2047ebc1a9b6dba..564b7725135f598d95323009c88285334f77c3b0 100644 --- a/src/table/block.rs +++ b/src/table/block.rs @@ -18,11 +18,11 @@ impl Block { pub fn size(&self) { todo!() } - /// + /// 生成迭代器 /// /// # Arguments /// - /// * `_comparator`: + /// * `_comparator`: 比较器 /// /// returns: Result, Status> /// diff --git a/src/table/block_builder.rs b/src/table/block_builder.rs index d5f8b810874944a75088f19d4f8c47663d05beb6..a58922a09598e533c26255af1605d7dcd7362acb 100644 --- a/src/table/block_builder.rs +++ b/src/table/block_builder.rs @@ -19,7 +19,7 @@ impl BlockBuilder { /// ``` /// /// ``` - pub fn add(&self, _key: &Slice, _value: &Slice) { + pub fn add(&mut self, _key: &Slice, _value: &Slice) { todo!() } /// 重置builder @@ -29,7 +29,7 @@ impl BlockBuilder { /// ``` /// block_builder.reset(); /// ``` - pub fn reset(&self) { + pub fn reset(&mut self) { todo!() } /// 构造block @@ -40,7 +40,7 @@ impl BlockBuilder { /// ``` /// let block = block_builder.finish(); /// ``` - pub fn finish(&self) -> Result { + pub fn finish(&mut self) -> Result { todo!() } /// 判断builder是否为空 diff --git a/src/table/filter_block.rs b/src/table/filter_block.rs index c5a5932a5ec90772fe16026efc6ac24c919fd008..524c324c4c7c82cbfef98718c4f3617e15104828 100644 --- a/src/table/filter_block.rs +++ b/src/table/filter_block.rs @@ -18,7 +18,7 @@ impl FilterBlockBuilder { /// ``` /// filter_block_builder.start_block(1024_u64); /// ``` - pub fn start_block(&self, _block_offset: u64) { + pub fn start_block(&mut self, _block_offset: u64) { todo!() } @@ -35,7 +35,7 @@ impl FilterBlockBuilder { /// ``` /// /// ``` - pub fn add_key(&self, _key: &Slice) { + pub fn add_key(&mut self, _key: &Slice) { todo!() } /// 构造filterBlock @@ -45,7 +45,7 @@ impl FilterBlockBuilder { /// ``` /// filter_block_builder.finish(); /// ``` - pub fn finish(&self) -> Result { + pub fn finish(&mut self) -> Result { todo!() } } @@ -53,7 +53,7 @@ impl FilterBlockBuilder { pub struct FilterBlockReader {} impl FilterBlockReader { - pub fn key_may_match(&self, _block_offset: u64, _key: &Slice) { + pub fn key_may_match(&self, _block_offset: u64, _key: &Slice) -> bool { todo!() } } \ No newline at end of file diff --git a/src/table/format.rs b/src/table/format.rs index 9a64d4b8bbf2d5da987a1838645a74e9da56e6be..d956954d18cf4af447d688db36883eadf46400a4 100644 --- a/src/table/format.rs +++ b/src/table/format.rs @@ -2,6 +2,7 @@ use crate::traits::coding_trait::CodingTrait; use crate::util::coding; use crate::util::slice::Slice; use crate::util::Result; +use crate::util::status::Status; /// Maximum encoding length of a BlockHandle pub const k_max_encoded_length: u32 = 10 + 10; @@ -44,7 +45,7 @@ pub struct BlockContents { heap_allocated:bool, } -trait Block { +trait BlockTrait { /// /// The offset of the block in the file. /// @@ -81,10 +82,10 @@ trait Block { /// ``` /// /// ``` - fn encode_to(&self) -> Slice; + fn encode_to(&self) -> Result; /// - /// 将 Slice 对象解码后与BlockHandle比较,是否可以成功 + /// 将 Slice 对象解码后与BlockHandle set field /// /// # Arguments /// * `input`: @@ -96,18 +97,18 @@ trait Block { /// ``` /// /// ``` - fn decode_from(&self, input: Slice) -> Result; + fn decode_from(&mut self, input: Slice) -> Result<()>; } -trait Foot { +trait FootTrait { // The block handle for the metaindex block of the table - fn metaindex_handle() -> BlockHandle; + fn metaindex_handle(&self) -> BlockHandle; - fn set_metaindex_handle(h: BlockHandle); + fn set_metaindex_handle(&mut self, h: BlockHandle); - fn index_handle() -> BlockHandle; + fn index_handle(&self) -> BlockHandle; - fn set_index_handle(h: BlockHandle); + fn set_index_handle(&mut self, h: BlockHandle); /// /// 将 Foot 对象编码成 Slice @@ -121,7 +122,7 @@ trait Foot { /// ``` /// /// ``` - fn encode_to(&self) -> Slice; + fn encode_to(&self) -> Result; /// /// 将 Slice 对象解码后与 BlockHandle 比较,是否可以成功 @@ -136,13 +137,13 @@ trait Foot { /// ``` /// /// ``` - fn decode_from(&self, input: Slice) -> Result; + fn decode_from(&mut self, input: Slice) -> Result<()>; } trait BlockContent { /// Read the block identified by "handle" from "file". On failure /// return non-OK. On success fill *result and return OK. - fn read_block( + fn read_block(&self, // todo RandomAccessFile, ReadOptions 未提供 // file: RandomAccessFile, options: ReadOptions, handle: BlockHandle @@ -150,7 +151,7 @@ trait BlockContent { } -impl Block for BlockHandle { +impl BlockTrait for BlockHandle { fn offset(&self) -> u64 { self.offset_ } @@ -195,20 +196,20 @@ impl Default for BlockHandle { } } -impl Foot for Footer { - fn metaindex_handle() -> BlockHandle { +impl FootTrait for Footer { + fn metaindex_handle(&self) -> BlockHandle { todo!() } - fn set_metaindex_handle(h: BlockHandle) { + fn set_metaindex_handle(&self, h: BlockHandle) { todo!() } - fn index_handle() -> BlockHandle { + fn index_handle(&self) -> BlockHandle { todo!() } - fn set_index_handle(h: BlockHandle) { + fn set_index_handle(&self, h: BlockHandle) { todo!() } @@ -222,7 +223,7 @@ impl Foot for Footer { } impl BlockContent for BlockContents { - fn read_block(handle: BlockHandle) -> Result { + fn read_block(&self, handle: BlockHandle) -> Result { todo!() } } diff --git a/src/table/mod.rs b/src/table/mod.rs index a91ce21e573ffa2ae8926752bd6db33e35856a35..d0e015761c328ff1877f66324062a402b3a2ee33 100644 --- a/src/table/mod.rs +++ b/src/table/mod.rs @@ -3,5 +3,5 @@ pub mod block_builder; pub mod filter_block; pub mod format; mod format_test; -pub mod ss_table; +pub(crate) mod ss_table; mod ss_table_test; \ No newline at end of file