• Sorting algorithms

    From Bob Latham@3:633/10 to All on Friday, November 06, 2026 08:45:15
    A music library scan tool I've written produces a list of over 4000
    lines, each line shows the path to a particular album. But the filer
    does not list in alphabetic order...

    There are two sort types I understand; Bubble sort and what I call
    "Best So Far" but I bet there is a different official name.

    I've always gone for bubble sort for two reasons, firstly I
    understand the principle and it does not require another chunk of ram
    to hold the result file. But using this method takes 12.6 seconds.

    The "Best So Far" method is to repeatedly pass through the source
    file and pick out the best line on each pass and move it out to
    another store and mark it as used in the source. I had the idea of
    squirting these best lines one at a time to a file on disc rather
    than provide temporary ram.

    I realised that using OS_BPut, line by line was not going to be as
    fast as saving a file in one go but tried it anyway. It took 6
    seconds. Faster yes but I don't like it, the sorted file never exists
    in the application. True it doesn't matter but it kind of does to me.

    Anyone got any suggestions for a better approach? Something I might
    even understand?

    A slight complication, any sort would need to handle is the C?line
    Dion problem. I like treating ? as e as regards the sort comparison
    stage.

    Also, how is StrongEd so lightning fast on sorts? It barely blinks.


    Still coded in Basic Assembler, in case you need to know.


    Thanks.

    Bob.


    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Jean-Michel@3:633/10 to All on Friday, November 06, 2026 17:30:51
    In message <5d336712aebob@sick-of-spam.invalid>
    Bob Latham <bob@sick-of-spam.invalid> wrote:

    A music library scan tool I've written produces a list of over 4000
    lines, each line shows the path to a particular album. But the filer
    does not list in alphabetic order...
    ???
    Is the list a text file?

    There are two sort types I understand; Bubble sort and what I call
    "Best So Far" but I bet there is a different official name.

    I've always gone for bubble sort for two reasons, firstly I
    understand the principle and it does not require another chunk of ram
    to hold the result file. But using this method takes 12.6 seconds.

    The "Best So Far" method is to repeatedly pass through the source
    file and pick out the best line on each pass and move it out to
    another store and mark it as used in the source. I had the idea of
    squirting these best lines one at a time to a file on disc rather
    than provide temporary ram.

    I realised that using OS_BPut, line by line was not going to be as
    fast as saving a file in one go but tried it anyway. It took 6
    seconds. Faster yes but I don't like it, the sorted file never exists
    in the application. True it doesn't matter but it kind of does to me.

    Anyone got any suggestions for a better approach? Something I might
    even understand?

    A slight complication, any sort would need to handle is the C?line
    Dion problem. I like treating ? as e as regards the sort comparison
    stage.
    Thanks for C?line :-)

    Also, how is StrongEd so lightning fast on sorts? It barely blinks.
    Yes, but failed with C?line...
    with capital letters C?line => C?LINE, ko too

    Still coded in Basic Assembler, in case you need to know.
    good luck!

    Thanks.

    Bob.



    --
    Jean-Michel

    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Bob Latham@3:633/10 to All on Friday, November 06, 2026 17:57:58
    In article <1db391335d.jmb@jmc.bruck.orange.fr>,
    Jean-Michel <jmc.bruck@orange.fr> wrote:
    In message <5d336712aebob@sick-of-spam.invalid>
    Bob Latham <bob@sick-of-spam.invalid> wrote:

    But the filer does not list in alphabetic order...

    ??? Is the list a text file?

    Yes.


    Bob.


    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Jean-Michel@3:633/10 to All on Friday, November 06, 2026 20:28:40
    In message <5d3399acf0bob@sick-of-spam.invalid>
    Bob Latham <bob@sick-of-spam.invalid> wrote:

    In article <1db391335d.jmb@jmc.bruck.orange.fr>,
    Jean-Michel <jmc.bruck@orange.fr> wrote:
    In message <5d336712aebob@sick-of-spam.invalid>
    Bob Latham <bob@sick-of-spam.invalid> wrote:

    But the filer does not list in alphabetic order...

    ??? Is the list a text file?

    Yes.
    I did some tests with C/C++ fonctions, result(s) not good with "C?line" problem.
    Only Datapower gave me the good order...
    Not tested with Fireworkz!





    Bob.



    --
    Jean-Michel

    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Paul Sprangers@3:633/10 to All on Saturday, November 07, 2026 13:36:33
    In article <5d336712aebob@sick-of-spam.invalid>,
    Bob Latham <bob@sick-of-spam.invalid> wrote:
    A music library scan tool I've written produces a list of over 4000
    lines, each line shows the path to a particular album. But the filer
    does not list in alphabetic order...

    My own database program uses SYS "OS_HeapSort". It sorts a block of 4000 strings in less than a fraction of a second, inluding the routine that
    takes capitals, diacritics and other signs into account. A perfect job,
    but... quite some programming is involved.

    Paul

    --
    https://riscos.sprie.nl

    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Jean-Michel@3:633/10 to All on Saturday, November 07, 2026 18:55:13
    In message <5d340015eePaul@sprie.nl>
    Paul Sprangers <Paul@sprie.nl> wrote:

    In article <5d336712aebob@sick-of-spam.invalid>,
    Bob Latham <bob@sick-of-spam.invalid> wrote:
    A music library scan tool I've written produces a list of over 4000
    lines, each line shows the path to a particular album. But the filer
    does not list in alphabetic order...

    My own database program uses SYS "OS_HeapSort". It sorts a block of 4000 strings in less than a fraction of a second, inluding the routine that
    takes capitals, diacritics and other signs into account. A perfect job, but... quite some programming is involved.

    Paul

    Nice,You have implemented your own routine in ASM , many characteristics
    to take into account, not easy.



    --
    Jean-Michel

    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Paul Sprangers@3:633/10 to All on Saturday, November 07, 2026 19:41:43
    In article <91421d345d.jmb@jmc.bruck.orange.fr>,
    Jean-Michel <jmc.bruck@orange.fr> wrote:

    Nice,You have implemented your own routine in ASM

    No, I wrote the entire program in BASIC and then compiled it with !ABC.
    But of course, OS_HeapSort does the actual sorting. My routines just
    prepare the strings. Remember however that OS_HeapSort only sorts memory blocks, it won't do anything with arrays - as far as I remember.

    Paul

    --
    https://riscos.sprie.nl

    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Martin@3:633/10 to All on Saturday, November 07, 2026 19:48:00
    In article <5d34218484Paul@sprie.nl>,
    Paul Sprangers <Paul@sprie.nl> wrote:
    In article <91421d345d.jmb@jmc.bruck.orange.fr>,
    Jean-Michel <jmc.bruck@orange.fr> wrote:

    Nice,You have implemented your own routine in ASM

    No, I wrote the entire program in BASIC and then compiled it with
    !ABC. But of course, OS_HeapSort does the actual sorting. My
    routines just prepare the strings. Remember however that
    OS_HeapSort only sorts memory blocks, it won't do anything with
    arrays - as far as I remember.

    The ArmSort module will happily sort one or more BASIC arrays (see www.avisoft.f9.co.uk) ... but it does not cater for the C?line problem
    without creating a duplicate array with the accent removed.

    --
    Martin Avison
    Note that unfortunately this email address will become invalid
    without notice if (when) any spam is received.

    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Bob Latham@3:633/10 to All on Sunday, November 08, 2026 12:13:58
    In article <5d34279617News04@avisoft.f9.co.uk>,
    Martin <News04@avisoft.f9.co.uk> wrote:
    In article <5d34218484Paul@sprie.nl>,
    Paul Sprangers <Paul@sprie.nl> wrote:
    In article <91421d345d.jmb@jmc.bruck.orange.fr>,
    Jean-Michel <jmc.bruck@orange.fr> wrote:

    Nice,You have implemented your own routine in ASM

    No, I wrote the entire program in BASIC and then compiled it with
    !ABC. But of course, OS_HeapSort does the actual sorting. My
    routines just prepare the strings. Remember however that
    OS_HeapSort only sorts memory blocks, it won't do anything with
    arrays - as far as I remember.

    The ArmSort module will happily sort one or more BASIC arrays (see www.avisoft.f9.co.uk) ... but it does not cater for the C?line
    problem without creating a duplicate array with the accent removed.

    Thanks everyone for you thoughts and ideas. My best code takes 6
    seconds but it does handle the C?line problem and it looks like a
    major effort to improve it unfortunately. Sorry I've been slow to
    return I've had an unpleasant virus for a couple of days.

    Thanks.

    Bob.


    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Paul Sprangers@3:633/10 to All on Wednesday, November 11, 2026 17:06:45
    I've written a short BASIC program that sorts the lines in a text file,
    taking capitals, undercasts and all sorts of diacritics, as well most other characters into account.

    My own example has nearly 6000 lines.
    The BASIC version took about 23 seconds to sort them, while the compiled version took less than 3 seconds to do the job. (On a 4t?2 computer.)

    The text file is not included, but you should rename yours to "Texts" in
    order to let the program do its work. If your text file counts more than
    6000 lines, you should change the DIM's in the program. Compile the program with the freely available !ABC compiler. Remember that the compiled version needs quite a big NEXT slot.

    There are much better or memory friendly ways to do this, but as an example
    it may have some use.

    Paul



    REM DIM two string arrays,
    REM big enough to store your lines.
    REM My example had 5913 lines.

    DIM text$(5913), dummy$(5913)

    REM Now store every line into both arrays.
    REM The dummy array will be adjusted on the fly,
    REM by changing undercast into capitals and by
    REM removing diacritics, in FNcase (see botom).

    f%=OPENIN("Texts")
    IF f%>0 THEN
    a%=0
    REPEAT
    a%+=1
    text$(a%) = GET$#f%
    dummy$(a%) = FNcase(text$(a%))
    UNTIL EOF#f%
    ENDIF
    IF f%>0 THEN CLOSE#f%

    REM NOW the actual sorting will start

    OK% = TRUE
    time = TIME

    PROCsort

    t = TIME - time : REM The time needed in centiseconds.

    REM Finally, print the sorted lines

    FOR i% = 1 TO a% : PRINT STR$(i%) +": " + text$(i%) : NEXT
    PRINT t
    END


    DEF PROCsort
    FOR i% = 1 TO a%
    IF dummy$(i%) < dummy$(i%-1) THEN
    SWAP text$(i%),text$(i%-1)
    SWAP dummy$(i%),dummy$(i%-1)
    OK% = FALSE
    ENDIF
    NEXT
    IF NOT OK% THEN OK% = TRUE : PROCsort
    ENDPROC


    DEF FNcase(x$)
    y$=""
    FOR j%= 1 TO LEN x$
    c%=ASC(MID$(x$,j%,1))
    IF c%>96 AND c%<123 THEN y$ += CHR$(c%-32) : REM undercast -> capital
    IF c%>47 AND c%< 58 THEN y$ += CHR$(c%) : REM numbers don't change
    IF c%>64 AND c%< 91 THEN y$ += CHR$(c%) : REM capitals don't change
    IF c%>223 AND c%<230 THEN y$ += "A" : REM diacritics removed
    IF c%>231 AND c%<231 THEN y$ += "E"
    IF c%>235 AND c%<240 THEN y$ += "I"
    IF c%>241 AND c%<247 THEN y$ += "O"
    IF c%>248 AND c%<253 THEN y$ += "U"
    IF c%=229 OR c%=197 THEN y$ += "A"
    IF c%=230 OR c%=198 THEN y$ += "AE"
    IF c%=231 OR c%=199 THEN y$ += "C"
    IF c%=241 OR c%=209 THEN y$ += "N"
    IF c%=248 OR c%=216 THEN y$ += "O"
    IF c%=223 THEN y$ += "SS"
    IF c%=255 THEN y$ += "Y"
    NEXT
    =y$

    --
    https://riscos.sprie.nl

    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Martin@3:633/10 to All on Wednesday, November 11, 2026 17:14:34
    In article <5d3622ac84Paul@sprie.nl>,
    Paul Sprangers <Paul@sprie.nl> wrote:
    I've written a short BASIC program that sorts the lines in a text
    file, taking capitals, undercasts and all sorts of diacritics, as
    well most other characters into account.

    My own example has nearly 6000 lines. The BASIC version took about
    23 seconds to sort them, while the compiled version took less than
    3 seconds to do the job. (On a 4t?2 computer.)

    The text file is not included, but you should rename yours to
    "Texts" in order to let the program do its work. If your text file
    counts more than 6000 lines, you should change the DIM's in the
    program. Compile the program with the freely available !ABC
    compiler. Remember that the compiled version needs quite a big NEXT
    slot.

    There are much better or memory friendly ways to do this, but as an
    example it may have some use.

    [Snip]

    As a specific example, it works but does have some limitations.
    The most obvious one is that any characters not included in FNcase are
    omitted from the sort key completely (eg blank or hyphen). This may be deliberate, but means it is not a plain sort.

    If you load the ArmSort module, then PROCsort can be replaced simply
    by the line
    *Sort 1 a% dummy$(n) text$(e)
    which probably saves time and effort.

    The *Sort command may mean ABC cannot compile it, but I would be
    interested to hear how the time compared without compilation.
    I suspect however that as FNcase tests each character 29 times, it
    could be optimised.

    Martin

    --
    Martin Avison
    Note that unfortunately this email address will become invalid
    without notice if (when) any spam is received.

    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Paul Sprangers@3:633/10 to All on Wednesday, November 11, 2026 19:25:34
    In article <5d3628e1b7News04@avisoft.f9.co.uk>,
    Martin <News04@avisoft.f9.co.uk> wrote:

    As a specific example, it works but does have some limitations.
    The most obvious one is that any characters not included in FNcase are omitted from the sort key completely (eg blank or hyphen).

    You're right, Martin. But it is deliberate indeed. I should have mentioned
    that the program sorts lines *alphabetically*, reason why it omits
    characters like spaces, hyphens, dots, colons etc. completely.

    I also left out ArmSort, because I wanted to show code that does it all by
    its self.

    I suspect however that as FNcase tests each character 29 times, it could
    be optimised.

    Absolutely. My database program sorts the same 6000 lines in a fraction of
    a second, font painting the result on screen included. But hm... I should
    wade through the rivers of code for finding out how I did that. And even
    then I'm afraid that I would no longer understand it.
    Oh youth, thou treacherous promise!

    Paul

    --
    https://riscos.sprie.nl

    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Jean-Michel@3:633/10 to All on Wednesday, November 11, 2026 20:36:03
    In message <5d3622ac84Paul@sprie.nl>
    Paul Sprangers <Paul@sprie.nl> wrote:

    I've written a short BASIC program that sorts the lines in a text file, taking capitals, undercasts and all sorts of diacritics, as well most other characters into account.

    My own example has nearly 6000 lines.
    The BASIC version took about 23 seconds to sort them, while the compiled version took less than 3 seconds to do the job. (On a 4t?2 computer.)

    The text file is not included, but you should rename yours to "Texts" in order to let the program do its work. If your text file counts more than
    6000 lines, you should change the DIM's in the program. Compile the program with the freely available !ABC compiler. Remember that the compiled version needs quite a big NEXT slot.

    There are much better or memory friendly ways to do this, but as an example it may have some use.

    Paul



    REM DIM two string arrays,
    REM big enough to store your lines.
    REM My example had 5913 lines.

    DIM text$(5913), dummy$(5913)

    REM Now store every line into both arrays.
    REM The dummy array will be adjusted on the fly,
    REM by changing undercast into capitals and by
    REM removing diacritics, in FNcase (see botom).

    f%=OPENIN("Texts")
    IF f%>0 THEN
    a%=0
    REPEAT
    a%+=1
    text$(a%) = GET$#f%
    dummy$(a%) = FNcase(text$(a%))
    UNTIL EOF#f%
    ENDIF
    IF f%>0 THEN CLOSE#f%

    REM NOW the actual sorting will start

    OK% = TRUE
    time = TIME

    PROCsort

    t = TIME - time : REM The time needed in centiseconds.

    REM Finally, print the sorted lines

    FOR i% = 1 TO a% : PRINT STR$(i%) +": " + text$(i%) : NEXT
    PRINT t
    END


    DEF PROCsort
    FOR i% = 1 TO a%
    IF dummy$(i%) < dummy$(i%-1) THEN
    SWAP text$(i%),text$(i%-1)
    SWAP dummy$(i%),dummy$(i%-1)
    OK% = FALSE
    ENDIF
    NEXT
    IF NOT OK% THEN OK% = TRUE : PROCsort
    ENDPROC


    DEF FNcase(x$)
    y$=""
    FOR j%= 1 TO LEN x$
    c%=ASC(MID$(x$,j%,1))
    IF c%>96 AND c%<123 THEN y$ += CHR$(c%-32) : REM undercast -> capital
    IF c%>47 AND c%< 58 THEN y$ += CHR$(c%) : REM numbers don't change
    IF c%>64 AND c%< 91 THEN y$ += CHR$(c%) : REM capitals don't change
    IF c%>223 AND c%<230 THEN y$ += "A" : REM diacritics removed
    IF c%>231 AND c%<231 THEN y$ += "E"
    IF c%>235 AND c%<240 THEN y$ += "I"
    IF c%>241 AND c%<247 THEN y$ += "O"
    IF c%>248 AND c%<253 THEN y$ += "U"
    IF c%=229 OR c%=197 THEN y$ += "A"
    IF c%=230 OR c%=198 THEN y$ += "AE"
    IF c%=231 OR c%=199 THEN y$ += "C"
    IF c%=241 OR c%=209 THEN y$ += "N"
    IF c%=248 OR c%=216 THEN y$ += "O"
    IF c%=223 THEN y$ += "SS"
    IF c%=255 THEN y$ += "Y"
    NEXT
    =y$

    Interesting, good ASCII table usage.
    Just a little error, for E "diacritics", sorry I am French, we have many.

    IF c%>231 AND c%<231 THEN y$ += "E"
    => IF c%>231 AND c%<236 THEN y$ += "E"

    I am waiting the same for UTF8...

    --
    Jean-Michel

    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Paul Sprangers@3:633/10 to All on Wednesday, November 11, 2026 22:55:49
    In article <bdd535365d.jmb@jmc.bruck.orange.fr>,
    Jean-Michel <jmc.bruck@orange.fr> wrote:

    IF c%>231 AND c%<231 THEN y$ += "E"
    => IF c%>231 AND c%<236 THEN y$ += "E"

    Well spotted! Silly typo of mine.

    I am waiting the same for UTF8...

    Don't hold your breath...

    Paul

    --
    https://riscos.sprie.nl

    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Sebastian Barthel@3:633/10 to All on Monday, November 16, 2026 18:31:20
    Am Wed, 11 Nov 2026 19:25:34 +0100 schrieb Meister Paul Sprangers:

    In article <5d3628e1b7News04@avisoft.f9.co.uk>,
    Martin <News04@avisoft.f9.co.uk> wrote:

    As a specific example, it works but does have some limitations.
    The most obvious one is that any characters not included in FNcase are
    omitted from the sort key completely (eg blank or hyphen).

    You're right, Martin. But it is deliberate indeed. I should have
    mentioned that the program sorts lines *alphabetically*, reason why it
    omits characters like spaces, hyphens, dots, colons etc. completely.

    I also left out ArmSort, because I wanted to show code that does it all
    by its self.

    I suspect however that as FNcase tests each character 29 times, it
    could be optimised.


    And even then I'm afraid that I would no longer understand it.

    I don't understand what this line

    IF dummy$(i%) < dummy$(i%-1) THEN

    does. It compares two string - OK. But what is a string "bigger" than
    another ?

    It is a sort of hidden sorting ? If so, then there should eventually be a variable that decribes the form of this sorting. A to Z oder Z to A or
    Numbers included etc.


    To make this thing faster there (s)could be third array - with numbers in
    it. This should be an integer array which points to the text$ and dummy$ array, simply by numbering them as 1, 2, 3, 4 and so on.
    To sort these one would do the same as in the progam shown, but the SWAP
    isn't done in the string-array; only in the integer-array. Every test
    needed is done by using the numbers in integer-array as index-numbers
    into the strings. Should be a LOT faster.

    At the end the output is generated by printing the strings as pointed to
    by the now sorted index-numbers in ascending from 0 to top in the integer- array.


    --
    abra-ka-da-bra , mumble , mumble , wau , miau - swoosh und wech

    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Paul Sprangers@3:633/10 to All on Monday, November 16, 2026 20:15:54
    In article <11dfi5o$1l3bi$1@solani.org>,
    Sebastian Barthel <naitsabes@freenet.de> wrote:

    I don't understand what this line
    IF dummy$(i%) < dummy$(i%-1) THEN
    does. It compares two string - OK. But what is a string "bigger" than another ?

    A string is 'bigger' than another if it alphabetically comes after the
    other one. "Sebastian Barthel" is bigger than "Sebestian Bach"!

    The point is that BASIC only looks at the ASCII value of characters for determining the alphabetical flow. Therefore it puts 'C?line' after
    'Coline', for example.

    The other point was that OP's original routine takes 12.7 seconds to sort a list of over 4000 lines and still has the 'C?line' problem, while a simple BASIC program (okay, compiled) sorts 6000 lines without that problem in
    about 3 seconds.

    But of course, this simple program can be enhanced a lot further in many
    ways, one of which is sorting pointers rather than strings, as you already pointed out.

    Paul

    --
    https://riscos.sprie.nl

    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Martin@3:633/10 to All on Monday, November 16, 2026 19:17:14
    In article <11dfi5o$1l3bi$1@solani.org>,
    Sebastian Barthel <naitsabes@freenet.de> wrote:
    Am Wed, 11 Nov 2026 19:25:34 +0100 schrieb Meister Paul Sprangers:

    In article <5d3628e1b7News04@avisoft.f9.co.uk>,
    Martin <News04@avisoft.f9.co.uk> wrote:

    As a specific example, it works but does have some limitations.
    The most obvious one is that any characters not included in
    FNcase are omitted from the sort key completely (eg blank or
    hyphen).

    You're right, Martin. But it is deliberate indeed. I should have
    mentioned that the program sorts lines *alphabetically*, reason
    why it omits characters like spaces, hyphens, dots, colons etc.
    completely.

    I also left out ArmSort, because I wanted to show code that does
    it all by its self.

    I suspect however that as FNcase tests each character 29 times,
    it could be optimised.


    And even then I'm afraid that I would no longer understand it.

    I don't understand what this line

    IF dummy$(i%) < dummy$(i%-1) THEN

    does. It compares two string - OK. But what is a string "bigger"
    than another ?

    It is a sort of hidden sorting ? If so, then there should
    eventually be a variable that decribes the form of this sorting. A
    to Z oder Z to A or Numbers included etc.

    No, it is not hidden. The word is not 'bigger' but 'higher' as in the
    ASCI values of each character are compared, so "A"<"B"<"C" etc.

    To make this thing faster there (s)could be third array - with
    numbers in it. This should be an integer array which points to the
    text$ and dummy$ array, simply by numbering them as 1, 2, 3, 4 and
    so on. To sort these one would do the same as in the progam shown,
    but the SWAP isn't done in the string-array; only in the
    integer-array. Every test needed is done by using the numbers in integer-array as index-numbers into the strings. Should be a LOT
    faster.

    No, it would be slower, because a SWAP of two strings in arrays
    already does exactly what you describe: it exchanges pointers to the
    strings, not the strings themselves.

    --
    Martin Avison
    Note that unfortunately this email address will become invalid
    without notice if (when) any spam is received.

    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Bob Latham@3:633/10 to All on Tuesday, November 17, 2026 09:11:31
    In article <5d38c72b71Paul@sprie.nl>,
    Paul Sprangers <Paul@sprie.nl> wrote:

    A string is 'bigger' than another if it alphabetically comes after
    the other one. "Sebastian Barthel" is bigger than "Sebestian Bach"!

    The point is that BASIC only looks at the ASCII value of characters
    for determining the alphabetical flow. Therefore it puts 'C?line'
    after 'Coline', for example.

    The other point was that OP's original routine takes 12.7 seconds
    to sort a list of over 4000 lines and still has the 'C?line'
    problem, while a simple BASIC program (okay, compiled) sorts 6000
    lines without that problem in about 3 seconds.

    But of course, this simple program can be enhanced a lot further in
    many ways, one of which is sorting pointers rather than strings, as
    you already pointed out.

    Sorry guys, I've been unwell for a few days so updates.

    I've got the sort time down to 5 seconds and this includes a 'C?line'
    fix.

    It's crude yes but it works and it's quite fast. I repeatedly scan
    scan though the file and each pass copy the bets lie to another file
    and of course I mark the line as invalid in the first file.
    Eventually, a scan finds nothing left and we're done.

    The room for the second file comes from an expanded wimp slot which
    is reduced back agin when the sort is complete.

    For my 'C?line' fix i noticed that the possible problem characters
    are for the most part form &C0 upwards and so I simply have a
    substitution table for those chars which is only used in the
    comparison section, I don't actually change the characters.

    I don't know if I can add a little code here but here is the core of
    my sort routine ...

    ADR R4,treat_as-&C0

    .BSFLpx23 CMP R10,R11
    BCS BCSLpx88; end of file

    LDRB R0,[R6],#1; BSF
    LDRB R0,[R0,R12]; convert to lower case
    CMP R0,#&C0
    LDRCSB R0,[R0,R4]

    LDRB R3,[R8],#1; New Challenger
    LDRB R3,[R3,R12]; convert to lower case
    CMP R3,#&C0
    LDRCSB R3,[R3,R4]

    CMP R3,R0; new,bsf
    BEQ BSFLpx23
    STRCC R10,bestSOFAR
    ;------------


    .treat_as EQUS"AAAAAA?CEEEEIIII"
    EQUS"DNOOOOO??UUUUY??"
    EQUS"aaaaaa?ceeeeiiii"
    EQUS"onooooo??uuuuy??":ALIGN

    Thanks everyone.

    Bob.


    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)