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

hashtable rebuild() #9

Closed
zhenchengdezhichi opened this issue Oct 19, 2016 · 1 comment
Closed

hashtable rebuild() #9

zhenchengdezhichi opened this issue Oct 19, 2016 · 1 comment

Comments

@zhenchengdezhichi
Copy link

哈希表rebuild的时候为什么指针每一个都去移动一遍,只需要把头指针变更一下就可以了 应该。
for (TableEntry** oldChainPtr = oldBuckets; oldSize > 0;
--oldSize, ++oldChainPtr) {
for (TableEntry* hPtr = *oldChainPtr; hPtr != NULL;
hPtr = *oldChainPtr) {
*oldChainPtr = hPtr->fNext;

  unsigned index = hashIndexFromKey(hPtr->key);

  hPtr->fNext = fBuckets[index];//插入在前面的单链表
  fBuckets[index] = hPtr;
}

}
这段是否可以改成
int i = 0 ;
for (TableEntry** oldChainPtr = oldBuckets; i < oldSize;
++i, ++oldChainPtr) {
fBuckets[i ]=*oldChainPtr;
}

@tetherit
Copy link
Contributor

tetherit commented Nov 1, 2016

English please?

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

1 participant