|
A generic stable indexed data sorting class
|
|
|
|
Submitted on: 3/11/2009 10:59:50 AM
By: Rde
Level: Intermediate User Rating:
By 14 Users Compatibility:VB 4.0 (32-bit), VB 5.0, VB 6.0
Users have accessed this article
12448 times.
|
|
|
|
|
With this generic solution you can sort any data that is stored in an indexed data storage structure such as lists, collections, and arrays of all data types, including multi-dimensional arrays and arrays of UDTs ...
Three methods are demonstrated - Event raising WithEvents, an Implemented callback, and a clever CallWindowProc technique I picked up from LukeH (selftaught) ...
The Implemented callback method is almost twice as fast as the Event raising method, and is also slightly faster than the CallWindowProc method ...
This is a complete solution that allows you to cancel sorting within the Compare routine, and also a progress parameter that indicates the percentage completed as a long value of 1 to 100. These features are included in the demo ...
Update 21 Feb 2008 tweaked a little speed and attempted to create a level performance test between the CWP method and the other two - now just a few 100ths of a second behind the Implemented method ...
Obscure Bug Fix 7 March 09. I documented they 'can sort sub-sets of the array data' but with these indexed versions if you do an error *could* occur without this very small change.
This article has accompanying files
|
| |
Terms of Agreement:
By using this article, you agree to the following terms...
- You may use
this article in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
- You MAY NOT redistribute this article (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.
- You may link to this article from another website, but ONLY if it is not wrapped in a frame.
- You will abide by any additional copyright restrictions which the author may have placed in the article or article's description.
|
Generic Sorting Classes
You can sort any data that is stored in an indexed data storage structure such as lists, collections, and arrays of all data types, including multi-dimensional arrays and arrays of UDTs.
It is up to you to write the comparison code needed in the exposed Compare routine to suit your particular storage structure and data type.
This is actually the best approach as it hides all the sorting details and leaves you to handle only the comparison code relavant to your current data implementation and desired sort criteria.
This is not intended to be a treatise on sorting multi-dimensional arrays or arrays of UDT's, if this is what you need then psc has has some very good examples on these subjects.
This is intended as a straighforward sorting solution that may be useful if you have a specific need to sort an indexed data structure, and you would like the sorting details to be hidden, and the sorting class's usage to be as simple and as generic as possible.
Each class header has clear instructions on how to implement that particular solution, and this form's code also demonstrates the usage of each sorting class without complicating it with data implementation details.
Free Usage
As usual, you are free to use any part or all of this code even for commercial purposes in any way you wish under the one condition that no copyright notice is moved or removed from where it is.
Happy coding :)
...
|
|
Download article
Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. Afterdownloading it, you will need a program like Winzip to decompress it.Virus note:All files are scanned once-a-day by Planet Source Code for viruses, but new viruses come
out every day, so no prevention program can catch 100% of them. For your own safety, please:
- Re-scan downloaded files using your personal virus checker before using it.
- NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.
- Scan the source code with Minnow's Project Scanner
If you don't have a virus scanner, you can get one at many places on the net
including:McAfee.com
|
Terms of Agreement:
By using this article, you agree to the following terms...
- You may use
this article in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
- You MAY NOT redistribute this article (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.
- You may link to this article from another website, but ONLY if it is not wrapped in a frame.
- You will abide by any additional copyright restrictions which the author may have placed in the article or article's description.
|
|
Other 45 submission(s) by this author
|
|
| |
Report Bad Submission |
|
| |
| Your Vote! |
|
See Voting Log |
| |
| Other User Comments |
4/25/2006 10:14:08 AM: Light Templer
Hi, just my *****, very cool! Regards LiTe (If this comment was disrespectful, please report it.)
|
4/25/2006 12:12:22 PM: Steppenwolfe
Well commented, and well written.. thanks. My 5. (If this comment was disrespectful, please report it.)
|
4/25/2006 3:34:01 PM: Cobein
Exellent like Steppenwolfe say well commented, and well written 5* (If this comment was disrespectful, please report it.)
|
4/26/2006 6:08:06 AM: Paul Turcksin
You did it again! A BIG 5. (If this comment was disrespectful, please report it.)
|
4/27/2006 5:22:22 AM: Rde
Thanks everyone for your generous votes and kind words.
I'm glad you like it.
Happy coding, Rd :)
(If this comment was disrespectful, please report it.)
|
4/27/2006 5:59:13 AM: Rde
You guessed it - i found a bug 8-)
In (Sort and) ReSort sub's the Exit Sub lines at the top must be before the bBuzy = True line !!
Sorry, will re-upload... (If this comment was disrespectful, please report it.)
|
4/27/2006 6:06:07 AM: Rde
The bug described above only occurs in the cStableSorter.cls class in the ReSort sub. (If this comment was disrespectful, please report it.)
|
4/28/2006 12:48:42 PM: Yorgi
Outstanding working code and learning tool! 5***** (If this comment was disrespectful, please report it.)
|
4/28/2006 11:36:06 PM: Rde
Thanks Yorgi (If this comment was disrespectful, please report it.)
|
4/28/2006 11:42:20 PM: Rde
I notice another small omition - the cStableSorter and ICompareClient classes should clearly state that:
"An interface is a contract. You must implement all of the properties and methods in the interface."
The client that implements the ICompareClient interface must always declare the ICompareClient_Compare sub. (If this comment was disrespectful, please report it.)
|
4/29/2006 9:09:16 PM: Option Explicit
Another amazing submission by PSC's "SortMaster". Thanks. (If this comment was disrespectful, please report it.)
|
4/30/2006 5:14:54 AM: Rde
Another small note:
The CallWindowProc method uses a function call into the test form to access the same array used for the sorting test
If you could access your data from within the same standard module as the CallWindowProc callback this could improve the performance to maybe be faster than both the other methods.
I picked up this CallWindowProc method from LukeH, so it's no wonder it is FAST!
Happy coding, Rd :) (If this comment was disrespectful, please report it.)
|
5/10/2006 5:13:03 AM: Rde
You are too kind Option Explicit
An interesting contrast:
I have spend some considerable time developing the binary twister algo over a couple of years now, yet the stable quicksort algo I wrote in one short session and it worked 'out of the box' (no debugging needed!)
Also, it was my work on twister v5's pre-sorter that brought about v2 of the stable quicksort (tv5's pre-sorter is very very similar to the stable qs v2)
cont'd... (If this comment was disrespectful, please report it.)
|
5/10/2006 7:00:18 AM: Rde
The binary twister is still my favourite - even though it is slightly slower on unsorted and reverse sorted operations.
The reason is it is twice as fast as any other algos on resorting operations - not just on fully sorted but also on semi-sorted data it is in a league of its own...
(If this comment was disrespectful, please report it.)
|
5/10/2006 7:10:56 AM: Rde
For example, if you sorted a very large data set that took several seconds, the user would not expect to wait that log again if they edited just one entry and your code refresh sorted the data.
To know a refresh sort will take just a tenth of a second even on a very large data set I feel gives confidence to refresh sort without performance concerns.
Anyhow, this is probably my last submission on this 'sort' of subject :)
Happy coding, Rd :)
(If this comment was disrespectful, please report it.)
|
3/29/2007 2:39:16 AM: Richard Mewett
Excellent stuff! Just realised I had not voted for this... ***** (If this comment was disrespectful, please report it.)
|
3/30/2007 2:58:47 AM: Rde
Thanks Richard
Happy coding, Rd :) (If this comment was disrespectful, please report it.)
|
12/23/2008 9:10:24 AM: Light Templer
Hi RD, still on VB6? ;-) Great what you are doing here! But don't miss VB2005. Its working on a different level and brings back the 'rapid' to VB development. Sorting of generics there is just a call to myXYArray.sort() ... Kind regards - LiTe (If this comment was disrespectful, please report it.)
|
1/2/2009 9:18:46 PM: Rde
Hi LiTe
Thx for the VB2005 tip
I fear I will be stuck with VB5/6 forever :) (If this comment was disrespectful, please report it.)
|
5/7/2009 4:15:50 AM: abudsans
'Free Usage'...You're the man! (If this comment was disrespectful, please report it.)
|
5/14/2009 6:43:19 AM: Rde
Thanks abudsans
Happy coding, Rd :) (If this comment was disrespectful, please report it.)
|
|
|
|
Note:Not only will your feedback be posted, but an email will be sent to the code's author from the email account you registered on the site, so you can correspond directly.
NOTICE: The author of this article has been kind enough to share it with you. If you have a criticism, please state it politely or it will be deleted.
For feedback not related to this particular article, please click here. |
To post feedback, first please login.
|