Discussions related to Visual Prolog
User avatar
drspro2
VIP Member
Posts: 115
Joined: 28 Apr 2006 12:03

question about collections RedBlack trees

Post by drspro2 »

if I understand it well that if you want to create an indexed collection you should use the class redblack tree.

In Vp5 there was the btree in the class chain-db.

Is there a standardised way or a preferable way to save a complete RedBlack tree to a file and read it into memory again afterwards?

so that in this way you could load a redblacktree from file into memory , update this tree , for example insert an entry, and then save it back to the file. Would this be a good way to build databases? you could use the redblack tree for example to store indexes with associated values , and these values could point to file-positions of (large) records in other files.

In the redblack class -help file i couldnt find anything like this. or do i completely misunderstand the purpose of the redblack tree.
User avatar
drspro2
VIP Member
Posts: 115
Joined: 28 Apr 2006 12:03

Re: question about collections RedBlack trees

Post by drspro2 »

ok i think i might understand it, if you would want to do this you should use redblack get indexes_nd, save them to a text file , and when you want to reload the index you re-create the redblack tree from the textfile with insertkey. but then you might as well store your indexes by just appending them in an index- text- file ( not sorted ) which is very fast, and when needed you load the whole text file in the redblack tree in memory and use it from there to be able to search fast. Its a pity that you cant update the redblack tree directly in a file on disk directly with minimum file access
User avatar
Thomas Linder Puls
VIP Member
Posts: 1483
Joined: 28 Feb 2000 0:01

Re: question about collections RedBlack trees

Post by Thomas Linder Puls »

Both keys and data in a read black tree can contain things that cannot be serialized. Very often the data in a red black tree are objects, and objects cannot be serialized.

The B+ trees (which still exists in the chainDB) have restrictions that make them suitable for residing on a disk.

But my advice it not to use a chainDB for "long term" storage. Such files are fragile if anything happens to them (if your program crashes in a bad situation, or something like that) then there is no means to recover the data.

My suggestion is always to use an SQL database and ODBC for long term storage of data. Both MySql and PostgreSQL are free to use.
Regards Thomas Linder Puls
PDC