@@ -24,7 +24,7 @@ Moose::Exporter->setup_import_methods(
24
24
as_is => [\&nwsrt_algorithms, \&nwsrt_title, \&nwsrt],
25
25
);
26
26
27
- our $VERSION = ' 2.01 ' ;
27
+ our $VERSION = ' 2.02 ' ;
28
28
29
29
#
30
30
# Our one use of overload, because default
@@ -162,33 +162,34 @@ Algorithm::Networksort - Create Sorting Networks.
162
162
=begin html
163
163
164
164
<svg xmlns =" http://www.w3.org/2000/svg"
165
- xmlns:xlink =" http://www.w3.org/1999/xlink" width =" 157 " height =" 120 " viewbox =" 0 0 157 120 " >
165
+ xmlns:xlink =" http://www.w3.org/1999/xlink" width =" 90 " height =" 84 " viewbox =" 0 0 90 84 " >
166
166
<title >Bose-Nelson Sort for N = 4</title >
167
167
<defs >
168
- <g id =" I_5649 " style =" stroke-width :2 ; fill :#000 ; stroke :#000 " >
169
- <line x1 =" 18 " y1 =" 0" x2 =" 139 " y2 =" 0" />
168
+ <g id =" I_1c13 " style =" stroke-width :2 ; fill :#000 ; stroke :#000 " >
169
+ <line x1 =" 12 " y1 =" 0" x2 =" 78 " y2 =" 0" />
170
170
</g >
171
- <g id =" C1_5649" style =" stroke-width :3 ;fill :#000 ; stroke :#000 " >
172
- <line x1 =" 0" y1 =" 0" x2 =" 0" y2 =" 26" />
173
- <circle cx =" 0" cy =" 0" r =" 3" /> <circle cx =" 0" cy =" 26" r =" 3" />
171
+
172
+ <g id =" C1_1c13" style =" stroke-width :2 ;fill :#000 ; stroke :#000 " >
173
+ <line x1 =" 0" y1 =" 0" x2 =" 0" y2 =" 14" />
174
+ <circle cx =" 0" cy =" 0" r =" 2" /> <circle cx =" 0" cy =" 14" r =" 2" />
174
175
</g >
175
- <g id =" C2_5649 " style =" stroke-width :3 ;fill :#000 ; stroke :#000 " >
176
- <line x1 =" 0" y1 =" 0" x2 =" 0" y2 =" 52 " />
177
- <circle cx =" 0" cy =" 0" r =" 3 " /> <circle cx =" 0" cy =" 52 " r =" 3 " />
176
+ <g id =" C2_1c13 " style =" stroke-width :2 ;fill :#000 ; stroke :#000 " >
177
+ <line x1 =" 0" y1 =" 0" x2 =" 0" y2 =" 28 " />
178
+ <circle cx =" 0" cy =" 0" r =" 2 " /> <circle cx =" 0" cy =" 28 " r =" 2 " />
178
179
</g >
179
180
</defs >
180
181
181
- <g id =" bosenelson04_5649" >
182
- <rect width =" 100%" height =" 100%" style =" fill :#eee " />
183
- <use xlink:href =" #I_5649" y =" 21" /> <use xlink:href =" #I_5649" y =" 47" />
184
- <use xlink:href =" #I_5649" y =" 73" /> <use xlink:href =" #I_5649" y =" 99" />
182
+ <g id =" bosenelson04_1c13" >
183
+ <use xlink:href =" #I_1c13" y =" 21" /> <use xlink:href =" #I_1c13" y =" 35" />
184
+ <use xlink:href =" #I_1c13" y =" 49" /> <use xlink:href =" #I_1c13" y =" 63" />
185
185
186
- <use xlink:href =" #C1_5649 " x =" 38 " y =" 21" /> <use xlink:href =" #C1_5649 " x =" 38 " y =" 73 " />
187
- <use xlink:href =" #C2_5649 " x =" 65 " y =" 21" /> <use xlink:href =" #C2_5649 " x =" 92 " y =" 47 " />
188
- <use xlink:href =" #C1_5649 " x =" 119 " y =" 47 " />
186
+ <use xlink:href =" #C1_1c13 " x =" 24 " y =" 21" /> <use xlink:href =" #C1_1c13 " x =" 24 " y =" 49 " />
187
+ <use xlink:href =" #C2_1c13 " x =" 38 " y =" 21" /> <use xlink:href =" #C2_1c13 " x =" 52 " y =" 35 " />
188
+ <use xlink:href =" #C1_1c13 " x =" 66 " y =" 35 " />
189
189
</g >
190
190
</svg >
191
191
192
+
192
193
<p >Bose-Nelson sorting network, inputs = 4, drawn as a Knuth diagram.</p >
193
194
194
195
<!--
@@ -222,14 +223,14 @@ Algorithm::Networksort - Create Sorting Networks.
222
223
$nw->graph_text(), "\n";
223
224
224
225
#
225
- # Change the sizes and add a background color.
226
226
# Create an SVG image of the Knuth diagram.
227
+ # Set the diagram sizes.
227
228
#
228
- $nw->graphsettings(vt_margin => 21, hz_margin => 18, indent => 20 ,
229
- vt_sep => 24 , hz_sep=>24 ,
230
- compradius => 3, compline => 3, inputradius => 0);
231
-
232
- $nw->colorsettings(background => "#eee" );
229
+ $nw->graphsettings(indent => 12 ,
230
+ hz_margin => 12 , hz_sep=>12 ,
231
+ vt_margin => 21, vt_sep => 12,
232
+ compradius => 2, compline => 2,
233
+ inputradius => 0, inputline => 2 );
233
234
234
235
print $nw->graph_svg();
235
236
@@ -561,9 +562,7 @@ sub hibbard
561
562
# $t = ceiling(log2($inputs - 1)); but we'll
562
563
# find it using the length of the bitstring.
563
564
#
564
- my $t = unpack (" B32" , pack (" N" , $inputs - 1));
565
- $t =~ s / ^0+// ;
566
- $t = length $t ;
565
+ my $t = length sprintf (" %b " , $inputs - 1);
567
566
568
567
my $lastbit = 1 << $t ;
569
568
@@ -775,9 +774,7 @@ sub batcher
775
774
# $t = ceiling(log2($inputs)); but we'll
776
775
# find it using the length of the bitstring.
777
776
#
778
- my $t = unpack (" B32" , pack (" N" , $inputs ));
779
- $t =~ s / ^0+// ;
780
- $t = length $t ;
777
+ my $t = length sprintf (" %b " , $inputs );
781
778
782
779
my $p = 1 << ($t -1);
783
780
@@ -841,9 +838,7 @@ sub bitonic
841
838
# $t = ceiling(log2($n - 1)); but we'll
842
839
# find it using the length of the bitstring.
843
840
#
844
- my $t = unpack (" B32" , pack (" N" , $n - 1));
845
- $t =~ s / ^0+// ;
846
- $t = length $t ;
841
+ my $t = length sprintf (" %b " , $n - 1);
847
842
848
843
my $m = 1 << ($t - 1);
849
844
@@ -951,9 +946,7 @@ sub balanced
951
946
# $t = ceiling(log2($inputs - 1)); but we'll
952
947
# find it using the length of the bitstring.
953
948
#
954
- my $t = unpack (" B32" , pack (" N" , $inputs - 1));
955
- $t =~ s / ^0+// ;
956
- $t = length $t ;
949
+ my $t = length sprintf (" %b " , $inputs - 1);
957
950
958
951
for (1 .. $t )
959
952
{
@@ -991,9 +984,7 @@ sub oddevenmerge
991
984
# $t = ceiling(log2($inputs - 1)); but we'll
992
985
# find it using the length of the bitstring.
993
986
#
994
- my $t = unpack (" B32" , pack (" N" , $inputs - 1));
995
- $t =~ s / ^0+// ;
996
- $t = length $t ;
987
+ my $t = length sprintf (" %b " , $inputs - 1);
997
988
998
989
my ($add_elem , $sort , $merge );
999
990
0 commit comments