1

I was reading the source code of the dictionary and came across the resize method. I saw the formula temp = (currentSize * 2), currentSize = GetNextPrimalNumber(temp). Why we must to set primal number as a dictionary size? https://referencesource.microsoft.com/#mscorlib/system/collections/generic/dictionary.cs,440

Can somebody explain why we should use primal numbers as a size of dictionary? Thanks a lot !

phuclv
  • 37,963
  • 15
  • 156
  • 475
QQQQq
  • 25
  • 4
  • Look at line 356. A dictionary key must be unique. If you have 8 bits for the key you only have 256 unique values. When you add the 257 value you must increase the size of the key to 9 bits. – jdweng Oct 30 '22 at 20:25

0 Answers0