I DO NOTHING way too much already

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
I meant the merge function expects a string. The dictionary shows examples in quotes.the sort command IS NOT expecting a string
Hi Richard -- i realise this is a loooooong thread to read through, so for convenience please see the handlers below.FourthWorld wrote: ↑Fri Mar 05, 2021 1:09 amAssociative arrays have no sense of order by their nature.
The most common way to access them in a specific sequence is to obtain and sort the keys.
What is the goal here?
Code: Select all
function sortArray @pArray, pDirection, pSortType, pKey
local tNextIndex, tSortedArray, tSortText
get the keys of pArray
put "sort lines of it [[pDirection]] [[pSortType]] by pArray[each]" into tSortText //1-dimensional array
if pKey is not empty then put "[pKey]" after tSortText //multidimensional array
do merge(tSortText)
repeat for each line tKey in it
add 1 to tNextIndex
put pArray[tKey] into tSortedArray[tNextIndex]
end repeat
return tSortedArray
end sortArray
Code: Select all
function sortArray @pArray, pDirection, pSortType, pKey
local tNextIndex, tSortText, tSortedIndex
get the keys of pArray
put "sort lines of IT [[pDirection]] [[pSortType]] by pArray[each]" into tSortText //1-dimensional array
if pKey is not empty then put "[pKey]" after tSortText //multidimensional array
do merge(tSortText)
repeat for each line tKey in IT
add 1 to tNextIndex
put tKey into tSortedIndex[tNextIndex]
end repeat
return tSortedIndex
end sortArray
Code: Select all
sortArray: 36 ms for 1000 iterations
8
6
2
3
5
1
4
7
Code: Select all
sortIndex: 36 ms for 1000 iterations
8
6
2
3
5
1
4
7
Code: Select all
constant kIterations = 1000
global gDirection, gType, gMethod
on preOpenCard
set the hilited of button "text" to true
set the hilited of button "ascending" to true
set the hilited of button "sortArray" to false
set the hilited of button "sortArrayOld" to false
set the hilited of button "sortIndex" to false
end preOpenCard
command doSort pMethod
local tArray, t0, tType, tDirection, tSource, tIndexA, x
put the milliseconds into t0
put empty into field "sortedArray"
set the useSystemDate to the hilited of button "useSystemDate"
put the dgData of group "data" into tSource
repeat kIterations
switch pMethod
case "sortArray"
put sortArray(tSource, gDirection, gType, "data") into tArray
# put "5th sorted element: " & tArray[5]["data"] & ", elapsed: " & the milliseconds - t0 && "ms" into field "metrics"
break
case "sortArrayOld"
put sortArrayOld(tSource, gDirection, gType, "data") into tArray
# put "5th sorted element: " & tArray[5]["data"] & ", elapsed: " & the milliseconds - t0 && "ms" into field "metrics"
break
case "sortIndex"
put sortIndex(tSource, gDirection, gType, "data") into tIndexA
# put "5th sorted element: " & tSource[tIndexA[5]]["data"] & ", elapsed: " & the milliseconds - t0 && "ms" into field "metrics"
-- repeat for each element tElement in tIndexA
-- add 1 to x
-- put tSource[tIndexA[x]] into tArray[x]
-- end repeat
break
end switch
end repeat --iterations
put the millisecs - t0 into tTime
if pMethod = "sortIndex" then
repeat for each element tElement in tIndexA
add 1 to x
put tSource[tIndexA[x]] into tArray[x]
end repeat
end if
put pMethod&": "& tTime & " ms for "& kIterations&" iterations" &cr& the keys of tArray
set the dgData of group "dataSorted" to tArray
set the dgHilitedLines of group "dataSorted" to 5
repeat for each element tElement in tArray
put tElement["data"] & return after field "sortedArray"
end repeat
end doSort
Absolutely! And i'm grateful that both you and Thierry have taken time to respond to thisFourthWorld wrote: ↑Fri Mar 05, 2021 5:32 amThierry's been doing this a while. When he recommends focusing on keys and not worrying about attempting to re-order the array, that's guidance worth heeding.
True, absolutely true !
Did it?
I took the time to review array fundamentals, with particular emphasis on arrays having no sense of order and not even being viewable, in hopes of raising awareness that whatever we use to display an array will also be the thing that gives it the appearance of order.The question is about dateTime sorting -- this does not produce a correct result, only partially sorting the dates.
Do you know offhand if that also prevents the "international" sort option from working?Klaus wrote: ↑Fri Mar 05, 2021 6:36 pmA little, but not too much "offtopic"...
Unfortunately "system date" etc. is not supported on ANDROID!
No idea why this seems so difficult to implement.
In any case we cannot sort a datagrid -> System Datetime
And I have to explain this embarrassing fact to users of the german LC forum at least once a week!
I already reported this back in 2014: https://quality.livecode.com/show_bug.cgi?id=11726
No, sorry, I created two datagrids with one column and entered some text with and without umlauts.Do you know offhand if that also prevents the "international" sort option from working?
Hm, after more than seven years I won't hold my breath, Richard!Curious that it's taken so long. We can guess it's not because Google has no support or internationalization; might be some difficulty translating the Java-based APIs to LC's C interface.
I suspect this is one of the areas where the company's work on LCFM will come home to LC: Filemaker has very excellent internationalization support, and without this in place so much of LCFM's value will be unrealizable. Just a guess, but I'd wager that gets fixed within the next LC release or two.
Often true with many things, but seven years ago the company wasn't heavily invested in delivering a premier Android user experience to the large Filemaker audience accustomed to taking internationalization for granted.
Alas, that was not my question.
Code: Select all
sort [{lines | items} of] <container> [<direction>] [<sortType>] [by <sortKey> ]
Code: Select all
sort lines of field "field 1" ascending dateTime