Why not distributed

is it right? since there is collision even after rehashing

yes your code is right

actually collision can’t be avoided only can be minimised