Hash Table?

BlitzMax Forums/BlitzMax Programming/Hash Table?

Gabriel(Posted 2007) [#1]
Does anyone have a good hash table implementation they would like to share? I need an implementation which permits multiple identical keys to co-exist, and that permits iteration with EachIn.

I know that writing one is neither particularly difficult or particularly time consuming but testing and tweaking one might well be and I've spent ( arguably too much ) time reinventing the wheel just lately so if I can possibly save some time here and there, I would like to do that.


tonyg(Posted 2007) [#2]
There's this and this


Gabriel(Posted 2007) [#3]
Aha, nice one. I found the one from SoS and Def's original, but neither implements an iterator as far as I could see, but I completely missed Noel's and his does have an iterator, so I think that should be fine.

Thanks for that!


slenkar(Posted 2007) [#4]
didnt know you used a special table just for a toke


SculptureOfSoul(Posted 2007) [#5]
Aha, nice one. I found the one from SoS and Def's original, but neither implements an iterator as far as I could see, but I completely missed Noel's and his does have an iterator, so I think that should be fine.

Thanks for that!


I didn't include EachIn support, although multiple keys with the same name are possible. You just call "InsertEntry" with a key that already exists, and the entry will be added to a list. Then, when you want to retrieve the multiple entries you call GetMultipleEntries( "keyname" ), which returns an object array. You can then iterate through the returned object array as needed.

You can also force entries to be unique, either by object or by key, by using InsertUniqueNamedObject, or InsertUniqueName(). Hopefully those function names are correct - I've changed the code a lot since then but haven't gotten around to uploading the new code.

Another thing you can even do with my hash table is insert an object with an identical key as others, and assign it a "priority" - and then it will be automatically sorted in the list it is stored on based on its priority. This functionality is probably rarely useful, but I needed it to allow certain functions (stored in the hashtable) to supercede or sometimes even mask others, and so added the functionality.

The only functionality that isn't working in the code for my hash table is the table does not automatically grow after reaching some kind of threshold. The Grow() function works, but it must be called manually. Of course, it doesn't freak out on hash collisions, but using a table that is far too small for the job is going to cost you some performance.