Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 07:52 23 Nov 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 : [PicoMites] Feature request regarding "Sort" command.

Author Message
twofingers
Guru

Joined: 02/06/2014
Location: Germany
Posts: 1236
Posted: 11:47am 29 Sep 2024
Copy link to clipboard 
Print this post

Feature request regarding "Sort" command.

For example, if we fill an array A$(10) with data from file names, then
we have the following:

A$(0)="EName"
A$(1)="CName"
A$(2)="AName"
A$(3)="BName"
A$(4)="DName"
A$(5)=""
A$(6)=""
A$(7)=""
A$(8)=""
A$(9)=""


But we want this:

A$(0)="AName"
A$(1)="BName"
A$(2)="CName"
A$(3)="DName"
A$(4)="EName"
A$(5)=""
A$(6)=""
A$(7)=""
A$(8)=""
A$(9)=""


The (string) sort command sorts without any further parameters like this:

A$(0)=""
A$(1)=""
A$(2)=""
A$(3)=""
A$(4)=""
A$(5)="AName"
A$(6)="BName"
A$(7)="CName"
A$(8)="DName"
A$(9)="EName"


SORT currently has the following parameters
  Quote  //SORT array() [,indexarray()]
[,flags] [,startposition]
[,elementstosort]


I imagine that we could, for example, introduce an additional flag bit (bit 3 = 4) for the sorting that considers empty strings as "biggest". The possible sorting with the specification of the number of elements to be sorted can create additional problems, e.g. if the array contains deleted, obsolete data.

I would be happy about that! Thank you for your patience and time!
Even if you ignore the suggestion! ;-)

Best regards
Michael

PS
I will probably be unavailable for the next few days (hospital)
causality ≠ correlation ≠ coincidence
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 9100
Posted: 04:48pm 29 Sep 2024
Copy link to clipboard 
Print this post

Please test this - standard RP2040 PicoMite version. Use Bit 2 to indicate that position of blank strings should be reversed in the sort order works, in both normal and reverse sort. In each case the position of the blanks is reversed from the normal order.


PicoMite.zip


Updated 17:50 UTC
Edited 2024-09-30 03:50 by matherp
 
twofingers
Guru

Joined: 02/06/2014
Location: Germany
Posts: 1236
Posted: 06:09pm 29 Sep 2024
Copy link to clipboard 
Print this post

Hi Peter, thanks for the quick reply. I think you didn't understand me correctly. It's not about strings with spaces, but about empty strings. These empty strings should be at the end of the array. The normal, non-empty strings should be at the beginning of the array.

That's what i want as the result:
A$(0)="AName"
A$(1)="BName"
A$(2)="CName"
A$(3)="DName"
A$(4)="EName"
A$(5)=""
A$(6)=""
A$(7)=""
A$(8)=""
A$(9)=""


This is the test program:
Dim a$(10)
A$(0)="AName"
A$(1)="BName"
A$(2)="CName"
A$(3)="DName"
A$(4)=""
A$(5)="EName"
A$(6)=""
A$(7)=""
A$(8)=""
A$(9)=""

Print
Print "befor sort:"
For i = 0To 9
 Print i, ">"a$(i)"<"
Next

Sort a$(),,4
Print
Print "after sort:"

For i = 0To 9
 Print i, ">"a$(i)"<"
Next

End


Output from your PicoMite.zip (standard RP2040):
with flag bit2 = True
(Sort a$(),,4)
befor sort:
0      >AName<
1      >BName<
2      >CName<
3      >DName<
4      ><
5      >EName<
6      ><
7      ><
8      ><
9      ><

after sort:
0      ><
1      ><
2      ><
3      ><
4      ><
5      ><
6      ><
7      ><
8      ><
9      ><


with flag bit0 = 1
(Sort a$(),,1)
befor sort:
0      >AName<
1      >BName<
2      >CName<
3      >DName<
4      ><
5      >EName<
6      ><
7      ><
8      ><
9      ><

after sort:
0      >EName<
1      >DName<
2      >CName<
3      >BName<
4      >AName<
5      ><
6      ><
7      ><
8      ><
9      ><


with flag bit1 = True
(Sort a$(),,2)
0      >AName<
1      >BName<
2      >CName<
3      >DName<
4      ><
5      >EName<
6      ><
7      ><
8      ><
9      ><

after sort:
0      ><
1      ><
2      ><
3      ><
4      ><
5      ><
6      >AName<
7      >BName<
8      >CName<
9      >DName<


Kind regards
Michael


A workaround could be to fill the array with the largest possible strings (strings from several chr$(255)) before use, before assigning the payload. But that would be very inelegant...

PS:
I found a typo at my opening post:
  twofingers said  ... I imagine that we could, for example, introduce an additional flag bit (bit 3 = 4) for the sorting that considers empty strings as "biggest". ...

Correct is flag bit (bit 2 = 4)!
Edited 2024-09-30 04:28 by twofingers
causality ≠ correlation ≠ coincidence
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 9100
Posted: 06:11pm 29 Sep 2024
Copy link to clipboard 
Print this post

Please reload the 17:50 version I posted a duff version first time
 
twofingers
Guru

Joined: 02/06/2014
Location: Germany
Posts: 1236
Posted: 06:35pm 29 Sep 2024
Copy link to clipboard 
Print this post

  matherp said  Please reload the 17:50 version I posted a duff version first time
The version used is from 17:46: Download at 19:18h.




Ragards
Michael
causality ≠ correlation ≠ coincidence
 
twofingers
Guru

Joined: 02/06/2014
Location: Germany
Posts: 1236
Posted: 06:39pm 29 Sep 2024
Copy link to clipboard 
Print this post

Peter, I don't expect you to spend so much time on this now. I'm not available for a few days anyway.
causality ≠ correlation ≠ coincidence
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 9100
Posted: 06:41pm 29 Sep 2024
Copy link to clipboard 
Print this post

AFAIK this version is correct

PicoMite.zip

NB: you should change your program as below otherwise you can get confused


Dim a$(10)
A$(0)="AName"
A$(1)="BName"
A$(2)="CName"
A$(3)="DName"
A$(4)=""
A$(5)="EName"
A$(6)=""
A$(7)=""
A$(8)=""
A$(9)=""

Print
Print "before sort:"
For i = 0 To Bound(a$())
Print i, ">"a$(i)"<"
Next

Sort a$(),,4
Print
Print "after sort:"

For i = 0 To Bound(a$())
Print i, ">"a$(i)"<"
Next

End

Edited 2024-09-30 04:42 by matherp
 
twofingers
Guru

Joined: 02/06/2014
Location: Germany
Posts: 1236
Posted: 06:58pm 29 Sep 2024
Copy link to clipboard 
Print this post

Wow!
Even
Sort a$(),,6

Dim a$(10)
A$(0)="AName"
A$(1)="BName"
A$(2)="bName"
A$(3)="DName"
A$(4)=""
A$(5)="EName"
A$(6)=""
A$(7)=""
A$(8)="XXXXX"
A$(9)="aaaaa"

Print
Print "befor sort:"
For i = 0 To Bound(a$())
 Print i, ">"a$(i)"<"
Next

Sort a$(),,6
Print
Print "after sort:"

For i = 0 To Bound(a$())
 Print i, ">"a$(i)"<"
Next

End


Output Bit1+Bit2:
befor sort:
0      >AName<
1      >BName<
2      >bName<
3      >DName<
4      ><
5      >EName<
6      ><
7      ><
8      >XXXXX<
9      >aaaaa<
10     ><

after sort:
0      >aaaaa<
1      >AName<
2      >BName<
3      >bName<
4      >DName<
5      >EName<
6      >XXXXX<
7      ><
8      ><
9      ><
10     ><


Fantastic! I am totally happy!      
I'm sprachlos!

Now I can go to bed!

Michael
causality ≠ correlation ≠ coincidence
 
Print this page


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

© JAQ Software 2024