Click to See Complete Forum and Search --> : Looking for some structure like a tree ...


Recrehal
October 5th, 2005, 01:14 PM
I'm looking for a structure, something like a tree or map, which allows me to check if a key is in there but also if the path to it matches in a specific order. Think of "hello". I'd like to know that the o is in the map but also that I've chosen the path "h" "e" "l" "l" "o" to get there. I'm not sure what structure I can use for this.

background: I want a tree of commands that will be read character by character out of a file. To avoid searching for every possible command, I'd like to speed things up by narrowing down the path in a tree. So the tree could consists of the three commands "hello1", "hello2" and "test".

Actually I would only need to store the position in the tree and check if the siblings have the next character. As the key would be unique the position would also be unique. So if you can store a position in a STL map and access the siblings let me know. The tree can't be binary.

wschweit
October 5th, 2005, 01:42 PM
Sounds like you need to use a Trie or something related.

http://www.csse.monash.edu.au/~lloyd/tildeAlgDS/Tree/Trie/

Recrehal
October 6th, 2005, 04:58 AM
That's pretty much what I'm looking for. Is it implemented in the STL or somewhere else or would I have to do it myself?

wschweit
October 6th, 2005, 10:49 AM
I googled "C++ trie library" and picked this out:

http://www.codeproject.com/cpp/Jumble.asp

It looks like it may at least give you something to work with.