StringArray Sort (case independent)

Post your FreeBASIC tips and tricks here. Please don’t post your code without including an explanation.
Juergen Kuehlwein
Posts: 210
Joined: Mar 07, 2018 13:59
Location: Germany

Re: StringArray Sort (case independent)

Postby Juergen Kuehlwein » Aug 17, 2019 12:16

Ok - i see the problem now!

1.) Please use always the latest version (i just uploaded a new one).

2.) I ran exhaustive tests on 32 bit (at least i hope so), there are still some problems with 64 bit code (e.g accessing passed z/wstring arrays in 64 bit still causes a GPF). So please compile for 32 bit when testing.

3.) You must remove or outcomment the first two lines in "dodicat_sort.bas" because these are specific to my IDE and raise an error otherwise. This applies to all test files you find inside the "new" folder. My IDE can do PowerBASIC and FreeBASIC, therefore "compiler freebasic" means, compile using the FreeBASIC compiler. Likewise the #compile ..." statement, tells my IDE which settings to use for the FreeBASIC compiler.

4.) You cannot just compile from fbc_34.exe or fbc_64.exe! You must run fbc.exe in it´s regular environment. That is you must first rename fbc.exe, fbrt0.o, libfb.a and libfbmt.a or backup them, where they are located on your machine. Then you must copy fbc_32.exe to fbc.exe, where your original fbc.exe existed. Do the same with fbrt0.o, libfb.a and libfbmt.a (should be in the "lib" subfolder). Then copy "array.bi" and ustring.bi" to the "inc" subfolder.

Now you can compile and run FreeBASIC files as usual (but with the new binaries).


JK
dodicat
Posts: 5913
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: StringArray Sort (case independent)

Postby dodicat » Aug 17, 2019 13:10

Thanks JK.
I'll start from fresh with a new fb and your latest build.
jj2007
Posts: 1214
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: StringArray Sort (case independent)

Postby jj2007 » Aug 17, 2019 13:13

Juergen Kuehlwein wrote:4.) You cannot just compile from fbc_34.exe or fbc_64.exe! You must run fbc.exe in it´s regular environment. That is you must first rename fbc.exe, fbrt0.o, libfb.a and libfbmt.a or backup them, where they are located on your machine. Then you must copy fbc_32.exe to fbc.exe, where your original fbc.exe existed. Do the same with fbrt0.o, libfb.a and libfbmt.a (should be in the "lib" subfolder). Then copy "array.bi" and ustring.bi" to the "inc" subfolder.

That sounds messy, even for FB standards. So it means you must ditch your old FreeBasic installation in favour of your version? And who guarantees that it does not break existing code? What happens if a new "official" FB version comes out?
MrSwiss
Posts: 3215
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: StringArray Sort (case independent)

Postby MrSwiss » Aug 17, 2019 13:18

Juergen Kuehlwein wrote:2.) I ran exhaustive tests on 32 bit (at least i hope so), there are still some problems with 64 bit code (e.g accessing passed z/wstring arrays in 64 bit still causes a GPF). So please compile for 32 bit when testing.
This seems to me to indicate, that the priorities are "the wrong way around".
FBC 64 should be "top priority" all else, I'd consider "legacy" ...
Juergen Kuehlwein
Posts: 210
Joined: Mar 07, 2018 13:59
Location: Germany

Re: StringArray Sort (case independent)

Postby Juergen Kuehlwein » Aug 17, 2019 14:31

It´s just for testing, this is NOT in any way official. Therefore i recommended to make backup copies of the existing binaries in order to be able to restore it afterwards!

64 bit has a different data alignment than 32 bit, this is what i´m struggling with currently. There will be a working 64 bit version too!


JK
jj2007
Posts: 1214
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: StringArray Sort (case independent)

Postby jj2007 » Aug 17, 2019 14:50

MrSwiss wrote:FBC 64 should be "top priority"
Yes, for everybody who regularly needs to allocate more than 2GB of memory.
MrSwiss
Posts: 3215
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: StringArray Sort (case independent)

Postby MrSwiss » Aug 17, 2019 14:55

jj2007 wrote:Yes, for everybody who regularly needs to allocate more than 2GB of memory.
No, nothing to do with memory, far more "going with the Time",
as opposed to "yesterday people" who are backwards oriented.
Juergen Kuehlwein
Posts: 210
Joined: Mar 07, 2018 13:59
Location: Germany

Re: StringArray Sort (case independent)

Postby Juergen Kuehlwein » Aug 17, 2019 16:46

64 bit is working now too! Please read more here: viewtopic.php?f=17&p=263397#p263397


JK
dodicat
Posts: 5913
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: StringArray Sort (case independent)

Postby dodicat » Aug 17, 2019 16:53

Used to like that old song
https://www.youtube.com/watch?v=W6N3o4TDYsI

JK
Power basic.
Is this where you got those ideas of built in array functions?
What about recursive macros as well?

I think by inlining code in my quicksort it makes not a jot of difference to 64 bit with optimisations.
I think -O3 and -O2 and -O1 inline functions anyway.
All inline:

Code: Select all

Dim Shared As String * 255 u
For n As Long=0 To 255
    u[n]=Iif(n<91 Andalso n>64,n+32,n)  'lookup string
Next

Sub quicksortup(low As String Ptr,high As String Ptr)
    If (high-low <= 1) Then Return
    Var J=low+1,I=J,lenb=Cast(Integer Ptr,low)[1],lena=0
    While J <= high
        lena=Cast(Integer Ptr,J)[1] '=Len(*a)
        If lena>lenb Then lena=lenb
        For n As Long =0 To lena-1
            If u[(J)[0][n]] < u[(low)[0][n]] Then Swap *J,*I:I+=1:Exit For
            If u[(J)[0][n]] > u[(low)[0][n]] Then Exit For
        Next
        J+=1
    Wend
    J=I-1: Swap *low,*J
    quicksortup(low,J)
    quicksortup(I,high)
End Sub

Sub create(L() As String)
    #define range(f,l) Int(Rnd*(((l)+1)-(f))+(f))
    #define q range(97,122)-Iif(Rnd>.5,32,0)
    Randomize 1
    For n As Long=Lbound(L) To Ubound(L)
        Dim As String g1=Chr(q,q,q,q,q,q,q,q,q,q,q,q,q,q,q,q,q,q,q,q,q,q,q,q,q,q,q,q,q,q)
        Dim As String g2=Chr(q,q,q,q,q,q,q,q,q,q,q,q,q,q,q,q,q,q,q,q,q,q,q,q,q,q,q,q,q,q)
        Dim As String g3=Chr(q,q,q,q,q,q,q,q,q,q,q,q,q,q,q,q,q,q,q,q,q,q,q,q,q,q,q,q,q,q)
        L(n)=Left(g1+g2+g3,60+Rnd*30)
    Next
End Sub

Sub show(L() As String)
    For n As Long=Lbound(L) To 10
        Print L(n)
    Next
    For n As Long=1 To 4
        Print "..."
    Next
    For n As Long=Ubound(L)-10 To Ubound(L)
        Print L(n)
    Next
End Sub

Dim As Double t1,t2
Dim As Long limit=1000000
Dim As String L(1 To limit)
Print "Creating string"
create(L())
Print "Commence sort (quicksort)"
t1=Timer
quicksortup(@L(Lbound(L)),@L(Ubound(L)))
t2=Timer
show(L())
Print t2-t1;"  Seconds quicksort"
Sleep

 
MrSwiss
Posts: 3215
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: StringArray Sort (case independent)

Postby MrSwiss » Aug 17, 2019 17:18

@dodicat,

seems to knock out the barrels bottom:
FBC 64 -gen gcc (no optimizer) = 1.25 Seconds
FBC 64 -gen gcc (-O 2) = 0.65 Seconds

Win10, pro, 64
CPU i7 (7th gen. ultra low power) 2 cores (4 threads) base speed: 2.9 GHz (variable)
jj2007
Posts: 1214
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: StringArray Sort (case independent)

Postby jj2007 » Aug 17, 2019 17:46

I am fine-tuning my mergesort, now down to 0.6 seconds on a Core i5 ;-)
dodicat
Posts: 5913
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: StringArray Sort (case independent)

Postby dodicat » Aug 17, 2019 19:18

Win 10 64 bits.
Why does nm not work for 64 bit files
It shows the table of .o files only
e.g.
nm libfb_64.a
gives

Microsoft Windows [Version 10.0.18362.295]
(c) 2019 Microsoft Corporation. All rights reserved.

(then the path)
then

. . .
. . .
nm: array_sort.o: File format not recognized
nm: array_tmpdesc.o: File format not recognized
nm: array_ubound.o: File format not recognized
nm: con_input.o: File format not recognized
nm: con_lineinp.o: File format not recognized
nm: con_lineinp_wstr.o: File format not recognized
nm: con_locate.o: File format not recognized
nm: con_pos.o: File format not recognized
. . .
. . .

Is cmd.exe still stuck in 32 bits?
MrSwiss
Posts: 3215
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: StringArray Sort (case independent)

Postby MrSwiss » Aug 17, 2019 19:35

Please people, stop hijacking this thread, for JK's array stuff (which has its own thread).
See: Community Discussion ... "New array features"
jj2007
Posts: 1214
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: StringArray Sort (case independent)

Postby jj2007 » Aug 17, 2019 20:06

Well, JK has code that answers the OP's question. Looks very relevant. What do you offer, other than your "32-bit is obsolete" bla bla?
MrSwiss
Posts: 3215
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: StringArray Sort (case independent)

Postby MrSwiss » Aug 17, 2019 20:11

jj2007 wrote:Well, JK has code that answers the OP's question.
I am OP ... in case you've NOT noticed ...

Return to “Tips and Tricks”

Who is online

Users browsing this forum: No registered users and 2 guests