The only modification I'd make to your code is, if possible, cache the
sorting data within a property of the class so it does not have to be
recalculated during each sort.
That works, but it's only a win if there's a consistent search that
is being done. In the original question it was implied that many
different types of searches need to be done. Secondly, a,b,c need to
be relatively static. If they tend to change more often than you
sort, doing the sort index calculation at sort time can be more
efficient.
Here's a bit of code from the middle of my sort, which may give you
an idea
why I've been having trouble finding ways to use use RB's built-in
sort
methods and why this particular sort is so messy.
Almost always, these kind of messy sorts have a hierarchy. So look
for a heirarchy of sorts that can be used to
sort the entire thing; each sort generates a sorting index.
Sort the entire array using the most general index. Then create
subarrays for each span of elements that sorted to the same index,
compute the second level sort index for them, and sort them on that.
Repeat as many levels deep as is needed. Spans of 1, obviously, do
not require a deeper sort.
The linked list idea is fine. If the amount of data is huge, it's a
win because of the simplicity of updates. But a set of sort indexes,
cached in the class, will make it easier to insert things.
Another approach is to have layers of arrays. Let's say you have 4
levels of sorting you need to do. Then you could define the
structure as something like this:
sortClass.sortArray an array of sortClass1
sortClass1.sortArray an array of sortClass2
sortClass2.sortArray an array of sortClass3
sortClass3.sortArray an array of yourRealClass
(Question: would arrays of variants work faster? probably not)
This gives you a wide tree structure, which can be very fast. Note
that each sublevel would cache the sorting index array, so you could
binary chop to find an insert position. In fact, you'd not have to
use sortWith here.
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>