top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Unique hash function for every tweet in Twitter?

+1 vote
1,437 views

This was asked today in interview any pointer.

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

posted Oct 4, 2015 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button
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 Answer

+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;
}
answer Oct 5, 2015 by Salil Agrawal
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?

+2 votes

How do I switch to a hash on a branch without creating moving to a new branch? Say I'm currently at the HEAD of master, and its hash is aaa. I want to stay on master, only switch to a previous hash... (say eee...)

I know I can use the HEAD~ or whatever, but I'd like to find out how to do it based only on a hash...

...