Thread View: comp.sys.acorn.programmer
23 messages
23 total messages
Started by Bob Latham
Fri, 06 Nov 2026 08:45
Sorting algorithms
Author: Bob Latham
Date: Fri, 06 Nov 2026 08:45
Date: Fri, 06 Nov 2026 08:45
39 lines
2317 bytes
2317 bytes
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.
Re: Sorting algorithms
Author: Jean-Michel
Date: Fri, 06 Nov 2026 16:30
Date: Fri, 06 Nov 2026 16:30
50 lines
3045 bytes
3045 bytes
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
Re: Sorting algorithms
Author: Bob Latham
Date: Fri, 06 Nov 2026 17:57
Date: Fri, 06 Nov 2026 17:57
14 lines
1148 bytes
1148 bytes
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.
Re: Sorting algorithms
Author: Jean-Michel
Date: Fri, 06 Nov 2026 19:28
Date: Fri, 06 Nov 2026 19:28
28 lines
1936 bytes
1936 bytes
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
Re: Sorting algorithms
Author: Paul Sprangers
Date: Sat, 07 Nov 2026 12:36
Date: Sat, 07 Nov 2026 12:36
15 lines
1666 bytes
1666 bytes
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
Re: Sorting algorithms
Author: Jean-Michel
Date: Sat, 07 Nov 2026 17:55
Date: Sat, 07 Nov 2026 17:55
23 lines
1969 bytes
1969 bytes
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
Re: Sorting algorithms
Author: Paul Sprangers
Date: Sat, 07 Nov 2026 18:41
Date: Sat, 07 Nov 2026 18:41
14 lines
1618 bytes
1618 bytes
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
Re: Sorting algorithms
Author: Martin
Date: Sat, 07 Nov 2026 19:48
Date: Sat, 07 Nov 2026 19:48
21 lines
2137 bytes
2137 bytes
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.
Re: Sorting algorithms
Author: Bob Latham
Date: Sun, 08 Nov 2026 12:13
Date: Sun, 08 Nov 2026 12:13
28 lines
2156 bytes
2156 bytes
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.
Re: Sorting algorithms
Author: Paul Sprangers
Date: Wed, 11 Nov 2026 16:06
Date: Wed, 11 Nov 2026 16:06
95 lines
3795 bytes
3795 bytes
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
Re: Sorting algorithms
Author: Martin
Date: Wed, 11 Nov 2026 17:14
Date: Wed, 11 Nov 2026 17:14
43 lines
2866 bytes
2866 bytes
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.
Re: Sorting algorithms
Author: Paul Sprangers
Date: Wed, 11 Nov 2026 18:25
Date: Wed, 11 Nov 2026 18:25
27 lines
2154 bytes
2154 bytes
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
Re: Sorting algorithms
Author: Jean-Michel
Date: Wed, 11 Nov 2026 19:36
Date: Wed, 11 Nov 2026 19:36
106 lines
4346 bytes
4346 bytes
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
Re: Sorting algorithms
Author: Paul Sprangers
Date: Wed, 11 Nov 2026 21:55
Date: Wed, 11 Nov 2026 21:55
16 lines
1447 bytes
1447 bytes
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
Re: Sorting algorithms
Author: Sebastian Barthel
Date: Mon, 16 Nov 2026 18:31
Date: Mon, 16 Nov 2026 18:31
49 lines
2965 bytes
2965 bytes
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
Re: Sorting algorithms
Author: Paul Sprangers
Date: Mon, 16 Nov 2026 19:15
Date: Mon, 16 Nov 2026 19:15
28 lines
2275 bytes
2275 bytes
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
Re: Sorting algorithms
Author: Martin
Date: Mon, 16 Nov 2026 19:17
Date: Mon, 16 Nov 2026 19:17
57 lines
3439 bytes
3439 bytes
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.
Re: Sorting algorithms
Author: Bob Latham
Date: Tue, 17 Nov 2026 09:11
Date: Tue, 17 Nov 2026 09:11
70 lines
3466 bytes
3466 bytes
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.
Re: Sorting algorithms
Author: Matthew Phillips
Date: Wed, 25 Nov 2026 20:05
Date: Wed, 25 Nov 2026 20:05
28 lines
2510 bytes
2510 bytes
In message <5d3913ac38bob@sick-of-spam.invalid> on 17 Nov 2026 Bob Latham wrote: > 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. > 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. You might like to consider the SWI Territory_Collate which has options to ignore both case and accents. I see from RISC OS 5.22 onwards it can even interpret numbers in the string and sort them more naturally. It will probably slow things down a little as a SWI will always be slower than an optimised routine in assembly language. -- Matthew Phillips Durham
Re: Sorting algorithms
Author: Bob Latham
Date: Wed, 25 Nov 2026 21:07
Date: Wed, 25 Nov 2026 21:07
10 lines
1272 bytes
1272 bytes
In article <163f6e3d5d.Matthew@sinenomine.co.uk>, Matthew Phillips <spam2011m@yahoo.co.uk> wrote: > You might like to consider the SWI Territory_Collate which has > options to ignore both case and accents. That's interesting, thanks for that. Bob.
Re: Sorting algorithms
Author: Jean-Michel
Date: Thu, 26 Nov 2026 11:50
Date: Thu, 26 Nov 2026 11:50
20 lines
1893 bytes
1893 bytes
In message <5d3d73e064bob@sick-of-spam.invalid>
Bob Latham <bob@sick-of-spam.invalid> wrote:
> In article <163f6e3d5d.Matthew@sinenomine.co.uk>,
> Matthew Phillips <spam2011m@yahoo.co.uk> wrote:
>> You might like to consider the SWI Territory_Collate which has
>> options to ignore both case and accents.
> That's interesting, thanks for that.
Yes, but don't forget Céline is Canadian/French...
> Bob.
--
Jean-Michel
Re: Sorting algorithms
Author: Harriet Bazley
Date: Thu, 26 Nov 2026 22:32
Date: Thu, 26 Nov 2026 22:32
52 lines
2915 bytes
2915 bytes
On 26 Nov 2026 as I do recall,
Jean-Michel wrote:
> In message <5d3d73e064bob@sick-of-spam.invalid>
> Bob Latham <bob@sick-of-spam.invalid> wrote:
>
> > In article <163f6e3d5d.Matthew@sinenomine.co.uk>,
> > Matthew Phillips <spam2011m@yahoo.co.uk> wrote:
>
> >> You might like to consider the SWI Territory_Collate which has
> >> options to ignore both case and accents.
>
> > That's interesting, thanks for that.
>
> Yes, but don't forget Céline is Canadian/French...
>
I only have Territory 1 (UK) on this computer so can't use other
territory numbers to test, but Territory_Collate certainly sorts Céline
and Coline correctly for me...
DIM block% 256
DATA Céline,Celine,Celine1,Celia,Coline,XXX
items%=0: name$=""
WHILE name$<>"XXX"
READ name$
PRINT name$
$(block%+items%*16)=name$+CHR$(0)
items%+=1
ENDWHILE
items%-=1
PRINT "Press space bar to repeat, or any other key to end"
REPEAT
str2%=RND(items%)-1
SYS"Territory_Collate",-1,block%,block%+str2%*16,3 TO result%
PRINT result%
CASE TRUE OF
WHEN result%>0:outcome$="greater than"
WHEN result%=0:outcome$="equal to"
WHEN result%<0:outcome$="less than"
ENDCASE
PRINT $block%;" is ";outcome$;" ";$(block%+str2%*16)
UNTIL GET<>32
--
Harriet Bazley == Loyaulte me lie ==
ObChocolate: Nice!
Re: Sorting algorithms
Author: Martin
Date: Thu, 26 Nov 2026 23:16
Date: Thu, 26 Nov 2026 23:16
34 lines
2727 bytes
2727 bytes
In article <7d8cff3d5d.harriet@bazleyfamily.co.uk>, Harriet Bazley <harriet@bazleyfamily.co.uk> wrote: > On 26 Nov 2026 as I do recall, > Jean-Michel wrote: > > In message <5d3d73e064bob@sick-of-spam.invalid> > > Bob Latham <bob@sick-of-spam.invalid> wrote: > > > > > In article <163f6e3d5d.Matthew@sinenomine.co.uk>, > > > Matthew Phillips <spam2011m@yahoo.co.uk> wrote: > > > > >> You might like to consider the SWI Territory_Collate which has > > >> options to ignore both case and accents. > > > > > That's interesting, thanks for that. > > > > Yes, but don't forget Céline is Canadian/French... [Snip] > $(block%+items%*16)=name$+CHR$(0) That illustrates one of the problems with using Territory_Collate - it needs zero terminated strings, but BASIC strings are cr terminated, or have a length and no terminator. So each string needs a zero adding before the collate - probably requiring a copy of the string, and removing the null afterwards. For small numbers of strings that is not a problem, but with thousands of strings it will be an overhead of both time and memory. -- Martin Avison Note that unfortunately this email address will become invalid without notice if (when) any spam is received.
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads