sorting fixed strings. not important, just curiosity

Just starting out? Need help? Post your questions and find answers here.
noxidderf
User
User
Posts: 18
Joined: Thu Oct 03, 2024 5:31 pm

sorting fixed strings. not important, just curiosity

Post by noxidderf »

was reading the help file and i saw that "Fixed strings are not supported by the sort routine."
I am not using one at the moment but I keep thinking about it.
I searched some but I did not read anything touching on my question.

I am wondering why it is not possible ? just curiosity, not looking for a indepth explanation.

is that something I would need to figure out how to do if I run into it,

I might be just being dumb here. I get stuck on these questions from time to time.


Fred, it is finally cooling off here. (-:
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: sorting fixed strings. not important, just curiosity

Post by RASHAD »

Hi
Maybe you can use ListIcon() gadget populate it with your strings then sort it
I can't tell about MAC or Linux but it works with Windows :D
Egypt my love
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: sorting fixed strings. not important, just curiosity

Post by wilbert »

You can use CustomSortArray() to sort fixed strings.

Code: Select all

Structure FS10
  s.s{10}
EndStructure

Procedure CompareFS10(*a.FS10, *b.FS10)
  ProcedureReturn CompareMemoryString(*a, *b, #PB_String_NoCase, 10)
EndProcedure

Dim s.s{10}(4)

s(0)="GHI"
s(1)="abc"
s(2)="MNO"
s(3)="JKL"
s(4)="DEF"

Debug "Unsorted"
For i=0 To 4
  Debug s(i)
Next

Debug ""

CustomSortArray(s(), @CompareFS10(), #PB_Sort_Ascending)

Debug "Sorted"
For i=0 To 4
  Debug s(i)
Next
Windows (x64)
Raspberry Pi OS (Arm64)
noxidderf
User
User
Posts: 18
Joined: Thu Oct 03, 2024 5:31 pm

Re: sorting fixed strings. not important, just curiosity

Post by noxidderf »

I lay back after my alarm went off this morning., and thought about my question.
It is just a block of memory with the fixed string information in one long block I would guess.

Wow, so many functions. I had not run across those yet. I am blown away with all the connivance.
thanks for pointing out the customsorts.
noxidderf
User
User
Posts: 18
Joined: Thu Oct 03, 2024 5:31 pm

Re: sorting fixed strings. not important, just curiosity

Post by noxidderf »

question about the example.
the length of the strings is 4 for 3 letters/symbols, is that to account for the 0 strings terminator ?
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: sorting fixed strings. not important, just curiosity

Post by wilbert »

noxidderf wrote: Wed Oct 30, 2024 4:03 pm the length of the strings is 4 for 3 letters/symbols, is that to account for the 0 strings terminator ?
A fixed string always occupies the maximum string length in memory.
The maximum length of each .s{10} string is 10 characters. I just didn't use all 10 of them.

The 4 in Dim s.s{10}(4) is the size of the array.
PureBasic uses the highest index (starting from 0) instead of the true array size so in this case the array contains 5 items (0 .. 4).
Windows (x64)
Raspberry Pi OS (Arm64)
AZJIO
Addict
Addict
Posts: 2141
Joined: Sun May 14, 2017 1:48 am

Re: sorting fixed strings. not important, just curiosity

Post by AZJIO »

noxidderf wrote: Wed Oct 30, 2024 4:03 pm question about the example.
the length of the strings is 4 for 3 letters/symbols, is that to account for the 0 strings terminator ?

Code: Select all

Dim s.s{3}(4)

s(0)="abc"
s(1)="def"
s(2)="ghi"
s(3)="jkl"
s(4)="mno"

Debug PeekS(@s(0), 3*5)
Debug PeekS(@s(0), 3 * (ArraySize(s()) + 1))
Another example

Code: Select all

arrsize = 8
#StrLength = 3
Dim s.s{#StrLength}(arrsize)
Define *t.Character

*t = @s(0)
For i = Abs('A') To Abs('A') + (arrsize + 1) * #StrLength ; Abs('z') 
	*t\c = i
	*t + SizeOf(Character)
Next

For i = 0 To ArraySize(s()) 
	Debug Str(i) + " " + s(i)
Next
noxidderf
User
User
Posts: 18
Joined: Thu Oct 03, 2024 5:31 pm

Re: sorting fixed strings. not important, just curiosity

Post by noxidderf »

got it, thanks. I needed coffee this morning.
Post Reply