I am learning programming abstract data types. Trying to build custom hash table based dict.
SO far I’ve created a class place holder.
public class HashMapDict implements IDict
{
private var _map:Array;
public function HashMapDict()
{
_map = new Array();
//TODO: implement function
}
public function set(keys:Array):Boolean
{
// 1. For each key in array of keys
// 2. Pass Key.key to hash function
// 3. Write Key to _map[hash(Key.key)]
return true;
}
}
I see the main method set doing the following
// 1. For each key in array of keys
// 2. Pass Key.key to hash function
// 3. Write Key to _map[hash(Key.key)]
What I am thinking about is to use cryptography libs for hash generation. But I am a bit confused with how it should work. e.g. Tried to look on several libs like as3crypto (http://crypto.hurlant.com/demo/) and it seems to produce hash in a way I don’t really think can be used for indexes in arrays.
E.g.
http://screencast.com/t/bE1lYQEqp4D
Can you advise which lib can I use to generate usable hashes? and how should they look like
For implementation of a hash table, a cryptographic hash function is overkill.
Use this only if you are concerned with an attack of someone who tries to feed you bad data (e.g. keys with lots of hash collisions) to make the hash table slow.
For a hash table use, a hash function like the following one is enough (pseudocode, as I don’t know the right syntax):
But as other answers said, there is already a hash table built in, and you don’t really need to reimplement it.