Is there are any protection from possible infinity loop in hashmap, if mod of a newly pushed key points to the bucket that already have maximum items amount, several (possible infinite) times in a row consecutively?
What I mean is:
(Hashed) key 'X' are pushed into hashmap. It mod to the 'B' (map buckets count) is 'b'.
Bucket number 'b' have 'N' items in it, which equal to the maximum allowed amount of items per bucket. So hashmap resizes to 'B + 1' size and move all stored elements to corresponding buckets by mod keys of elements with new map buckets count.
It tries to mod 'X' again for 'B+1'. New value is 'c'. However, bucket number 'c' have 'N' elements. Hashmap resizes to 'B+2' and move stored elements.
It tries to mod 'X' again for 'B+2'. New value is 'd'. However, bucket number 'd' have 'N' elements. Hashmap resizes to 'B+3' and move stored elements.
It tries to mod 'X' again for 'B+3'. New value is 'e'. However, bucket number 'e' have 'N' elements. Hashmap resizes to 'B+4' and move stored elements.
It tries to mod 'X' again for 'B+4'. New value is 'f'. However, bucket number 'f' have 'N' elements. Hashmap resizes to ...and so on.
Intuitively it feels that chance that it will happens even 2 times in a row are pretty low...but it not equal to zero. So is there are a way to prevent it from happening?
Or crossing fingers and hope for the best is an only options here, without sacrificing speed/performance?