03-04-2023, 10:46 AM
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!
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!