Yes it is faster to insert the record in place.  When you use
DmFindSortPosition, it does a binary search to find out where the record
should be inserted.  Then when you insert it into the DB at that point, I
believe there is just some info that is modified in the DB header.  In any
case, the performance impact of the actual insert is negligible (you would
have to insert at the end of the array in your 2nd scenario).

As Peter Epstein said in his previous post, if you do the sort, you have to
sort all the records in the db which takes n log n comparisons.  Assuming
the DB is sorted, using DmFindSortPosition with its binary search would be
log n comparisons to find the insertion position, and is the faster
solution.

Cheers,

-DGA

> -----Original Message-----
> I see that you can "insert" records into the pdb in a 
> specific location.
> Would it be faster to determine where the record goes and 
> insert it that it
> would be to append it to the end of the pdb and resort the 
> entire pdb every
> time?  I think so but wanted another opinion.
> 
> Thanks.
> 
> "Peter Epstein" <[EMAIL PROTECTED]> wrote in message
> news:59880@palm-dev-forum...
> >
> > In a nutshell: Finding records by unique ID is slow 
> (linear). Finding
> > records by index is fast (almost constant time). A binary 
> search API is
> > available that'll give you log time if you keep your 
> records sorted by the
> > search criteria. Of course, re-sorting your database is 
> slow (n log n).
> > --
> > Peter Epstein
> >

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

Reply via email to