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

Started by
6 comments, last by SiCrane 17 years, 10 months ago
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
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.
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
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.
I do not whant to use the STL map, just because i whant to use my own library with my own data types ...


:)

thankx
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.
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?
If you insist on doing this yourself (hopefully only for learning purposes) you should probably start with an unbalanced binary search tree.

This topic is closed to new replies.

Advertisement