Monday, August 11, 2008

Implementing Dictionary in C++

Working with C#, I loved the feature of the data-type : Dictionary. I was wondering how we can implement a Dictionary in C++.

Heres what could be a way out...

1. Following the C# implementation as the model, we create a class having two elements : key and value, and implement it as a doubly linked-list. This will optimize structure parsing of the dictionary.

2. We can use Templates to make it a case with generic key and value types.

3. Another internal optimization would be to use hash.

4. Sort the dictionary based on the key values.

5. Provide functions to set and unset key-value pair.
--As I noticed that dictionary is immutable during access, provide a stack say _keys_to_delete on top of which we can push the keys of entries to be deleted. Implement a garbage collection of sorts that runs a loop to delete the entries based on the keys found in the stack _keys_to_delete after the dictionary has finished iterative access (so that it again becomes mutable)...

14 comments:

Jose said...

typedef map &lt string, string &gt Dictionary;

Jose said...

typedef std::map <string, string> Dictionary;

amigo said...
This comment has been removed by the author.
amigo said...

recommend you to look at this - http://code.google.com/p/google-sparsehash/

this is hash map

Husain and saif said...

First I want to congratulate you for this amazing blog!
We Are Pleased To Announce The Launch Of Movies Gallery 08, Mobile Movies in 3gp format, Reality show, Funny Video, Upcoming Movies 08 Trailer, About Dubai,Real Estate, Tips Of Career And Many More.

To start just go to http://moviesvideo.blogspot.com/

We hope you like it. Please send us any feedback on the movies and help us improve the sites further.

Hapi said...

Hello.. Do you know how to Add Adsense Code Inside Single Post Only in XML Template? Visit your blog to learn how.. Have a nice thursday!

Nicole said...

Download Full Version Software at AriesGames... http://ariesgames.blogspot.com

QuackWare said...

Cool Stuff, can you check out my C++ Code Samples too?

Anabel said...

muy interesante su articulo! :):):):):):)

Martin said...

like jose already said, you are talking about a hashmap and it's been in the stl since the very beginning...

Naeem Akram Malik said...

I think std::map does a good job...

ali said...

telecharger turbo c gratuit
turbo c logiciel gratuit

manish gupta said...

thanx for the information..more more details visit www.studentluv.com

Annie said...

Thank you for your whole labor on this web page. I love working on research and it’s really simple to grasp why. I notice all of the dynamic mode you present both useful and interesting tricks through this blog and therefore encourage contribution from other ones on the concept. Without a doubt i become educated in lot of things.
external hard drive recovery