Chris Cobb > PTools-SDF-0.01 > SDF::Sort::Bubble

Download:
PTools-SDF-0.01.tar.gz

Annotate this POD

CPAN RT

Open  0
Report a bug
Source  

NAME ^

SDF::Sort::Bubble - Sort an PTools::SDF::SDF object on specified key field(s)

VERSION ^

This document describes version 0.08, 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::Bubble" );

     $sdfObj->sort( $mode, @keyFields );

     ($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 be used to sort the data, unless one of the other sort classes is specified via the extend method in PTools::SDF::SDF.

The tradeoff is flexibility vs performance. This is by far the slowest sort algorithm but is also the most flexible. Even so, 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 ], KeyFields )

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 KeyFields 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 one of the following strings, used to control the behavior of the Bubble Sort algorithm used by this class.

 rev     reverse      - to sort in reverse order
 ignore  ignorecase   - ignore case sensitivity during the sort

Any combination of the above may be used

 rev:ignorecase

Using reverse sorting with multiple KeyFields should be 'experimented with' to ensure the desired results are obtained.

KeyFields

One or more KeyFields may be specified when using this sort class. Keys are specified using the same field names as are used within the PTools::SDF::SDF object.

Keys can be passed either in a simple array or as a colon separated list.

At least one key field must be passed or an exception is generated.

Example:

     use PTools::SDF::IDX;

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

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

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

     $stat and die $err;

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 ], KeyFields )

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. See PTools::SDF::Sort::Quick, 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>

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.