top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration

Unique hash function for every tweet in Twitter?

+1 vote

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 Google+ Share Button LinkedIn Share Button Multiple Social 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)

 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...

Contact Us
+91 9880187415
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Karnataka INDIA.