Jump to content
  • Advertisement
Sign in to follow this  
ClementLuminy

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

This topic is 4362 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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!