Sign in to follow this  

Which Data Structure to associate string and value????

This topic is 4197 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello. I need some advices: In my program, i use a data structure ( actually the STL map container ) to associate a string with an Handle . In the next version of my program, i cannot use the map structure, i need to recreate an other one ... I was thinking to use a kind of hash table with the string as key and the Handle as value, but i dont know which hash function to use to hash the string ... This container structure will be use in a ressource manager, to allocate on the fly, named ressource ( textures, 3d model ), and to retrieve the handle of the ressource giving it name.... If can help me ... :) Thanks a lot !! Clem

Share this post


Link to post
Share on other sites
You can use the simpliest hash function if you want, but you'll get more collisions. You can look up google for hash tables using chaining or open addressing.

Share this post


Link to post
Share on other sites
In, fact, i think the best solution for me is to use the same kinf of data structure is the stl map container ...

Can anybody tell me which algorithm is used internally into this structure ???

thanks

Share this post


Link to post
Share on other sites
The std::map container is some sort of balanced binary tree. Which kind is used is implementation specific, but is commonly a red-black tree. If you could explain why you can't use the std::map structure, then we might be able to give you better suggestions.

Share this post


Link to post
Share on other sites
If you are at a level of skill where you have to ask these sorts of questions, you *will* get it wrong trying to do it yourself. Trust me.

Share this post


Link to post
Share on other sites
Quote:
Original post by ClementLuminy
I do not whant to use the STL map, just because i whant to use my own library with my own data types...
Perhaps you could elaborate on that. It is the STL, after all; using your own data types should not be a problem. If you mean you want to use your own container classes, then again, do you have a particular reason for that?

Share this post


Link to post
Share on other sites
If you insist on doing this yourself (hopefully only for learning purposes) you should probably start with an unbalanced binary search tree.

Share this post


Link to post
Share on other sites

This topic is 4197 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this