string-hash.c
unsigned long int Str_Hash(char *str, unsigned long int cap) {
    const int p = 31;
    unsigned long int index = 0;
    int len = strlen(str);
    unsigned long long pow = 1;
    for (int i = 0; i < len; i++) {
        index = (index + (str[i] - 'a' + 1) * pow) % cap;
        pow = (pow * p) % cap;
    }

    return abs(index);
}
//Hashes using the given string. Horner Hash.
Hashes using the given string. Horner Hash.
Hashes using the given string . Horner Hash .
unsigned long int Str_Hash(char *str, unsigned long int cap) {
    const int p = 31;
    unsigned long int index = 0;
    int len = strlen(str);
    unsigned long long pow = 1;
    for (int i = 0; i < len; i++) {
        index = (index + (str[i] - 'a' + 1) * pow) % cap;
        pow = (pow * p) % cap;
    }
    return abs(index);
}
unsigned long int Str_Hash ( char * str , unsigned long int cap ) { const int p = 31 ; unsigned long int index = 0 ; int len = strlen ( str ) ; unsigned long long pow = 1 ; for ( int i = 0 ; i < len ; i ++ ) { index = ( index + ( str [ i ] - ' ' + 1 ) * pow ) % cap ; pow = ( pow * p ) % cap ; } return abs ( index ) ; }
Hashes using the given string.
Hashes using the given string .