dominoExperts.com - Powered by Domino 8.5.2 Domino Accelerator Pack
- Cache, Combine, JS-Minify and Compress content
Lotus Triple Search DominoExperts + Blogs + R8 forum
dominoExperts.com -> Script vault -> Lotus Script

 Very fast sorting algorithm


Kenneth HaggmanPost date: 2007-04-27 11:40

There is an abundance of sorting algorthms 'out there'.
Too often I find myself, by force of habit, using bubble-sort.
For large arrays, the sorting algorithms below - shell sort - has proven itself to be extremely fast.

Sub shellSort( ar( ) As String )
Dim Lower As Integer
Dim Upper As Integer
Dim botMax As Integer
Dim i As Integer
Dim k As Integer
Dim h As Integer
Dim v As String

Lower% = Lbound( ar$( ) )
Upper% = Ubound( ar$( ) )

h% = 1
Do
h% = (3*h%) + 1
Loop Until h% > Upper%-Lower%+1
Do
h% = h% \ 3
botMax% = Lower% + h% - 1
For i% = botMax% + 1 To Upper%
v$ = ar$( i% )
k% = i%
While ar$( k% - h% ) > v$
ar$( k% ) = ar$( k% - h% )
k% = k% - h%
If (k% <= botMax%) Then Goto wOut
Wend
wOut:
If (k% <> i%) Then ar$(k%) = v$
Next
Loop Until h% = 1
End Sub

Tomas NielsenPost date: 2007-04-27 15:16

Nice one!

Have you compared it to using Evaluate(|@Sort(array)|, doc) ?

Or maybe you mean really big arrays that do not fit in a field?


Joacim BoivePost date: 2007-05-10 15:47

Cool Kenneth!

I found a "bug" in your code. With an array of 32767 you get overflow so you need to declare you integer variables to something larger like Long or Double. Probably you should write it as a function as well, makes it more useful..

 

Tomas - I took the liberty to do a very quick comparison.

Kennets solution did sort an array containing 32767 entries of seven figure numbers in around 3000 msec.

You solution could only hold around 16000 entries with two figur numbers and did a sort in 800Msec.

Kenneths solution with the same settings: 1000msec

 

This on a client running notes R7.01 and with profiling enabled to get the results.

 

Kenneths solution is way more flexible and personally I like to stay away from Evaluate as much as possible, the performance is at least similar.

 

/Jocke

 




RSS feed
Subscribe to Forum

Share this page

Top posters
Tomas Nielsen212
Joacim Boive27
Fredrik Stöckel27
Danne14
Niklas Waller13
Kenneth Haggman11
Bryan Kuhn10
Daniel Lehtihet9
Jonas Israelsson8
dm997