March 12th, 2013, 04:28 PM
Finding items (strings) in multiple lists
It's hard to give proper title for this topic but anyways..
Im working on a script compiler and i need to handle different types of data.
Actually different categories of items.
Let's say i have two categories: cat's and bird's. They are different and stored in different lists.
And let's say there is a simple command: GIVE_FOOD_TO(animal_type, food_type)
Animal type here can be either from birds category or cat's category.
And also let's say user gives command: GIVE_FOOD_TO(cat1, fish)
and also for example: GIVE_FOOD_TO(bird1, birdfood)
Variable names could be anything, but im storing each variable name in std::map so later i can figure out with what animal current command is used. You get the idea hopefully.
When im parsing the script then i must know if user supplied either cat or bird.
If i just would have cat's or bird's category then i would have only 2 lists and not a big problem to loop through either cats list or birds list and find out in what list the "cat1" is or in what particular list the "bird1" is. It would be in one or another.
But i have a lot of categories and looping through all of these lists (or std::maps) is slow and doesn't seem like a good idea. Just to find out in what list it's stored.
I can't rely on variable names, they could be anything.
So i need the ideas how to solve such a problem.
Big picture atm:
1) I have one BIG box which stores all of the categories
2) When i need to find out to which category the variable (animal_type) point's to i must get it quickly, dunno, std::map in std::map or something?
What i need basically is:
I have different lists (each one is just a category for either birds or cats in this example)
And when i have variable name, i must find out quickly in what particular category this item is stored. So i can work with it.
If it's confusing then i will try to explain more.
Thanks in advance for any tips, hints, ideas.
Last edited by BytePtr; March 12th, 2013 at 04:31 PM.
Rate my post if i it was useful!
Click Here to Expand Forum to Full Width
This is a CodeGuru survey question.