[fpc-pascal] sorting and merging array of records

waldo kitty wkitty42 at windstream.net
Thu Jan 12 17:55:23 CET 2012


On 1/12/2012 11:23, waldo kitty wrote:
> On 1/12/2012 07:20, Tomas Hajny wrote:
>> On Thu, January 12, 2012 03:34, waldo kitty wrote:
[TRIM]
>>> i'll probably have broken my code by the time you read this... but i'll
>>> very likely be attempting to implement the logic in my Input_Satellite_List
>>> routine ;) OB-)
>>
>> Possible, but likely resulting in some useless overhead (computing
>> performance-wise) if you still intend to use the method Insert in that
>> case.
>
> yeah, that went over like a lead balloon... i'm digging into the insert method
> override, instead... just gotta figure out how to access the epoch in the
> current record and the one in the passed record for the decision making
> comparison...

yeah, i know... bad form to reply to my own message but...

I GOT IT!! WHOOHOO! finally...


procedure TTLEColl.Insert (Item: Pointer);
var
   I: Sw_Integer;
   old: Pointer;
begin
    If NOT Search(KeyOf(Item), I) OR Duplicates Then   { Item valid }
      AtInsert(I, Item)                                { Insert the item }
    else                                               // otherwise
      // compare the epochs & replace existing record if < item^.epoch
      if PTLERec(At(i))^.epoch < PTLERec(Item)^.epoch then
        begin
          old := At(i);                  // save existing pointer first!
          AtPut(i, Item);                // now put in the new record
          PTLERec(old)^.Done;            // time to remove the old data
          dispose(old);                  // and finally dispose it
        end
      else
        begin                            // we're tossing this one out
          PTLERec(Item)^.Done;           // so remove the data first
          dispose(Item);                 // and then dispose the item
        end;
end;


now the list is sorted, newer entries replace older ones and there's no more 
whining from heaptrc about left over fluff on the heap... yeah!


and i said it before but dang this thing's fast... compared to the old tool that 
i've been using for eons... i mean look at it like this... we're comparing a 
turtle with a lightening bolt... somehow "fast" just doesn't seem to be strong 
enough to describe the difference in speed :P




More information about the fpc-pascal mailing list