Bloomberg LP Interview Question
Financial Software DevelopersCountry: United States
Interview Type: Phone Interview
i have used the following method for storing names in a hash if names are like this...siva12..rama13.etc..not sure if this is sufficient for pure names(strings)..of course not
int hash_name(char *str) {
int n=0;
int index = 0;
int ch = 0;
while(*str++) {
ch = *str & 0xFF;
if (ch >= 0 && ch <= 9) {
n = (n * 10) + ( ch -'0');
else
c = c ^ ch;
}
index= ((c ^ n) & 0xFF ) % HASHMASK;
return index;
}
Names cannot be unique. So in the absence of another unique identifier (such as SSN or biometric data) it is not possible to avert hash collisions.
- Ashish Kaila November 23, 2011