[EMAIL PROTECTED] wrote:
> i have an app that has to update two table with pdf files from 
> directories. There are about  900 files in one Dir and about 3000 in the 
> other. I have to check if each file is in the table if not add it. This 
> requires 3000 searches on the table but as the app progresses it slows 
> down to a crawl. Anybody have any ideas?.

What you're describing will run in quadratic time. You can do it in 
linear time, though.

Get a sorted list of files in the directory and a sorted list of files 
in the table. Use a sorting algorithm that performs very well on lists 
that are already sorted since chances are very good that the lists you 
generate from the file system and from the database will already be sorted.

Now, walk through both lists at the same time. Ideally, the lists are 
identical. Whenever you encounter an item in the file list that isn't in 
the database list, add it to a third list.

When you've made it all the way through the lists, take your third list 
and add everything there to the database.

> I have to add to this the revers for deleted files, so I really could do 
> with speeding up the loop.

You can find the items to remove from the database at the same time as 
you find the ones to add. Use a fourth list to store the items that 
should be deleted.

> The list below is the milliseconds it takes to do 100 hundred records. 
> There are no updates in the trimmings just locates

I don't understand how to read those lists. Is it just saying that it 
takes 0 ms to find the first file in the database, 109 ms to find the 
second file, and so on? In that case, what you have is a simple linear 
progression. Nothing too remarkable.

> ======================================
> IPACTA_TRIALS_PDFS
> 0 
> 109 
> 203 
> 266 
> 328 
> 500 

-- 
Rob
_______________________________________________
Delphi mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi

Reply via email to