I’m looking for a good hash utility or framework to map the string to some int value in range say {1 .. k}
I should use it in the runtime component that receives a lot of concurrent requests from users with ‘userId’ that is string and i want to map that value to defined integer range.
Of course the length of the userId value could be different but it is ok with me to assumt on some minimum lenght for using this function
It should be very fast
Thanks
Every Java object has a builtin
hashCodemethod, which returns anint. ForStringit is pre-defined for you (it needs to be implemented for custom objects).To map this to
1..k, where k is an integer, consider using the modulus: