Page 1 of 1

Managing Many Nodes

Posted: Sat Mar 27, 2004 1:13 pm
by Guest
In my level i have player models spawn according to the settings in an xml file. so the number of them is always changing. one of the options in the xml file is to give each node a name. how can i manage them all?. i want to be able to access a particular one, when i knoe only its name.

i though i could use a linked list, but does this mean that every time i want to access a node i have to search through every node in the list to find it?

is there any faster, more efficient way of doing this? thanks

Posted: Sat Mar 27, 2004 1:48 pm
by nebukadnezzar
i think the fastest way is using a sorted linked list
using quicksort and binary search.
(or use a tree instead)

Posted: Sat Mar 27, 2004 2:24 pm
by Guest
So if i used a sorted linked list, i could just search through nodes beginning with the letter i wanted? is this what u mean?

btw: thanks for the quick reply

Posted: Sat Mar 27, 2004 3:03 pm
by nebukadnezzar
you could do so
but binary search means

pick the item in the middle..
if it equal to the search value abort and return the value.
if it's less take the middle of the upper half
if not the middle of the lower half
..and now recurse to the beginning ...

Posted: Sat Mar 27, 2004 3:11 pm
by Guest
oh cool. i see.
thanks

Posted: Sat Mar 27, 2004 5:53 pm
by rebecca
hi
i use the map of the standard template library for this.
heres how you do it:

#include <map>

typedef std::map<std::string, irr::scene::ISceneNode*> NodeMap

NodeMap nodes;

// insert, make sure name is unique!!!!
void insertNode(const char* name, irr::scene::ISceneNode* node)
{
nodes[name]=node;
}

// lookup
irr::scene::ISceneNode* getNode(const char* name)
{
return nodes[name];
}

// remove
void removeNode(const char* name)
{
NodeMap::iterator iter=nodes.find(name);
if(iter!=nodes.end())
{
irr::scene::ISceneNode* node=(*iter).second;
node.remove();
nodes.erase(iter);
}
}

regards
rebecca

Posted: Sun Mar 28, 2004 4:25 am
by Guest
perfect :D

Posted: Sun Mar 28, 2004 1:16 pm
by nebukadnezzar
is there a way to use regular expressions in a map with string as key value

Posted: Wed Mar 31, 2004 11:45 am
by Guest
hi nebukadnezzar

not directly. you have to use your own comperator class. google for std map maybe you'll find something usefull

regards
rebecca

Posted: Wed Mar 31, 2004 1:54 pm
by nebukadnezzar
i know but is there a comparator for this?
(and one where i don't need to link a big library)
at the moment i've written a comparator which compares only the first characters until it reaches the '*'.
Thats not truly regexp but it satisfies al my needs atm.

Posted: Fri Apr 02, 2004 10:04 am
by Guest
regexp from boost should be fairly small. don't know of any other

regards
rebecca