Jump to content
  • Advertisement
Sign in to follow this  
korvax

Need help structuring simple resource list

This topic is 2140 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

Hi, Im looking for a template resource list that, anyhow.

My problem is that I want the list to recognize if an item already already exist in it, and i was thinking that i might to this with a wstring name.

And rest of my program will access its resource by index in the list (and not name) thought that would be the fastest of "none pointer" solutions.

 

For

GenericList<Shader> shaderlist; 

position = shaderlist.add(pShader, "Shader")

 

So I have two questions,

I need a  dynamic container that can grantee the indexes of all the resource when an object is remove from the list, as I understands it std::vector does not do this, and array is not std::dynamic.

 

Secondly, Should I store the resource and name as a pair in that container or should I do it in two containers one resource and one for name, where the indexes are matching all the time. Not sure what will be most efficent?

 

thx

Share this post


Link to post
Share on other sites
Advertisement

It looks like you need two containers:

* One that knows the list of names that already exist (perhaps std::unordered_set<std::wstring>, or perhaps std::unordered_map<std::wstring,int>, since you probably want to be able to recover the index from the name) and

 * one to associate an integer index to an object (std::unordered_map<int,MyClass> or std::map<int,MyClass>, depending on whether preserving the order is important for anything).

Share this post


Link to post
Share on other sites

It looks like you need two containers:

* One that knows the list of names that already exist (perhaps std::unordered_set<std::wstring>, or perhaps std::unordered_map<std::wstring,int>, since you probably want to be able to recover the index from the name) and

 * one to associate an integer index to an object (std::unordered_map<int,MyClass> or std::map<int,MyClass>, depending on whether preserving the order is important for anything).

"Can all of them guarantee the insertion order is that what unordered means?" -- disregard this.. 

I see what you mean now.. But why use unordered and not plain hashmaps for instance?

Edited by korvax

Share this post


Link to post
Share on other sites

std::map is some type of sorted binary tree. std::unordered_map is actually a hash. So their implementations are quite different, but the most obvious difference is that std::map keeps the elements sorted by key, while the std::unordered_map does not. Similarly for std::set and std::unordered_set.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!