question about string hash function

Discussion in 'Programmer's Corner' started by moslem, Jul 10, 2010.

  1. moslem

    moslem Thread Starter New Member

    Joined:
    Dec 16, 2009
    Messages:
    20
    Hello every one,
    i've a string hash function it's performace is already good but there is some things that happens inside it and idon't know why
    the hash function:
    unsigned int table::hash(const string &word)
    {
    int hash = 0;
    int n=word.length();
    for(int i=0;i<n;i++)
    hash = 31*hash+word;
    return hash % MAX_TABLE;
    }
    my questions about it
    why we multiply by 31 the hash every time is this for making weighting for the characters or any thing else?
    thanks inadvance.
     
  2. Harrington

    Harrington New Member

    Joined:
    Dec 19, 2009
    Messages:
    86
    Location:
    London
    moslem likes this.
  3. Papabravo

    Papabravo AAC Fanatic!

    Joined:
    Feb 24, 2006
    Messages:
    7,698
    Location:
    Michigan, USA (GMT-5)
    moslem likes this.
Loading...

Share This Page