X-Git-Url: http://git.vpit.fr/?p=perl%2Fmodules%2FScalar-Vec-Util.git;a=blobdiff_plain;f=lib%2FScalar%2FVec%2FUtil.pm;h=dd8b1cbcea3b3cdb30da08a3098a114c9701b838;hp=b5a8080e7f235a1cde6ca7693f59dd9547d92af0;hb=856caa5792565f48b11a5dc86856519b649eaffb;hpb=c36fbc2566b9aeb0642e7a1b2fb8fc843faff3e9 diff --git a/lib/Scalar/Vec/Util.pm b/lib/Scalar/Vec/Util.pm index b5a8080..dd8b1cb 100644 --- a/lib/Scalar/Vec/Util.pm +++ b/lib/Scalar/Vec/Util.pm @@ -146,6 +146,37 @@ sub vshift { } } +=head2 C<< vrot $v, $start, $length, $bits >> + +In the area starting at C<$start> and of length C<$length> in C<$v>, rotates bits C positions left if C<< $bits > 0 >> and right otherwise. +Bits outside of the specified area are left untouched. +Currently allocates an extra buffer of size C. + +=cut + +sub vrot { + my ($start, $length, $bits) = @_[1 .. 3]; + return unless $length and $bits; + my $left = 1; + if ($bits < 0) { + $left = 0; + $bits = -$bits; + } + $bits %= $length; + return unless $bits; + $length -= $bits; + my $buf = ''; + if ($left) { + vcopy($_[0], $start + $length, $buf, 0, $bits); + vcopy($_[0], $start, $_[0], $start + $bits, $length); + vcopy($buf, 0, $_[0], $start, $bits); + } else { + vcopy($_[0], $start, $buf, 0, $bits); + vcopy($_[0], $start + $bits, $_[0], $start, $length); + vcopy($buf, 0, $_[0], $start + $length, $bits); + } +} + =head2 C<< veq $v1 => $v1_start, $v2 => $v2_start, $length >> Returns true if the C<$length> bits starting at C<$v1_start> in C<$v1> and C<$v2_start> in C<$v2> are equal, and false otherwise. @@ -166,7 +197,7 @@ sub veq_pp { =head1 EXPORT -The functions L, L, L and L are only exported on request. +The functions L, L, L, L and L are only exported on request. All of them are exported by the tags C<':funcs'> and C<':all'>. The constants L and L are also only exported on request. @@ -178,7 +209,7 @@ use base qw/Exporter/; our @EXPORT = (); our %EXPORT_TAGS = ( - 'funcs' => [ qw/vfill vcopy vshift veq/ ], + 'funcs' => [ qw/vfill vcopy vshift vrot veq/ ], 'consts' => [ qw/SVU_PP SVU_SIZE/ ] ); our @EXPORT_OK = map { @$_ } values %EXPORT_TAGS;