Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 [Module] Dictionary
Index -> Programming, Turing -> Turing Tutorials
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Aange10




PostPosted: 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:

code:

initialize (number_of_buckets) = Needs to be called after making the dictionary. Takes in a number of buckets parameter.
add (key, value : string) = Adds a key and value pair
remove (key)  = Removes a key and value pair
getValue (key) = Get's the value of a given key
containsKey (key) = Tells whether the key is in the dictionary


It's worth noting that if a key/value pair is added and the key already exists, the value will be over written.

Enjoy.



dictionary.rar
 Description:

Download
 Filename:  dictionary.rar
 Filesize:  1.73 KB
 Downloaded:  409 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> Programming, Turing -> Turing Tutorials
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 1 Posts ]
Jump to:   


Style:  
Search: