void SeparateChainingHash::PrintInfo() const { size_t maxChainSize = GetChainSize(pChains[0]); size_t sumOfSizes = maxChainSize; size_t minChainSize = maxChainSize; for (size_t i = 1; i < ChainsCount; i++) { size_t size = GetChainSize(pChains[i]); sumOfSizes += size; maxChainSize = std::max(maxChainSize, size); minChainSize = std::min(minChainSize, size); } size_t memoryUsed = sizeof(*this) + // object size sizeof(Box*) * ChainsCount + // vector of lists sumOfSizes * sizeof(Box); // Nodes allocated for the lists size_t dataSize = sumOfSizes * sizeof(int); size_t overhead = ((memoryUsed - dataSize) * 100) / memoryUsed; std::cout << "SeparateChainingHashStl stats:" << "\n - Max chain size: " << maxChainSize << "\n - Avg chain size: " << (sumOfSizes / ChainsCount) << "\n - Min chain size: " << minChainSize << "\n - list node size: " << sizeof(Box); PrintCommonInfo(sumOfSizes, memoryUsed); }
int GetChainSize( signed char myGrid[kGridAcross][kGridDown], int x, int y, int color ) { int total; if( (x<0) || (x>=kGridAcross) || (y<0) || (y>=kGridDown) ) return 0; if( myGrid[x][y] != color ) return 0; myGrid[x][y] = -color; total = 1 + GetChainSize( myGrid, x-1, y, color ) + GetChainSize( myGrid, x+1, y, color ) + GetChainSize( myGrid, x, y-1, color ) + GetChainSize( myGrid, x, y+1, color ); return total; }
int SizeUp( signed char myGrid[kGridAcross][kGridDown], int x, int y, int color ) { int total; total = GetChainSize( myGrid, x, y, color ); CleanSize( myGrid, x, y, color ); return total; }