Strategy for read and rewind file for unordered data

I

iksrazal

Hi all,

I have to create an element tree as follows:

Data A
|
|
Data B
|
|
Data C

There can be multiple Data A, each of which can have many Data B, and
each Data B can have many Data C. There is no order in the file in
which Data A, Data B, Data C can appear - only a marker 'Data A', for
example at the beginning of a line. The file size is two megs - but %90
percent is ignored. There are multiple files, but the data is seperate
and should have no dependency clashes.

My first thought is to do it as such:

RandomAccessFile raf = new RandomAccessFile("BSS0","r");
InputStream in = new FileInputStream(raf.getFD());
BufferedReader reader = new BufferedReader ( new InputStreamReader ( in
) );
while ((line = reader.readLine()) != null) {
// find data A
Scanner sc = new Scanner(line);
}
// now, rewind raf
raf.seek(0);

repeat finding Data B which matches data A, and Data C which matches
Data B.

In essence re-reading the same file several times.

The other thing is the collection. How would one map a Data A
one-to-many relationship to Data B, which has a one-to-many
relationship with Data C?

I'm just getting started, but I'd appreciate any ideas.
iksrazal
 
R

Roedy Green

There can be multiple Data A, each of which can have many Data B, and
each Data B can have many Data C. There is no order in the file in
which Data A, Data B, Data C can appear - only a marker 'Data A', for
example at the beginning of a line. The file size is two megs - but %90
percent is ignored. There are multiple files, but the data is seperate
and should have no dependency clashes.

How about a serialised tree file with just the links in it as an index
file. You read this in its entirety into RAM.

It has pointers in it, offsets in the random access file, where to
find the bulk data for the corresponding node.

You can then access the data of the node in a single read.
 
I

iksrazal

Roedy Green escreveu:
How about a serialised tree file with just the links in it as an index
file. You read this in its entirety into RAM.

It has pointers in it, offsets in the random access file, where to
find the bulk data for the corresponding node.

You can then access the data of the node in a single read.

Hi Roedy,

Hmm. Not sure I understand "serialised tree file". I looked
unsuccesfully in your glossary for "tree file" - I think what you mean
is sort of a composite pattern based b-tree. Googling for "java tree
file" didn't turn up much.

I know about memory-mapped files, is that what you meant? I know how
offsets work with RandonAccessFile, is there a memory based equivalent?


Thanks for the reply,
iksrazal
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top