1/3 Test Cases Passed
You need to earn 2 or 3 stars in order to submit.
1/3 Test Cases Passed
You need atleast 2 stars to grade your answer.
class Hash { //when initialized, creates N buckets in the array. Have it store an empty singly linked list constructor(n) { this.buckets = []; this.total_buckets = n; for(var i=0; i<n; i++){ this.buckets.push(new SLL()); } } //based on the key, have it return the appropriate index to look hash_function(key){
} //generates a hash number given a string _generate_hash(str){ let hash = 0; if (str.length == 0) return hash; for (let i = 0; i < str.length; i++) { let char = str.charCodeAt(i); hash = ((hash<<5)-hash)+char; hash = hash & hash; // Convert to 32bit integer } return hash; } } class SLL { constructor(){ this.head = null; } } //create a hash map with 256 buckets let hash_map = new Hash(256);
Test Cases (0/3)
-
hash_map.hash_function("hackerhero") to return 136
-
hash_map.hash_function("codingdojo") to return 134
-
hash_map.hash_function("datacompass") to return 40