On Apr 26, 2009, at 12:48 PM, Max Taylor wrote: > > Will your actual individual records be relocated within your file or > will they remain static? The file is loaded to an array and the array will be sorted. For my purposes the record order within the file is irrelevant. > Do you plan to create a separate key file(s) with pointers to the > next record in the sorted list? Right now I don't have a specific plan. I might use an index sort ( where the index is created and sorted and not the entire file - see FBtoC examples in the folder "Sorting" for a good explanation of indexed vs. non-indexed sorts ) but there is no plan to imbed pointers to next/prior records. I haven't done any imbedded pointers since my old IMS and IDMS days. > > Could the key file be automatically updated as new entries are added > or deleted from the record file? This could be done but it is unnecessary for my goals. DBMS systems handle this kind of activity but I don't need a DBMS ( yet! ). The data could get very large, and the code does lots of searches based on user selections, so my primary concern is making the searches more efficient ( currently sequential ). The best way I know to decrease search time is to sort the array and use a binary search. My secondary sorting goal would help printed reports. > > 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? My thought too. I've seen sorts that are tailored to specific needs but we ( FBers ) need a generalized sort. Input would be the record size, offset to the first sort field within the record, length of the first sort field and whether to sort ascending or descending on that sort field. This would repeat for each sort field. The user of the sort doesn't have to worry how the sort is done but only has to specify the sort fields etc. The downside to the general approach( unless the sort requests information to make its own decisions ) is the inability to pick the right sort for the application. Things like data size, whether data is partially sorted impact how efficient and fast some sorts can be. Many of the standard sort methods ( e.g. quicksort, bubble, shell, and more ) can be found on the web in C I just saw some code today using Cocoa's NSSortDescriptor tailored for a specific need but it has potential. > > 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 Yes, those methods have been around for many years but, as mentioned above, is beyond what is needed for my current application. If my solution is general enough, I'll share with the list. One place folks can look for a binary search is the FBtoC source code. Brian S.