Hello,
I'm pretty new to PureBasic, coming from XProfan like some other people here. I have 2 things to say (beside, that this module is really great!):
First, there's a bug in the code, or let's say some "unwanted behaviour". Looking at the comparison functions (I picked "CompareFloat" to demonstrate it) sorting is not stable:
Code: Select all
Procedure CompareFloat(sEntry1.s, sEntry2.s, SortOrder.b)
; ' -----------------------------------------------------
; ' Gibt zurück, ob das erste der beiden unterschiedlichen
; ' Elemente nach Maßgabe des Parameters SortOrder größer
; ' (1 bei aufsteigender Sortierung) oder kleiner (-1 bei
; ' aufsteigender Sortierung) als das zweite Element ist.
; ' Gleiche Elemente wurden bereits in CompareFunc ausge-
; ' schlossen; für sie wäre sonst 0 zurückzugeben.
; ' -----------------------------------------------------
; ' Rückgabewert je nach erwünschter Sortierung:
ReplaceString(sEntry1, ",", ".", #PB_String_InPlace, 1, 1) ; ersetze Dezimalkomma durch Punkt, damit ValF korrekt arbeitet
ReplaceString(sEntry2, ",", ".", #PB_String_InPlace, 1, 1)
If SortOrder = #AscSort
; Aufsteigende Sortierung zweier unterschiedlicher Zahlen
If ValF(sEntry1) < ValF(sEntry2)
ProcedureReturn -1
Else
ProcedureReturn 1
EndIf
Else ; Absteigende Sortierung
If ValF(sEntry1) > ValF(sEntry2)
ProcedureReturn -1
Else
ProcedureReturn 1
EndIf
EndIf
EndProcedure
When sorting ascending this code looks up if the first entry lower than the second. If so it stays the same, otherwise they are swapped. If both entries are the same, they are swapped. This is usually not wanted. It should be either
Code: Select all
If ValF(sEntry1) <= ValF(sEntry2)
or
for ascending sorting. this would make sorting stable.
https://en.wikipedia.org/wiki/Sorting_a ... #Stability
Second: If possible I would like to get some enhancements, but if not I will do them by myself (it will just take longer since I'm very new to PureBasic). I would really appreciate some more functions, including RefreshSort (do the last sort again, I need this for a ListIconGadget that is cleared and filled again), SortNow (sort a ListIconGadget by a selected Column and Order (I already edited the code for myself to do this)) and ResetSort (speaks for itself.)