Re:String.hashCode() is plenty unique
by FartyMcFarter on Sunday August 19, 2018 @10:35PM
(#17797383)
True - but I still don't think it's reasonable to assume that a hash function behaves that way.
Re:String.hashCode() is plenty unique
by iainmerrick on Saturday August 11, 2018 @03:29PM
(#17741144)
You could do that and also use a real hash for longer inputs.
Literally truncating the input wouldn’t be great in the likely case that your hash table is using only 10 bits (say) of the hash value, but I bet there are similar approaches that would work.
I can trivially write a hash function that produces a unique 32-bit hash for inputs of 32-bit. Just truncate the input to 32 bits. It's not a very good hash function for longer inputs, of course.