| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Acme::Rautavistic::Sort; |
|
2
|
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
45258
|
use warnings; |
|
|
2
|
|
|
|
|
6
|
|
|
|
2
|
|
|
|
|
72
|
|
|
4
|
2
|
|
|
2
|
|
13
|
use strict; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
77
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
12
|
use Scalar::Util 'reftype'; |
|
|
2
|
|
|
|
|
8
|
|
|
|
2
|
|
|
|
|
252
|
|
|
7
|
|
|
|
|
|
|
require Exporter; |
|
8
|
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
11
|
use vars qw(@ISA @EXPORT_OK %EXPORT_TAGS); |
|
|
2
|
|
|
|
|
10
|
|
|
|
2
|
|
|
|
|
844
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
@EXPORT_OK = qw(dropsort); |
|
14
|
|
|
|
|
|
|
%EXPORT_TAGS = (all => [qw(dropsort)]); |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# choose the best one |
|
17
|
|
|
|
|
|
|
# *{dropsort} = *{dropsort5}; |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub dropsort { |
|
20
|
2
|
|
|
2
|
|
13
|
no warnings; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
263
|
|
|
21
|
27
|
|
|
27
|
1
|
2603
|
my $last; |
|
22
|
27
|
100
|
|
|
|
54
|
map { $_ ge $last ? $last = $_ : () } @_; |
|
|
105
|
|
|
|
|
376
|
|
|
23
|
|
|
|
|
|
|
} |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# TODOs / Ideas: |
|
26
|
|
|
|
|
|
|
# Attribute : Rautavistic(dropsort) |
|
27
|
|
|
|
|
|
|
# an Arrays, behält immer dropsort-Sortierung bei, nach jeder Änderung am Array |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=head1 NAME |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
Acme::Rautavistic::Sort - Rautavistic sort functions |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head1 VERSION |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
Version 0.01 |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=cut |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
use Acme::Rautavistic::Sort ':all'; |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# default alphanumeric comparison |
|
47
|
|
|
|
|
|
|
@res = dropsort(qw(3 2 3 1 5)); # qw(3 3 5) |
|
48
|
|
|
|
|
|
|
@res = dropsort(qw(cc bb dd aa ee)); # qw(cc dd ee) |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
# numeric comparison |
|
51
|
|
|
|
|
|
|
@res = dropsort sub { $_[0] <=> $_[1] }, 1, 11, 2; |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
This module provides rautavistic sort functions. For more description |
|
57
|
|
|
|
|
|
|
of the functions see below. |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head2 dropsort |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
From http://www.dangermouse.net/esoteric/dropsort.html: |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
Dropsort is a fast, one-pass sorting algorithm suitable for many |
|
64
|
|
|
|
|
|
|
applications. |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
Algorithm Description Dropsort is run on an ordered list of numbers by |
|
67
|
|
|
|
|
|
|
examining the numbers in sequence, beginning with the second number in |
|
68
|
|
|
|
|
|
|
the list. If the number being examined is less than the number before |
|
69
|
|
|
|
|
|
|
it, drop it from the list. Otherwise, it is in sorted order, so keep |
|
70
|
|
|
|
|
|
|
it. Then move to the next number. |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
After a single pass of this algorithm, the list will only contain |
|
73
|
|
|
|
|
|
|
numbers that are at least as large as the previous number in the |
|
74
|
|
|
|
|
|
|
list. In other words, the list will be sorted! Analysis Dropsort |
|
75
|
|
|
|
|
|
|
requires exactly n-1 comparisons to sort a list of length n, making |
|
76
|
|
|
|
|
|
|
this an O(n) algorithm, superior to the typical O(n logn) algorithms |
|
77
|
|
|
|
|
|
|
commonly used in most applications. |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
Dropsort is what is known in the computer science field as a lossy |
|
80
|
|
|
|
|
|
|
algorithm. It produces a fast result that is correct, but at the cost |
|
81
|
|
|
|
|
|
|
of potentially losing some of the input data. Although to those not |
|
82
|
|
|
|
|
|
|
versed in the arts of computer science this may seem undesirable, |
|
83
|
|
|
|
|
|
|
lossy algorithms are actually a well-accepted part of computing. An |
|
84
|
|
|
|
|
|
|
example is the popular JPEG image compression format, which enjoys |
|
85
|
|
|
|
|
|
|
widespread use because of its versatility and usefulness. In similar |
|
86
|
|
|
|
|
|
|
fashion, dropsort promises to revolutionise the sorting of data in |
|
87
|
|
|
|
|
|
|
fields as diverse as commercial finance, government record-keeping, |
|
88
|
|
|
|
|
|
|
and space exploration. |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 EXPORT |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
dropsort |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 FUNCTIONS |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head2 dropsort |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
@SORTED = dropsort @VALUES; |
|
99
|
|
|
|
|
|
|
@SORTED = dropsort sub { $_[0] <=> $_[1]}, @VALUES; |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
Does drop sort. |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
If the first argument is a sub reference, use that to do the |
|
104
|
|
|
|
|
|
|
comparison of two values. |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
Please note, that due to the nature of the algorithm, just reversing |
|
107
|
|
|
|
|
|
|
$_[0] and $_[1] does not reverse the order of the result. You can only |
|
108
|
|
|
|
|
|
|
use it to modify the comparator, eg. to use number comparison instead |
|
109
|
|
|
|
|
|
|
of the default string comparator. |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
Use |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
@SORTED = reverse dropsort @VALUES; |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
to reverse the result. |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head1 AUTHOR |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
Steffen Schwigon, C<< >> |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
Felix Antonius Wilhelm Ostmann (benchmark, optimization and stunt |
|
122
|
|
|
|
|
|
|
coordinator) |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head1 BUGS |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
dropsort currently only sorts by string comparison. This will |
|
127
|
|
|
|
|
|
|
hopefully be fixed by being able to argument it with a comparison |
|
128
|
|
|
|
|
|
|
function, similar to Perl's sort. |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
Please report any bugs or feature requests to |
|
132
|
|
|
|
|
|
|
C, or through the web |
|
133
|
|
|
|
|
|
|
interface at |
|
134
|
|
|
|
|
|
|
L. |
|
135
|
|
|
|
|
|
|
I will be notified, and then you'll automatically be notified of |
|
136
|
|
|
|
|
|
|
progress on your bug as I make changes. |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=head1 SUPPORT |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
perldoc Acme::Rautavistic::Sort |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
You can also look for information at: |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=over 4 |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
L |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=item * CPAN Ratings |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
L |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
L |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=item * Search CPAN |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
L |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=back |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
For more information about rautavistic sort and rautavistic in general |
|
169
|
|
|
|
|
|
|
see |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=over 4 |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=item * http://www.dangermouse.net/esoteric/dropsort.html |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=item * http://www.rautavistik.de (in german) |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=back |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
Copyright 2008 Steffen Schwigon, all rights reserved. |
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify |
|
184
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=cut |
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
1; |
|
189
|
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
# End of Acme::Rautavistic::Sort |