Personally I never use thread handling except as a way of doing intensive tasks without my GUI from locking up and people thinking the program froze. I'm also fairly certain windows hates multiple streams open to the same file at once. I ran into that issue with Eschaton since OSX doesn't care unless both streams are active or something similar.
This is the best I can do in generalized form:
Code: Select all
main()
{
recurse(0, root, queue)
queue.sort_by_depth
for(i = 0, i < queue.count, i++)
{
queue(i).data.read
}
}
recurse(depth, data, queue)
{
for(i = 0, i < data.count, i++)
{
queue.add(data(i), depth)
recurse(depth+1, data(i).children, queue)
}
}
It's kind of sloppy but I'm not sure there is a recursive algorithm that can do what you want to do. I'll get on adapting that to your code unless some one posts a better way. It will actually be decently light too since all the operations would be done reading from the xml data rather than the binary data.
Edit: I found a wiki article on the same sort of problem. It relates to searching through trees rather than just going through the whole thing but the algo is roughly the same.
Breadth-first traversal