In article <6631@palm-dev-forum>, Richard Burmeister wrote:
>There is a problem with using DmNumRecordsInCategory:  it can be slow.  Does
>anyone know of a method that is as fast as DmNumRecords but counts only
>non-deleted records?

DmNumRecords is fast because the total number of records is stored in the
database header.  Returning this value is O(1).  DmNumRecordsInCategory is
O(n) because it must loop through all the records in the database, checking
to see if they are not deleted and in the right category.

The only way to get the number of non-deleted records in O(1) is to store
the number on your own (e.g. count once when your app starts up, then use a
wrapper around functions that create or delete records).

Another method, which is still O(n) but much faster than
DmNumRecordsInCategory is to move all deleted records to the end of the
database.  Then, you can write a function that counts backward from the end
of the database to find the number of deleted records, which you then
subtract from DmNumRecords.  If you use Dm*Sort, deleted records will
automatically be moved to the end.  

HTH,
-Ben

-- 
Ben Darnell              [EMAIL PROTECTED]
http://thoughtstream.org
Finger [EMAIL PROTECTED] for PGP/GPG key 1024D/1F06E509


-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palm.com/devzone/mailinglists.html

Reply via email to