ReneMiner
17-12-2015, 11:05
Currently i do some sorting of two associated Arrays (String + lineNumber, because i can not sort an UDT)
by appending MKL$(lineNumber) to the string-array-members which are to sort- so i have my connection between String and Number that belong together. So i sort by alphabet and i cut the last 4 bytes from the string after copying them to the numerical array-elements with same Index.
Thats quite simple because i have only to sort by element sName and there's only one more element to consider.
(see thinIce.tBasic, Sub btnCodeFunctionList_Click() - the small button up-left of a codewindow that displays the function-names of scriptunit)
Now we have a new #Trace (#Profile)- directive.
It writes csv-file that i can read in as data like
Dim FunctionNames() As String
Dim NumberOfCalls() As Number
Dim UsedTime() As Number
The FunctionName(1), NumberOfCalls(1) and UsedTime(1) belong together- so they are associated somehow.
if i sort one of these now i have no clue what index the element had before and which time belongs to which name. And if i want to sort by UsedTime or NumberOfCalls it would be some effort
lets say i read in the values from csv-file to myProfile() in a structure as below.
Now I want to sort by ... FunctionNames, but the other two arrays shall be sorted the same order too...
i would do it this way:
Type tProfile
FunctionName As String
NumberOfCalls As Number
UsedTime As Number
End Type
Dim myProfile() As tProfile
' now i loaded, parsed and filled csv-data into myProfile()-array
' lets say it has 1234 members now...
' and i want to sort by function-names:
Array Sort myProfile, UDT_Element(tProfile.FunctionName), Collate Ucase
' or i want to sort to see what used the most time:
Array Sort myProfile, UDT_Element(tProfile.UsedTime), Descend
now i could display data as sorted.
So either we should be able to sort UDTs
or back to the simple Arrays:
Dim FunctionNames(123) As String
Dim NumberOfCalls(123) As Number
Dim UsedTime(123) As Number
' lets say these variables are filled now...
' create a Buffer :
Dim myIndexList(Ubound(FunctionNames)) As Long
' now pass the pointer where to store the indices
Array Sort FunctionNames, Collate Ucase, VarPtr(myIndexList(1))
so myIndexList(1) later would hold the NEW Index of previous FunctionNames(1) and I could bring NumberOfCalls() and UsedTime() in the same order.
by appending MKL$(lineNumber) to the string-array-members which are to sort- so i have my connection between String and Number that belong together. So i sort by alphabet and i cut the last 4 bytes from the string after copying them to the numerical array-elements with same Index.
Thats quite simple because i have only to sort by element sName and there's only one more element to consider.
(see thinIce.tBasic, Sub btnCodeFunctionList_Click() - the small button up-left of a codewindow that displays the function-names of scriptunit)
Now we have a new #Trace (#Profile)- directive.
It writes csv-file that i can read in as data like
Dim FunctionNames() As String
Dim NumberOfCalls() As Number
Dim UsedTime() As Number
The FunctionName(1), NumberOfCalls(1) and UsedTime(1) belong together- so they are associated somehow.
if i sort one of these now i have no clue what index the element had before and which time belongs to which name. And if i want to sort by UsedTime or NumberOfCalls it would be some effort
lets say i read in the values from csv-file to myProfile() in a structure as below.
Now I want to sort by ... FunctionNames, but the other two arrays shall be sorted the same order too...
i would do it this way:
Type tProfile
FunctionName As String
NumberOfCalls As Number
UsedTime As Number
End Type
Dim myProfile() As tProfile
' now i loaded, parsed and filled csv-data into myProfile()-array
' lets say it has 1234 members now...
' and i want to sort by function-names:
Array Sort myProfile, UDT_Element(tProfile.FunctionName), Collate Ucase
' or i want to sort to see what used the most time:
Array Sort myProfile, UDT_Element(tProfile.UsedTime), Descend
now i could display data as sorted.
So either we should be able to sort UDTs
or back to the simple Arrays:
Dim FunctionNames(123) As String
Dim NumberOfCalls(123) As Number
Dim UsedTime(123) As Number
' lets say these variables are filled now...
' create a Buffer :
Dim myIndexList(Ubound(FunctionNames)) As Long
' now pass the pointer where to store the indices
Array Sort FunctionNames, Collate Ucase, VarPtr(myIndexList(1))
so myIndexList(1) later would hold the NEW Index of previous FunctionNames(1) and I could bring NumberOfCalls() and UsedTime() in the same order.