Just want to test this sorting algorithm:
Code: Select all
'StrCmpLogicalW Returns 0 if S1=S2. 1 if S1>S2. -1 if S1<S2.
'0 if same
'1 if string 1 is larger than string 2
'-1 if string 1 is smaller than string 2
Declare Function StrCmpLogicalW Lib "shlwapi" (ByVal lpStr1 As Long, ByVal lpStr2 As Long) As integer
Declare Function VarPtr Lib "msvbvm60.dll" Alias "VarPtr" (lpObject As any) As Long
Sub GnomeSort(byref pvarArray As variant)
Dim i As Long, j As Long, iMin As Long, iMax As Long, varSwap As variant
iMin = LBound(pvarArray) + 1
iMax = UBound(pvarArray)
i = iMin
j = i + 1
Do While i <= iMax
If StrCmpLogicalW(StrPtr(pvarArray(i)), StrPtr(pvarArray(i - 1))) = -1 Then
varSwap = pvarArray(i)
pvarArray(i) = pvarArray(i - 1)
pvarArray(i - 1) = varSwap
If i > iMin Then i = i - 1
Else
i = j
j = j + 1
End If
Loop
End Sub
Code: Select all
StrCmpLogicalW(StrPtr(pvarArray(i)), StrPtr(pvarArray(i - 1))) = -1
Code: Select all
StrCmpLogicalW(VarPtr(pvarArray(i)), VarPtr(pvarArray(i - 1))) = -1
I dont know if we can avoid the use of these two win32 apis by some way, but the interesting on it is to do the logical comparison the most speeding up.
For example this direct comparison works but it is extremelly slow and not valid for the purpose:
Code: Select all
If pvarArray(i) < pvarArray(i - 1) Then
Some help ? thx in advance