This is a basic hashtable implementation I threw together in about 30 mins. 1) Green flag 2) Click "Add Value" to enter some keys and values 3) Click "Get Value" to recall a value 4) Green flag to reset The hashtable list holds indices to the heap. The heap holds the keys and values, and the index to the next key-value pair with the same hash, in case of hash collision (it's a basic linked-list). To add or get a value, its hash is computed mod the length of the hashtable, and then the resulting number is used as the index, making the hashtable more efficient than brute-force looping a list for large lists. For a small amount of collisions, the time complexity for add and remove is almost O(1)
Thanks to http://stackoverflow.com/questions/2962207/constructing-a-hash-table-hash-function for the hash function Pros: - It has a pretty good hash function - It handles collisions well - It's pretty fast (even without turbo mode or screen refresh) Cons: - Case insensitive due to Scratch being Scratch. I'm too lazy to implement the costume hack right now - It doesn't support removing items yet - It supports a limited charset. You can add more characters to the ALPHABET variable though - The UI is bad. I threw it together in 5 secs because I didn't have paint.net on hand to make good buttons or graphics