Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 21:16 20 Apr 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : CMM2: V5.06.00b1 - Pages and Pages

     Page 3 of 3    
Author Message
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8569
Posted: 02:18pm 23 Nov 2020
Copy link to clipboard 
Print this post

  Quote  I already used built-in SOR() methods, but something stopped me from use it)


is that because the sort takes into account case? If so it would be easy to add an additional parameter to indicate ignore case
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 3833
Posted: 02:21pm 23 Nov 2020
Copy link to clipboard 
Print this post

  matherp said  
  Quote  I already used built-in SOR() methods, but something stopped me from use it)


is that because the sort takes into account case? If so it would be easy to add an additional parameter to indicate ignore case


Yes please ...

... and a parameter to reverse the sort (descending vs. ascending)

... and a lower bound to start the sort from (default Option Base)

... and a number of elements to sort (default all)

If you'd like to make all my library work obsolete, and all my code faster I'd greatly appreciate it

Cheers,

Tom
Edited 2020-11-24 00:22 by thwill
Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 3833
Posted: 02:24pm 23 Nov 2020
Copy link to clipboard 
Print this post

Oh, and if you're looking for a use for that shiny new function slot:
' Case-sensitive binary search for a value in a SORTED array.
'
' @param  a$()    the array.
' @param  s$      the value to search for.
' @param  flags$  "i" to search case-insensitively,
' @param  lb%     the lower bound to search from,
'                 if 0/unset then search from the first element.
' @param  ub%     the upper bound to search from,
'                 if 0/unset then search from the last element.
' @return         the index of the element containing the value,
'                 or -1 if not present.
Function array.bsearch%(a$(), s$, flags$, lb%, ub%)
 Local lb_% = Max(Mm.Info(Option Base), lb%)
 Local ub_% = ub%
 If ub_% = 0 Then ub_% = Bound(a$(), 1)
 Local i%

 If InStr(UCase$(flags$), "I") Then
   Local us$ = UCase$(s$)
   Local ua$
   Do While ub_% >= lb_%
     i% = (lb_% + ub_%) \ 2
     ua$ = UCase$(a$(i%))
     If us$ > ua$ Then
       lb_% = i% + 1
     ElseIf us$ < ua$ Then
       ub_% = i% - 1
     Else
       Exit Do
     EndIf
   Loop
 Else
   Do While ub_% >= lb_%
     i% = (lb_% + ub_%) \ 2
     If s$ > a$(i%) Then
       lb_% = i% + 1
     ElseIf s$ < a$(i%) Then
       ub_% = i% - 1
     Else
       Exit Do
     EndIf
   Loop
 EndIf

 If ub_% >= lb_% Then array.bsearch% = i% Else array.bsearch% = -1
End Function


I've definitely posted too many times today ... no more coffee for this man,

Tom
Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 3833
Posted: 02:28pm 23 Nov 2020
Copy link to clipboard 
Print this post

  jirsoft said  Another argument is listing DIRs before FILEs or mix it. On MacOS is standard sort it mixed, on Windows DIRs first...


At the command line it is also mixed on Windows (at least on Win 10), it's Explorer that puts directories first, though possibly that is configurable.

Regards,

Tom
Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
jirsoft

Guru

Joined: 18/09/2020
Location: Czech Republic
Posts: 532
Posted: 02:40pm 23 Nov 2020
Copy link to clipboard 
Print this post

  matherp said  
  Quote  I already used built-in SOR() methods, but something stopped me from use it)


is that because the sort takes into account case? If so it would be easy to add an additional parameter to indicate ignore case


Yes, I had 2 reasons:
1. case sensitivity
2. half empty static array (but now I got an idea, I could fill it with CHR$(255) before and it will work)

But as Tom writes, SORT(array(), case insesitive, lower limit, upper limit will be just perfect...
Jiri
Napoleon Commander and SimplEd for CMM2 (GitHub),  CMM2.fun
 
vegipete

Guru

Joined: 29/01/2013
Location: Canada
Posts: 1082
Posted: 07:11pm 23 Nov 2020
Copy link to clipboard 
Print this post

  jirsoft said  2. half empty static array (but now I got an idea, I could fill it with CHR$(255) before and it will work)

Great idea!

What is the best method to set an array of strings to a default value, or clear all of the strings to "" (null) ?
Visit Vegipete's *Mite Library for cool programs.
 
     Page 3 of 3    
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024