|
-
May 24th, 2009, 07:31 AM
#1
VB6: All purpose sort
Since VB6 is missing a generic all purpose sort procedures, maybe it would make sense to create one? There are many functions available pretty much everywhere, but not that many that would have a generic speed optimization for VB nor any that would take "anything" and just sort it.
My initial idea would be to have three subs:
Code:
' CaseSensitive sort (A < a, å < ä)
Public Sub Sort(ParamArray Arrays())
End Sub
' Binary sort (A < a, å > ä)
Public Sub SortB(ParamArray Arrays())
End Sub
' CaseInsensitive sort (A = a, å < ä)
Public Sub SortI(ParamArray Arrays())
End Sub
The ParamArray would take any number of arrays, check that the given variables are real string or numeric data type arrays and then also check for dimensions.
There are a few things that require thinking. For strings the obvious one is "which sorting method to use?" – there are quite a few ones out there, for benchmarks I guess the most interesting is Super Fast String Sorts over at PSC. Numeric data types are a bit different case and probably require a different algorithm to use.
Should a simpler but slower sort function be used with small arrays?
One more additional thought: if a control is passed such as ComboBox or ListBox, should that be sorted too? Or worse yet, a control array of those controls? I guess I haven't seen such implementations even though those would be possible to do. As far as I can remember it is possible to get the buffer of a ListBox so it would possible to sort it efficiently with a few memory tricks.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|