Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

一些疑问 #1

Open
Yang6149 opened this issue May 23, 2020 · 4 comments
Open

一些疑问 #1

Yang6149 opened this issue May 23, 2020 · 4 comments

Comments

@Yang6149
Copy link

  1. 在linear_probe_hash_table.cpp 71行,求BlockIndex我认为应该是auto targetBlockIndex = (mmHash%headerPage->GetSize()) / BLOCK_ARRAY_SIZE;
  2. 如果在插入相同Key时,键值对横跨了两个Block要怎么解决?
@carlclone
Copy link
Owner

  1. 新的代码没push上来
    auto targetBlockIndex = mmHash & headerPage->GetSize();这个定位元素在哪个blockPage
    auto targetSlotIndex = mmHash % BLOCK_ARRAY_SIZE; 这个定位元素在slot数组(blockPage里)的哪个位置

2.我的实现里没解决这个,课程似乎没要求实现 , 但应该是要在当前page里存储一个指向下一个page的指针吧

@Yang6149
Copy link
Author

headerPage->GetSize() 指的是整个Hash表能容纳的KV对个数。所以mmHash & headerPage->GetSize()应该是该键值对全局的位置,而不是所在的Block的位置。以下是我的实现

  auto hashV = hash_fn_.GetHash(key);
  auto gloIndex = hashV % header->GetSize();
  auto blockIndex = gloIndex / BLOCK_ARRAY_SIZE;
  //auto curBlockIndex = blockIndex;
  auto slotIndex = gloIndex-blockIndex*BLOCK_ARRAY_SIZE;

@Yang6149
Copy link
Author

方便加以下联系方式讨论以下吗?QQ:614989768

@carlclone
Copy link
Owner

不是GetSize(),是NumBlocks() , 记错了, 最近写CS144的lab去了 , 这门课测试用例有点少所以没啥动力往后坐了 , 晚上push一下
auto targetBlockIndex = mmHash & headerPage->NumBlocks();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants