From 4958700d6d8430967a94d89d1f31e179e11b7825 Mon Sep 17 00:00:00 2001 From: eric Date: Wed, 20 Mar 2024 07:21:52 +0800 Subject: [PATCH] bug fix --- kr2r/src/compact_hash.rs | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/kr2r/src/compact_hash.rs b/kr2r/src/compact_hash.rs index 2f2623d..f0b9024 100644 --- a/kr2r/src/compact_hash.rs +++ b/kr2r/src/compact_hash.rs @@ -346,9 +346,7 @@ where // 哈希表的容量 pub config: HashConfig, pub table: &'a [B], - pub page_data: &'a [B], - pub page_index: usize, - pub page_size: usize, + pub page: Page, } impl<'a, B> CHTable<'a, B> @@ -374,16 +372,14 @@ where return Err(Error::new(ErrorKind::Other, "out of capacity")); } - let page_data = &table[start_index..end_index]; - // let page = Page::::new(page_index, page_size, page_data); + let page_data = table[start_index..end_index].to_vec(); + let page = Page::::new(page_index, page_size, page_data); let chtm = CHTable { config, table, mmap, - page_data, - page_index, - page_size, + page, }; Ok(chtm) } @@ -402,7 +398,7 @@ where let first_idx = idx; loop { - if let Some(cell) = self.page_data.get(idx) { + if let Some(cell) = self.page.data.get(idx) { if cell.right(value_mask) == B::default() || cell.left(self.config.value_bits) == compacted_key { @@ -410,9 +406,9 @@ where } idx = idx + 1; - if idx >= self.page_size { + if idx >= self.page.size { // 需要确定在table中的位置, page index 从0开始 - let index = self.page_size * self.page_index + idx; + let index = self.page.size * self.page.index + idx; return self.get_from_table(index, compacted_key); } if idx == first_idx { @@ -432,7 +428,7 @@ where let first_idx = idx; loop { - if let Some(cell) = self.page_data.get(idx) { + if let Some(cell) = self.page.data.get(idx) { if cell.right(value_mask) == B::default() || cell.left(self.config.value_bits) == compacted_key {