disk based dictionary - IO efficiency

Q

qouify

Hello,
here is my problem. I have a dictionnary of words (e.g., type
char[N]) stored sequentially (but not sorted) in a file F and I want
to insert in it some words stored in memory in a balanced tree T.
some elements of T may already be in F and I do not want to have them
twice in F after insertion.
i want to do something like this:

for each word in F
- if word is in T
-- remove word from T
for each word in T
- append word to F

here is how I implemented it :
1 - open F in "r" mode
2 - read sequentially (with fread) the words in F and delete them from
T
3 - close F
4 - open F in "a" mode
5 - append (with fwrite) to F all the remaining words of T
6 - close F

my questions are:
1 - is this an efficient way to do, and is there a better way?
2 - are there any trick to know to improve efficiency?

Thanks for help
 

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

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top