mirror of
https://github.com/TheAlgorithms/C
synced 2024-11-22 05:21:49 +03:00
improved hash code function
I improved the hash code function
This commit is contained in:
parent
df5d9d63c3
commit
c26124199f
@ -43,6 +43,12 @@ int get_hash(char s[])
|
||||
hash_code = s[counter] + (hash_code << 6) + (hash_code << 16) - hash_code;
|
||||
}
|
||||
|
||||
/*
|
||||
make sure hash_code is always positive.
|
||||
because we want uses it as index
|
||||
*/
|
||||
hash_code = (hash_code < 0) ? hash_code * -1 : hash_code;
|
||||
|
||||
/* % modulo is for fitting the index in array. */
|
||||
return hash_code % MAXELEMENTS;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user