Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need a sorting routine
#6
How essential is speed to this process?  With such a limited dataset, I imagine a counting routine would blaze through the process in a single pass.  (Which would be useful when dealing with data sets with millions of elements in it.)

Process would work like this:

DIM A_String_Array(1 TO Array_Max_Limit) AS STRING

Then you simply read the array in one loop and add the index to the proper array element.

FOR I = 1 TO Array_Max_Limit
   A_String_Array(My_Data(I).a) = A_String_Array(My_Data(I).a) + MKL$(I)
NEXT

^  That just built you an indexed array in one single pass.  Now to "Sort" it, you can just read that array and rebuild your data from it.


Count = 0
FOR I = 1 TO Array_Max_Limit
FOR J = 1 TO LEN( A_String_Array(I)) STEP 4 'we stored our index as long values
Count = Count + 1
index = CLV(MID$(A_String_Array(I), J, 4))
    SWAP My_Data(Count), My_Data(index)
NEXT
NEXT

There may be some glitchness in the above as I haven't tested it (I'm not at a PC with QB64 on it at the moment), but the concept is sound. It's the same process as what I use in my MemSort routines for integers and bytes -- the fastest "sort" isn't any sort routine. It's a simple count routine.

Sorting is a process of take this, swap with that... repeat an excessive number of times.

This is just a case of: Read the value, store the index in an array large enough to hold all our values. Our SWAP of information only comes once for each index. There's no repetition involved.

And you can't get any faster than that!
Reply


Messages In This Thread
Need a sorting routine - by TerryRitchie - 03-04-2023, 06:53 AM
RE: Need a sorting routine - by mnrvovrfc - 03-04-2023, 08:58 AM
RE: Need a sorting routine - by TerryRitchie - 03-04-2023, 05:34 PM
RE: Need a sorting routine - by mdijkens - 03-04-2023, 09:00 AM
RE: Need a sorting routine - by TerryRitchie - 03-04-2023, 06:16 PM
RE: Need a sorting routine - by bplus - 03-04-2023, 10:02 AM
RE: Need a sorting routine - by RhoSigma - 03-04-2023, 10:03 AM
RE: Need a sorting routine - by SMcNeill - 03-04-2023, 10:46 AM
RE: Need a sorting routine - by SMcNeill - 03-04-2023, 06:14 PM
RE: Need a sorting routine - by TerryRitchie - 03-04-2023, 06:30 PM
RE: Need a sorting routine - by SMcNeill - 03-04-2023, 06:27 PM
RE: Need a sorting routine - by SMcNeill - 03-04-2023, 06:47 PM
RE: Need a sorting routine - by TerryRitchie - 03-04-2023, 06:52 PM
RE: Need a sorting routine - by SMcNeill - 03-04-2023, 07:14 PM
RE: Need a sorting routine - by Dimster - 03-05-2023, 02:49 PM
RE: Need a sorting routine - by TempodiBasic - 03-11-2023, 02:26 AM
RE: Need a sorting routine - by TempodiBasic - 03-11-2023, 02:34 AM



Users browsing this thread: 10 Guest(s)