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 KingdomPosts: 8569 |
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 KingdomPosts: 3833 |
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 KingdomPosts: 3833 |
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 KingdomPosts: 3833 |
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 RepublicPosts: 532 |
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: CanadaPosts: 1082 |
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 |