Closed zhenchengdezhichi closed 8 years ago
哈希表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; }
English please?
哈希表rebuild的时候为什么指针每一个都去移动一遍,只需要把头指针变更一下就可以了 应该。 for (TableEntry* oldChainPtr = oldBuckets; oldSize > 0; --oldSize, ++oldChainPtr) { for (TableEntry* hPtr = oldChainPtr; hPtr != NULL; hPtr = oldChainPtr) { oldChainPtr = hPtr->fNext;
} 这段是否可以改成 int i = 0 ; for (TableEntry* oldChainPtr = oldBuckets; i < oldSize; ++i, ++oldChainPtr) { fBuckets[i ]=oldChainPtr; }