-- ChipSortLists.mesa -- A Chipmonk package that sorts Chipmonk object -- lists in increasing order by smallest x, and within equal -- smallest x in increasing order by smallest y. -- last modified by E. McCreight, November 1, 1982 4:37 PM -- written by E. McCreight, October 13, 1981 3:15 PM DIRECTORY ChipNetDefs, ChipOrient, ppdefs; ChipSortLists: PROGRAM IMPORTS ChipOrient EXPORTS ChipNetDefs = BEGIN OPEN ppdefs, ChipOrient, ChipNetDefs; SortListPtrSeq: PUBLIC PROCEDURE[lps: ListPtrSeqPtr, less: PROCEDURE[lp1, lp2: listPtr] RETURNS[BOOLEAN] ] = BEGIN r, l: CellIndex; IF lps.count=0 THEN RETURN; -- Nothing to sort. r _ lps.count-1; -- max legal index l _ (r+1)/2; WHILE r>0 DO i, j: CellIndex; item: listPtr; IF l>0 THEN {l _ l-1; item _ lps.lp[l]} ELSE BEGIN item _ lps.lp[r]; lps.lp[r] _ lps.lp[0]; r _ r-1; END; FOR i _ l, j DO j _ i+i+1; -- I'd like to say 2*i+1 but -- I don't trust the optimizer IF j>r THEN EXIT; IF j