Skip to content

Commit

Permalink
bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
eric committed Mar 19, 2024
1 parent bbb1cab commit 4958700
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions kr2r/src/compact_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,9 +346,7 @@ where
// 哈希表的容量
pub config: HashConfig<B>,
pub table: &'a [B],
pub page_data: &'a [B],
pub page_index: usize,
pub page_size: usize,
pub page: Page<B>,
}

impl<'a, B> CHTable<'a, B>
Expand All @@ -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::<B>::new(page_index, page_size, page_data);
let page_data = table[start_index..end_index].to_vec();
let page = Page::<B>::new(page_index, page_size, page_data);

let chtm = CHTable {
config,
table,
mmap,
page_data,
page_index,
page_size,
page,
};
Ok(chtm)
}
Expand All @@ -402,17 +398,17 @@ 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
{
return cell.right(value_mask);
}

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 {
Expand All @@ -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
{
Expand Down

0 comments on commit 4958700

Please sign in to comment.