Moved string hashing function away from main files

This commit is contained in:
Danielv123 committed 2017-09-19 08:35:55 +02:00
1 parent 27665b8e93
commit 339f38c1b0
2 files changed
+62

No files matched your search

+14
View File
@@ -0,0 +1,14 @@
function hashCode(string){
if(typeof string !== "string") throw "ERROR: Not a string";
var hash = 0;
if (string.length == 0) return hash;
for (let i = 0; i < string.length; i++) {
char = string.charCodeAt(i);
hash = ((hash << 5) - hash) + char;
hash = hash & hash; // Convert to 32bit integer
}
return hash;
}
module.exports = {
hashCode: hashCode,
}