diff --git a/include/unique_stack_table.h b/include/unique_stack_table.h index 329a534..ff48edf 100644 --- a/include/unique_stack_table.h +++ b/include/unique_stack_table.h @@ -128,7 +128,7 @@ private: uint32_t totalNodes_ = 0; // current available node count, include index 0 uint32_t availableNodes_ = 0; - uint32_t hashModulus_ = 0; + uint32_t hashModulus_ = 1; // 0 for reserved, start from 1 uint32_t availableIndex_ = 1; // for de-conflict diff --git a/src/unique_stack_table.cpp b/src/unique_stack_table.cpp index 6f7434f..8b4ffff 100644 --- a/src/unique_stack_table.cpp +++ b/src/unique_stack_table.cpp @@ -31,7 +31,7 @@ bool UniqueStackTable::Init() } availableNodes_ = totalNodes_; - hashModulus_ = availableNodes_ >= 1 ? availableNodes_ - 1 : 0; + hashModulus_ = availableNodes_ > 1 ? availableNodes_ - 1 : 1; hashStep_ = (totalNodes_ / (deconflictTimes_ * HASH_STEP_BASE_MULTIPLE + HASH_STEP_BASE_NUM)); tableBuf_ = std::make_unique(tableSize_); @@ -71,7 +71,7 @@ bool UniqueStackTable::Resize() availableIndex_ += availableNodes_; totalNodes_ = ((newtableSize / sizeof(Node)) >> 1) << 1; // make it even. availableNodes_ = totalNodes_ - oldNumNodes; - hashModulus_ = availableNodes_ >= 1 ? availableNodes_ - 1 : 0; + hashModulus_ = availableNodes_ > 1 ? availableNodes_ - 1 : 1; hashStep_ = availableNodes_ / (deconflictTimes_ * HASH_STEP_BASE_MULTIPLE + HASH_STEP_BASE_NUM); HLOGI("After resize, totalNodes_: %u, availableNodes_: %u, availableIndex_: %u hashStep_: %" PRIu64 "", totalNodes_, availableNodes_, availableIndex_, hashStep_);