[futurebasic] Re: [FB] Sorting Records on multiple key fields within the record

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : April 2009 : Group Archive : Group : All Groups

From: Max Taylor <maxclass@...>
Date: Sun, 26 Apr 2009 12:48:10 -0700
On Apr 26, 2009, at 9:09 AM, Brian Stevens wrote:

> On Apr 26, 2009, at 2:46 AM, Robert Purves wrote:
>> Brian Stevens wrote:
>>> Does anyone have code to enable the use of two ( or more )  key  
>>> fields in one sort?  In the contrived example below it shows data  
>>> sorted alphabetically ( ascending ) on Store name and within a  
>>> given store name sorts Product alphabetically. Finally, it sorts  
>>> by date for the same product. Data is in records and index sorting  
>>> is the target but any method is fine. Thought I'd ask before  
>>> working through this. TIA....Brian S.
>>> Store Name		Product	Date
>>> MyGroceryStore	Eggs  	10/11/2009  ( mm/dd/yyyyy )
>>> MyGroceryStore	Milk	  	10/10/2009
>>> MyGroceryStore	Milk    	10/11/2009
>>> ...
>>> ...
>>> TheirGrocery		Milk  	12/11/2009
>>> TheirGrocery		Milk  	12/13/2009
>> The simplest way is to use a stable sorting algorithm <http://en.wikipedia.org/wiki/Sorting_algorithm 
>> >.
>> Sort on date first. Then sort on product. Then sort on store name.
> Thank you Robert for clarifying the core method. That is very helpful.
> Besides the various sorting methods( and I'm aware picking the  
> correct sort method is important ) there are some Core Foundation  
> calls to be considered and I'm still examining options.


I am following this with interest as to what you choose to do here and  
how you implement it.

Just a few questions.

Will your actual individual records be relocated within your file or  
will they remain static?
Do you plan to create a separate key file(s) with pointers to the next  
record in the sorted list?

Could the key file be automatically updated as new entries are added  
or deleted from the record file?

Could the way you do this be designed to be somewhat generic so as to  
sort by any key(s) in any file containing records of any length on any  
given fields?

I do not by any means mean to imply that one solution will fit every  
situation but keeping an updated key list sorted by a specific set of  
criteria seems like it might require less manipulation in the long  
run. As records are added the key list it is immediately updated so it  
is never out of required order. Data base programs have been doing  
this sort of thing for as long as I can remember which is all the way  
back to DBase 1 and 2 which I used in 1982 to write the record and  
billing program for a cable TV outfit in Palm Springs, CA.

Any way, just some thoughts, but I am interested in how you finally  
accomplish this task.

Max Taylor
The MaxClass Guy