Unique hash function for every tweet in Twitter?

+1 vote
610 views

This was asked today in interview any pointer.

"Design a unique hash function for every tweet in Twitter"

posted Oct 4, 2015

The unique hash function or unique index mapped from the key (twitter tweets )?
Finding the unique hash function ? I don't think so if yes please let me know.
I think it should be simple i.e. finding the hash function for the "string in tweet + user_handle" (two people can have same tweet but should have different index). Then we need to handle the exceptions i.e. retweet etc.

+1 vote

What you need is hash function which takes input as string and userhandle (original person who tweeted the matter). Rest is simple (handle the collision in the hash) -

Modified sdbm

``````static unsigned long sdbm(unsigned char *tweet, unsigned char *handle)
{
unsigned long hash = 0;
int c;
while (c = *tweet++)
hash = c + (hash << 6) + (hash << 16) - hash;

while (c=*handle++)
hash = c + (hash << 6) + (hash << 16) - hash;

return hash;
}
``````
Similar Questions
+1 vote

I'm looking for a hash function and a related function or operator such that:

`````` H(string1 . string2) = f(H(string1), H(string2))
H(string1 . string2) = H(string1) op H(string2)

where:
H() is the hash function
string1 is a string
string2 is a string
. is the string concatenation operator
f() is a function
op is a binary operator
``````

Any suggestions?