From a7ec88bca04a682dd25c781531712ec860585a0d Mon Sep 17 00:00:00 2001 From: colagy Date: Tue, 17 Jan 2023 17:30:41 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/db/db_format.rs | 6 +++--- src/db/table_cache.rs | 2 +- src/table/block.rs | 4 ++-- src/table/block_builder.rs | 6 +++--- src/table/filter_block.rs | 8 ++++---- src/table/format.rs | 39 +++++++++++++++++++------------------- src/table/mod.rs | 2 +- 7 files changed, 34 insertions(+), 33 deletions(-) diff --git a/src/db/db_format.rs b/src/db/db_format.rs index 1af9eef..7dccd97 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 5713d19..ad6079b 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 3aa9b0c..564b772 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 d5f8b81..a58922a 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 c5a5932..524c324 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 9a64d4b..d956954 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 a91ce21..d0e0157 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 -- Gitee