concurrent-map icon indicating copy to clipboard operation
concurrent-map copied to clipboard

Add support for a custom number of shards for the map

Open kahuang opened this issue 6 years ago • 3 comments

This adds a new constructor to the ConcurrentMap that allows the user to pass in the number of shards we should shard the map to

kahuang avatar Aug 13 '18 17:08 kahuang

I have same idea with you that shard number matters. https://github.com/orcaman/concurrent-map/issues/71

CanoeFZH avatar Aug 14 '18 03:08 CanoeFZH

if you change the shard count dont you have to change the hash function params too? https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function#FNV_hash_parameters

benitogf avatar Dec 19 '20 05:12 benitogf

@benitogf No, not unless you create a huge number of shards. The FNV32 hash function just creates a 32 bit hash, which is a number between 0 and 4.29 billion. The code mods this hash by the number of shards, so if you used 100 or 200 shards you would still likely get good dispersion of the keys between the shards. Of course, if you want 4 billion shards (not recommended) then yes you should probably use a different hashing function like FNV128 etc.

westofpluto avatar Jan 03 '24 18:01 westofpluto