Re: Phix:Sort Columns Not Working Like Expected
- Posted by Spock Jun 26, 2020
- 1834 views
I should strongly recommend going the columnize() route, defining 5 and 'A' next to each other to start with, as per the pp(ic) outputs. Inserting/deleting the 3rd element of 54321 and ABCDE looks simple enough, but once they're 50+ elements long it gets to be a RPITA keeping two or more such sequences perfectly in step. Note that when I say "columnize() route", you should understand there is a reversibility about that:
sequence ic = columnize({{5,4,3,2,1},{'A','B','C','D','E'}}) ppOpt({pp_IntCh,-1}) pp(ic) -- {{5,'A'}, {4,'B'}, {3,'C'}, {2,'D'}, {1,'E'}} pp(columnize(ic)) -- {{5,4,3,2,1}, {'A','B','C','D','E'}}
Thanks, Pete! I think columnize() will work fine.
I downloaded the latest version of Phix to examine the sort routines. It appears that sort_columns() is a wrapper for custom_sort() which uses Shellsort which is acknowledged in the source as being unstable.
For Orac I dumped RDS' Shellsort in favor of a Merge/Insertion sort hybrid (See Timsort) to guarantee stability. Without stability it is risky to do multi-column sorting as the result might not always be 100% correct. For the business programs used in our office correctness is absolutely essential.
Given the popularity of Phix I recommend the same or equivalent be done to it. The above hybrid is reasonably performant.
Spock