NAME
Sort Overview - An overview of the PTools::SDF::Sort:* modules
VERSION
This document is not specific to any version of the PTools-SDF modules.
DESCRIPTION
This document is a brief overview of each of the sort classes. Note that these will only sort PTools::SDF::SDF objects (and classes that inherit from this). The data format used is a flat ascii file consting of records containing fields delimited by an arbitrary character (usually a colon ':' character).
The classes described below implement various sorting algorithms, and which sort class will be used is entirely up to the user of these modules.
The sort utilities are a set of PTOols-SDF modules that exist outside of this class hierarchy. These are intentionally not defined within the PTools::SDF::* modules for several reasons:
they provide functionality that is not always needed
they may be used by different "types" of PTools::SDF::* classes (we are only discussing "SDF::SDF type" objects here)
they are implemented as 'user extendible' as explained next; a programmer has the ability to choose which module to use at run time, and can alter the selection at any time
SORT UTILITIES
Select Which Sort via User Extendible Method
The sort method defined in the PTools::SDF::SDF base class is 'user extendible.' This means that the programmer using these modules decides which module (class) will be used to perform the sort.
The current list of sort utility modules includes the following. The syntax used to 'extend' an object method, which is to say 'select the class' that will implement the method, is shown here.
$sdfObj->extend( "sort", "SDF::Sort::Bubble"); # slow/flexible
$sdfObj->extend( "sort", "SDF::Sort::Shell" ); # medium/medium
$sdfObj->extend( "sort", "SDF::Sort::Quick" ); # fast/inflexible
$sdfObj->extend( "sort", "SDF::Sort::Random"); # fast ramdomizer
Note: Based on which class is specified, the calling parameters may vary. See notes here and in the man page for each module.
$sdfObj->sort( $mode, @sortFieldNames ); # Bubble (multiple keys)
$sdfObj->sort( $mode, $sortFieldName ); # Shell (only one key)
$sdfObj->sort( undef, $sortFieldName ); # Quick (no mode/one key)
$sdfObj->sort( undef, undef ); # Random (no args needed)
The $mode parameter, when allowed, can be any of the following.
$mode = "reverse"
$mode = "ignorecase"
$mode = "reverse:ignorecase"
Currently only PTools::SDF::SDF type objects can be sorted (this includes any object that inherits from the PTools::SDF::SDF base class, including PTools::SDF::CSV, PTools::SDF::DIR and PTools::SDF::IDX, among others. Three sort modules are provided with the basic PTools-SDF package. The tradeoffs in deciding which one to use include functionality vs. speed.
PTools::SDF::Sort::Bubble
This is the default sorting module used when invoking the 'sort' method on any 'PTools::SDF::SDF type' object. This provides the greatest flexibility and the slowest speed. The sort can specify multiple sort fields, case insensitivity and 'forward' or 'reverse' sorting. However, as the number of records exceeds about 100 the speed becomes increasingly slower. Sorting over about 1,000 records may be too slow for a given application to be considered useful.
See PTools::SDF::Sort::Bubble.
PTools::SDF::Sort::Shell
This is a faster alternative to the Bubble Sort algorithm, but only one sort key may be used. 'Reverse' and 'case insensitive' sorting may still be specified.
PTools::SDF::Sort::Quick
This is one of the fastest sorters included with these tools. However, only one sort key may be specified. No other options are currently available with this sorter. However, a sort of over 10,000 records may cause little or no noticable delay.
PTools::SDF::Sort::Random
This by far the fastest sort mechanism. With this sorter, no keys or options are necessary. When using this class a sort of around 100,000 records will cause only a brief delay.
See PTools::SDF::Sort::Random.
Custom Utility Extensions
As mentioned above, any programmer may design their own sort and/or lock modules to be used with the 'PTools::SDF::*' classes. There is not yet much documentation for the criteria necessary to accomplish this. However, comments exist in the following classes that explain it: PTools::SDF::File, PTools::SDF::SDF, and each of the sort and lock modules.
Also, there is a PerlTools (PTools) utility module named PTools::Extender that abstracts this functionality for general use when developing Perl modules outside of the PTools::SDF:: suite of classes.
SEE ALSO
See PTools::SDF::ARRAY, PTools::SDF::CMD::BDF PTools::SDF::CSV, PTools::SDF::DB, PTools::SDF::DIR, PTools::SDF::DSET, PTools::SDF::File, PTools::SDF::IDX, PTools::SDF::INI, PTools::SDF::Lock::Advisory, PTools::SDF::Lock::Selective, PTools::SDF::SDF, PTools::SDF::Sort::Bubble, PTools::SDF::Sort::Quick, PTools::SDF::Sort::Random, PTools::SDF::Sort::Shell, and PTools::SDF::TAG.
Also see PTools::Extender for examples of designing methods that are 'user extendible' at run time.
AUTHOR
Chris Cobb, <chris@ccobb.net>
COPYRIGHT
Copyright (c) 1997-2005 by Chris Cobb. All rights reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.