Now it's time to apply our new knowledge about hash tables and algorithms.
Create your own hash class and algorithm from scratch. You can use the one we created a few lessons ago as a template - but the next step is to improve it further. Use a TDD approach to build out your class and methods.
The hash table should have the following methods:
HashTable.prototype.set(): Should add a key-value pair to the hash table.
HashTable.prototype.get(): Should get a key-value pair from the hash table. Try incorporating a linked list!
HashTable.prototype.remove(): Should remove a key-value pair from the hash table.
HashTable.prototype.clear(): Should clear all key-values from the hash table.
HashTable.prototype.hash(): The hash is the most important part!
HashTable.prototype.hash() method, you can try the following:
Try out the DBJ2 hashing algorithm. Make your own modifications such as applying bitwise manipulation in a different way.
More difficult: Add a
HashTable.prototype.resize() method will need to create a new array and then use the updated hashing algorithm to recalculate where all the key-value pairs should go in the new array.
Try making your own (probably not so) secure hashing algorithm. Once again, use a TDD approach.
"bat"are passed into the algorithm. How different are the two hashes? You should also try to avoid symmetry - which means that
"tab"could end up with the same hashes because they have the same characters. So the order of characters in your hashing algorithm also matters!
Use a whiteboard to diagram how a hash table works. You may use code and illustrations. For instance, you might want to visually illustrate how a hashing algorithm maps a key to an array's index. Prepare your explanation as if you are describing hashing algorithms to someone that only knows the basics of coding (such as arrays and functions).
Lesson 7 of 7
Last updated more than 3 months ago.