This linear search will be extremely long as you've discovered :)  If you
can keep the DB sorted, which it sounds like you are doing given that you
are using DmFindSortPosition, implement a simple binary search (or a
variation thereof) and you will be able to _dramatically_ improve your
search times.

If the data isn't currently being sorted, I'd strongly consider sorting it
so you can exploit the speed advantages of a binary search.  If I remember
correctly, a linear search has O(n) and binary has O(log(n)).  Google gives
a nice link at 

http://ciips.ee.uwa.edu.au/~morris/Year2/PLDS210/searching.html

with an explanation and some code.

Cheers,

-DGA

> -----Original Message-----
> Does anyone know of a fast way to search through a very large 
> database (17000 records)?
> I currently use the  the standard approach:
> 
> for (UInt16 recordNum = 0; recordNum < DmNumRecords(db); recordNum++)
> {
>      MemHandle dbRecordHandle = DmQueryRecord(db, recordNum);
>      MemPtr dbRecordPtr = MemHandleLock(dbRecordHandle);
>      ...  check if data matches search criterion
>      MemHandleUnlock(dbRecordHandle);
> }
> 
> This takes about 20 seconds.
> 
> I have successfully used DmFindSortPosition when looking for 
> data that is sorted, but I
> cannot think of any way to speed up the search for other data.

-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/

Reply via email to