NAME

SDF::Sort::Quick - Sort an PTools::SDF::SDF object on a specified key field

VERSION

This document describes version 0.07, released March, 2005.

SYNOPSIS

use PTools::SDF::SDF;       # or any subclass thereof, including:
use PTools::SDF::ARRAY;
use PTools::SDF::IDX;
use PTools::SDF::DIR;
use PTools::SDF::DSET;

$sdfObj = new PTools::SDF::SDF( $fileName );

$sdfObj->extend( "sort", "PTools::SDF::Sort::Quick" );

$sdfObj->sort( $mode, $keyField );

($stat,$err) = $sdfObj->status;

$stat and die $err;

DESCRIPTION

This sort class is one of several extended classes used to select which algorithm is employed to sort data in the calling object. It is up to the client script to select the specific algorithm, as shown in the Synopsis section, above.

By default this class will not be used to sort the data. This sort sort classe must specified via the extend method in PTools::SDF::SDF.

The tradeoff is flexibility vs performance. This by far the 'highest speed' sort algorithm; however, it is 'not very flexible.' For files containing no more than 100 records, all of the sort modules are roughly equivalent in speed.

Constructor

new

Note that this is not intended to be a public method. It is only invoked by objects of the PTools::SDF::SDF class, or any subclasses thereof. Objects of this class are not intended for direct access, but only indirectly through the containing object.

Public Methods

The interface of this sort method is documented here. This is the intended usage for clients of the PTools::SDF::* class of objects.

The actual calling syntax for module designers is shown in the following section, below.

sort ( [ Mode ], KeyField )

As shown in the Synopsis section, above, objects of this class are not accessed directly. Make a call to this method through the containing object where the unsorted data resides.

This class will attempt to determine whether numeric or character sorting should occur for each of the KeyField passed, based on the values in the first two records in the object containing data.

At least two records must exist in the containing PTools::SDF::SDF object or an exception is generated.

Mode

The Mode parameter is not used by this class. It is included in the interface definition to keep the various sort modules as polymorphic as possible.

KeyField

Only a single KeyField may be specified when using this sort class. The key is specified using the same field names as are used within the PTools::SDF::SDF object.

If no key field is passed, an exception is generated.

Example:

use PTools::SDF::IDX;

$idxObj = new PTools::SDF::IDX( "/etc/passwd" );

$sdfObj->extend( "sort", "PTools::SDF::Sort::Quick" );

$sdfObj->sort( undef, "uname" );

($stat,$err) = $sdfObj->status;

$stat and die $err;

For this example, the extend method must be called prior to invoking the sort method. Otherwise the default PTools::SDF::Sort::Bubble class is used.

Of course, this just an example. It would be appropriate to use the PTools::SDF::File::Passwd class instead as this provides additional methods for manipulating password file data.

Private Methods

The actual calling syntax for module designers is documented here. This is the syntax used when invoking this method from withn the extended sort method of the PTools::SDF::SDF class only.

The user interface of this sort method is shown in the preceeding section.

sort ( SdfRef [, Mode ], KeyField )

The SdfRef is a reference to the actual PTools::SDF::SDF object, or subclass. This is passed as the first parameter to give this object access to the data to be sorted.

The other parameters are the same as explained above.

INHERITANCE

None currently.

SEE ALSO

Other extended sort classes are available. PTools::SDF::Sort::Bubble, PTools::SDF::Sort::Random and PTools::SDF::Sort::Shell.

Also see PTools::SDF::Overview, PTools::SDF::ARRAY, PTools::SDF::CSV, PTools::SDF::DB, PTools::SDF::DIR, PTools::SDF::DSET, PTools::SDF::File, PTools::SDF::IDX, PTools::SDF::INI, PTools::SDF::SDF, PTools::SDF::TAG and PTools::SDF::Lock::Advisory.

AUTHOR

Chris Cobb, <nospamplease@ccobb.net>

Adapted from A quick sort demonstration algorithm SortAlgorithm.java (version QSortAlgorithm.java 1.3, 29 Feb 1996) by James Gosling and Kevin A. Smith.

COPYRIGHT

Copyright (c) 1997-2007 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.