| 1 | package Math::Vector::SortIndexes; | ||
| 2 | |||
| 3 | 1 | $VERSION = 0.02; | |
| 4 | 1 | @EXPORT_OK = qw(sort_indexes_descending sort_indexes_ascending); | |
| 5 | 1 | ▶ | use base 'Exporter'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | |||
| 7 | 1 | ▶ | sub sort_indexes_descending { |
|
Subroutine
sort_indexes_descending: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 8 | 1 | (sort { $_[$b] <=> $_[$a] } 0..$#_); | |
| 9 | } | ||
| 10 | |||
| 11 | 1 | ▶ | sub sort_indexes_ascending { |
|
Subroutine
sort_indexes_ascending: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 12 | 1 | (sort { $_[$a] <=> $_[$b] } 0..$#_); | |
| 13 | } | ||
| 14 | |||
| 15 | =head1 NAME | ||
| 16 | |||
| 17 | Math::Vector::SortIndexes - Sort the indices of a numeric vector | ||
| 18 | |||
| 19 | =head1 SYNOPSIS | ||
| 20 | |||
| 21 | use Math::Vector::SortIndexes qw(sort_indexes_descending | ||
| 22 | sort_indexes_ascending); | ||
| 23 | |||
| 24 | @vector = qw(44 22 33 11); | ||
| 25 | @indexes1 = sort_indexes_ascending @vector; | ||
| 26 | @indexes2 = sort_indexes_descending @vector; | ||
| 27 | |||
| 28 | print "@indexes1\n"; # Prints 3 1 2 0 | ||
| 29 | print "@indexes2\n"; # Prints 0 2 1 3 | ||
| 30 | |||
| 31 | =head1 DESCRIPTION | ||
| 32 | |||
| 33 | This module allows you to find the sort the indices of a numeric vector. | ||
| 34 | The subroutine names explain themselves: sort_indexes_ascending and | ||
| 35 | sort_indexes_descending. Import them and use them as you see fit. | ||
| 36 | |||
| 37 | =head1 AUTHORS | ||
| 38 | |||
| 39 | David James <david@jamesgang.com> | ||
| 40 | |||
| 41 | =head1 SEE ALSO | ||
| 42 | |||
| 43 | L<Math::VecStat> | ||
| 44 | |||
| 45 | =head1 LICENSE | ||
| 46 | |||
| 47 | Copyright (c) 2002 David James | ||
| 48 | All rights reserved. | ||
| 49 | This program is free software; you can redistribute it and/or | ||
| 50 | modify it under the same terms as Perl itself. | ||
| 51 | |||
| 52 | =cut | ||