PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

How to save a tree in memory to disk

Hi,

I am trying to program a T9 clone for
the PocketPC.
It will work a little different than T9.
Instead of pointing to one of the nine buttons
you'll have to stroke in direction of the symbols(1..9). That way you don;t have to raise your pen.
I cant describe it, you'll have to see it.
It works great! I can allready type 25 words a minute. But i have a problem:

I have a rather strange tree in memory.
Each node consist of 9 pointer to other nodes and
a pointer to a list of char*s.

Imagine i have the word "KAI";
my tree traversal will be:

1 : curNode = StartNode;
2 : curNode = curNode.n5 (cause "K" is on the 5th key)
3 : curNode = curNode.n2 (cause "A" is on the 2nd key)
4 : curNode = curNode.n4 (cause "i" is on the 4nd key)

5 : curWord = curNode.word;
6 : repeat until curWord.next = nil
7 : addWordToUserInterFace(curWord.word);




Thus:

Node {
n1 *node;
n2 *node;
...
n9 *node;
words *word;
}


This all works great! When loaded the program
works as a charm.
But the problem:
I have a wordlist in ascii and i create in memory
the tree. But it takes almost 60 seconds to
build the tree (20000 words in dictionary)!
That's unacceptable ofcourse.

I know that it is possible to
flush this tree to disk. But i don;t know how:
I myself think that i have to inherit from
CObject, but i don;t know how.

Can someone help me?

Greetz,


Kaiton

<img src="http://web.icq.com/whitepages/page_me/1,,,00.html?to=163639225&from;=wendi&fromemail;=kai@mail.com&body;=dddsd" width="1" height="0">
BurningSheep · 09 Jul 2002, 11:32 UTC
You will have to traverse the entire tree and write the information you get to disk, so you can easily retrieve it again. There are a lot of algorithms to do that, most of them rely on recursion.
For instance lookup a preorder tree traversal algo, that should give you an idea of how to save such a datastructure. It's not difficult you can write it in no time, but I don't know how long it will take to serialize a large tree on a ppc (but maybe you'll only do this once on a normal computer anyway?).
(Beware, rambling coder text ahead)

I'd be tempted to work out a data structure to store the suffix trie / patricia trie in a structure that didn't rely on actual pointers (i.e. make it so it can be referenced from where-ever it is loaded into memory ... relocatable).

That way you can just build the data structure once, dump it to disk, then re-load it and use that. The interesting part will be working out how to then add to it (I'm assuming you'll need to).

Have you thought about using bit-sets at each trie node rather than a series of pointers? It'll be far more compact in memory if you can do that.

Have a look at this:

http://citeseer.nj.nec.com/andersson95efficient.html

And see if it helps any.

(http://citeseer.nj.nec.com is *great* for research like this since the the other reference site went belly-up .. can't even remember what that one was called now).

Cheers,

Refractor
He Refractor!

That site is great!
Thanks!