mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-14 07:24:52 +09:00
Moved string hashing function away from main files
This commit is contained in:
1 parent
27665b8e93
commit
339f38c1b0
2 files changed
+62
No files matched your search
@@ -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,
|
||||
}
|
||||
Reference in new issue
Block a user