Re-ordering a list of fixed-length records in-place

Giganews Newsgroups
Subject: Re-ordering a list of fixed-length records in-place
Posted by:  R.Wieser (addre…@not.available)
Date: Thu, 14 Jan 2021

Hello all,

I've got a series of records that I've "sorted" by using a DPA filled with
indices to those records, and use DPA_Sort to sort those indices.

I would now like to re-order the fixed-length records in the order shown by
the DPA, and to make things interresting I would like to have that done
in-place [1].

The thing is that I've been looking at it and I do not see a simple, lineair
approach to it that *doesn't* involve searching for the to-be-swapped-with
record.

Consider the below table.  The first colum is the index into the DSA, the
second the index the DSA holds into the actual records, and the third those
records contents.

----|Indx|record content
----+----+------------
0000 0007 I4: 00000384
0001 0000 I4: 00000438
0002 0008 I4: 0000087E
0003 0002 I4: 00000915
0004 0003 I4: 00000B14
0005 0009 I4: 00000CD4
0006 0004 I4: 000011FD
0007 0001 I4: 0000198F
0008 000A I4: 00001B74
0009 0005 I4: 00002245
000A 0006 I4: 000025F8

The DSA list shows the record indices in a sorted order.  But how do I now
move the record at index 7 (DSA position 0) to record index 0 without
trashing ther record already there (which should end up at record index 1) ?

Am I looking for something that just can't be done under my 'no searching'
condition ?

[1] My current solution is to copy all the records, use that to copy from
into the origional and finally delete the copy.  Which severely limits the
maximum size of the to-be-sorted list of records.

Regards,
Rudy Wieser

Replies