Computer Science Canada [Module] Dictionary |
Author: | Aange10 [ Fri Jul 27, 2012 2:11 am ] | ||
Post subject: | [Module] Dictionary | ||
For those who are interested, I wrote this module to provide a hash table type easily. I got tired of writing a new one in every program, so I figured I'd make it a class. It's a very basic implementation, but it seems to be more than sufficient to me (about 10x faster than searching an array, in my programs anyways). The algorithm is very simple; ord the values of the key, add them together and mod it by the number of buckets == your bucket number. Then it just searches for your key. Anyways, the basic functions are:
It's worth noting that if a key/value pair is added and the key already exists, the value will be over written. Enjoy. |