Skip to content

Commit

Permalink
Added Compute_Hash function
Browse files Browse the repository at this point in the history
  • Loading branch information
rsd511 committed Jun 7, 2020
1 parent 7ce6d9a commit b5dc61c
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions String/hashComputer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
ll compute_hash(string& s) {
ll p = 31;
ll m = 1e9 + 9;
ll hash_value = 0;
ll p_pow = 1;
fa(c,s) {
hash_value = (hash_value + (c - 'a' + 1) * p_pow) % m;
p_pow = (p_pow * p) % m;
}
return hash_value;
}

0 comments on commit b5dc61c

Please sign in to comment.