multiple lists, reference or index only sort.

What I want to do is sort multiple times on multiple list quickly, At the moment I’m get data from a non database source, like the finder. Put in Filemaker, do the sort and bring back top Applescript. What I want to do is keep the orginal lists (memory issues) and rearrange just an index. Then I could repeat with i in IndexList and get info from multiple list.

There this great merge sort. Which sort the actual list.

I made this example.

set CityList to {"Auckland", "New York", "Hamilton", "Auckland", "New York"}
set SubrubList to {"City", "Kings", "City", "Archhill", "City"}

mergeSort(CityList, 1, -1)
CityList

--Handler from merge sort page go here

Get to:

Auckland
Archhill
City
Hamilton
City
New York
City
Kings

which is SortedIndexList = {4,1,3,5,2}

It like a reference or pointer method.

In the real world there’s, by country, then by city, then by suburb, then by street, then by number, then by flat, then by room, then by bed, then by side. LOL get the point.

And in the real world around 500 Items in 6 List. Inside AppleScript Limits.

May be ScriptDB. But I like to use Applescript becuase of releasing to to others at no cost, FileMaker runtimes are a pain.

Would be useful for files, by file type, then by date or size. Get the point.

See want people have to say before I go modifing merge sort myself.

Bevan, did you find a solution to this?

I use this (easily modified for two lists, but illustrated for 3 - it’s from a script proposed by Kai Edwards):


to sort3Lists(sortList, SecondList, thirdList)
	tell (count sortList) to repeat with i from (it - 1) to 1 by -1
		set s to sortList's item i
		set r to SecondList's item i
		set q to thirdList's item i
		repeat with i from (i + 1) to it
			tell sortList's item i to if s > it then
				set sortList's item (i - 1) to it
				set SecondList's item (i - 1) to SecondList's item i
				set thirdList's item (i - 1) to thirdList's item i
			else
				set sortList's item (i - 1) to s
				set SecondList's item (i - 1) to r
				set thirdList's item (i - 1) to q
				exit repeat
			end if
		end repeat
		if it is i and s > sortList's end then
			set sortList's item it to s
			set SecondList's item it to r
			set thirdList's item it to q
		end if
	end repeat
	return {sortList, SecondList, thirdList}
end sort3Lists

set {MasterSorted, BSorted, CSorted} to sort3Lists(MasterList, ListB, ListC)