Numbering lines

Alex Tweedly alex at tweedly.net
Sun Oct 28 20:27:02 EDT 2018


My apologies Hermann. I had not been following the original thread 
closely, and got confused by the embedded quoting in the later messages. 
I was looking at Geoff's code - not yours - and he explicitly said "

And of course if retaining the order isn't critical "


So I agree your array method does indeed work properly. However, it is 
rather 'splendidly' slow compared to the simpler method as recommended 
by Mark H and myself :-); it takes almost twice as long on my test cases 
(between 30,000 and 300,000 lines of moderate length, highly repetitive, 
9.0.0, Mac Book Pro circa 2011).
Full code below ....

-- Alex
on mouseUp
    local tData1, tData2, time1, temp, tText
    repeat 30000 times
       put "this is a medium length line that can be updated" &CR after 
tText
    end repeat

    local tWith
    put prependLineNumbers(tText) into tWith
    put prependLineNumbers2(tText) into tWith

    --   put prependLineNumbersProgress(tText) into tWith

end mouseup
function prependLineNumbers pText
    local timeLastUpdated, time1, time2, temp
    local tCount
    put the number of lines in pText into tCount
    put the millisecs into time1
    local I
    repeat for each line L in pText
       add 1 to I
       put I && L &CR after temp
    end repeat
    put tCount && the millisecs - time1 &CR after msg
    return temp
end prependLineNumbers

function prependLineNumbers2 pText
    local timeLastUpdated, time1, time2, temp
    local tCount, S, K
    put the number of lines in pText into tCount
    put the millisecs into time1

    split pText by return
    put the keys of pText into K
    sort K numeric
    repeat for each line L in K
       put cr & L && pText[L] after S --> change separator here
    end repeat

    put tCount && the millisecs - time1 &CR after msg
    return char 2 to -1 of S
end prependLineNumbers2



On 28/10/2018 20:06, hh via use-livecode wrote:
>> Alex T. wrote:
>> You require to keep the line ordering completely unchanged -
>> and Hermann's superfast method can't meet that need.
>> JLG wrote:
>> You're right, split deletes duplicates. In fact, I use it as a quick way
>> to do just that.
> You are both spendidly wrong:
> Could you please simply try my functions and read the dictionary in order
> to understand why you are wrong? Please!
>
> Is it not yet Halloween ...
>
> -- D is the separator for numbers and text lines, usually space or ": "
> -- T is the input text, delimited with return
> -- prepends the number and separator to each line:
> function addLineNumbers D,T
>    split T by return
>    put the keys of T into K
>    sort K numeric
>    repeat for each line L in K
>      put cr & L & D & T[L] after S
>    end repeat
>    return char 2 to -1 of S
> end addLineNumbers
>
> -- D is the separator for numbers and text lines, usually space or ": "
> -- T is the input text, delimited with return
> -- removes the number and separator from each line:
> function removeLineNumbers D,T
>    split T by return and D
>    put the keys of T into K
>    sort K numeric
>    repeat for each line L in K
>      put cr & T[L] after S
>    end repeat
>    return char 2 to -1 of S
> end removeLineNumbers
>
>
>
>
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode





More information about the use-livecode mailing list