question about string hash function

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

  1. moslem

    Thread Starter New Member

    Dec 16, 2009
    20
    0
    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

    New Member

    Dec 19, 2009
    86
    3
    moslem likes this.
  3. Papabravo

    Expert

    Feb 24, 2006
    9,409
    1,542
    moslem likes this.
Loading...