sb-js-data-structures
Advanced tools
Comparing version 1.0.7 to 1.0.8
{ | ||
"name": "sb-js-data-structures", | ||
"version": "1.0.7", | ||
"version": "1.0.8", | ||
"repository": { | ||
@@ -19,2 +19,3 @@ "type": "git", | ||
"linked list", | ||
"doubly linked list", | ||
"bst", | ||
@@ -21,0 +22,0 @@ "binary search tree", |
@@ -13,4 +13,17 @@ const KEY = 0 | ||
public hash = (key: string) => key.toString().length % this.size | ||
public hash = (key: string) => { | ||
let hash = 0 | ||
if (key.length == 0) { | ||
return hash | ||
} | ||
for (var i = 0; i < key.length; i++) { | ||
var char = key.charCodeAt(i) | ||
hash = (hash << 5) - hash + char | ||
hash = hash & hash // Convert to 32bit integer | ||
} | ||
return hash % this.size | ||
} | ||
public insert = (key: string, value: T) => { | ||
@@ -17,0 +30,0 @@ const index = this.hash(key) |
606393
1550