Skip Menu |
 

This queue is for tickets about the Bit-Vector CPAN distribution.

Report information
The Basics
Id: 38997
Status: rejected
Priority: 0/
Queue: Bit-Vector

People
Owner: Nobody in particular
Requestors: kwilliams [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



Subject: New method: Interval_Norm()
Download (untitled) / with headers
text/plain 938b
It would be nice if there were an Interval_Norm() method that would compute the number of bits set within a range: $norm = $vec->Interval_Norm($from, $to); Currently it seems the available solutions are sub-optimal, requiring allocation of additional bit vectors and examining too much of $vec: $mask = $vec->Shadow; $mask->Interval_Fill($from, $to); $temp = $mask->Shadow; $temp->And( $vec, $mask ); $norm = $masked->Norm; Of course if there's a better solution I'm overlooking, I'd love to hear it. It would also be nice if there were a simple Interval() method that would just return a sub- vector: $sub = $vec->Interval($from, $to); That would make several operations on sub-vectors more convenient. I believe the current solution is to do: $sub = Bit::Vector->new($to-$from+1); $sub->Interval_Copy($vec, 0, $from, $to-$from+1); Which works fine but is a bit wordy (if you'll pardon the pun). -Ken
Download (untitled) / with headers
text/plain 2.3k
On Thu Sep 04 14:29:42 2008, KWILLIAMS wrote: Show quoted text
> It would be nice if there were an Interval_Norm() method that would > compute the number of > bits set within a range: > > $norm = $vec->Interval_Norm($from, $to); > > Currently it seems the available solutions are sub-optimal, requiring > allocation of additional > bit vectors and examining too much of $vec: > > $mask = $vec->Shadow; > $mask->Interval_Fill($from, $to); > > $temp = $mask->Shadow; > $temp->And( $vec, $mask ); > > $norm = $masked->Norm; > > Of course if there's a better solution I'm overlooking, I'd love to > hear it.
There is at least a shorter solution: $temp = $vec->Clone(); $temp->Interval_Empty(0,$from-1) unless ($from-1 < 0); $temp->Interval_Empty($to+1,$temp->Size()-1) unless ($to+1 > $temp->Size()-1); $norm = $temp->Norm(); Show quoted text
> It would also be nice if there were a simple Interval() method that > would just return a sub- > vector: > > $sub = $vec->Interval($from, $to); > > That would make several operations on sub-vectors more convenient. I > believe the current > solution is to do: > > $sub = Bit::Vector->new($to-$from+1); > $sub->Interval_Copy($vec, 0, $from, $to-$from+1); > > Which works fine but is a bit wordy (if you'll pardon the pun). > > -Ken
There is also a different solution: $sub = Bit::Vector->new($to-$from+1); # any size is ok here, but correct size should be a trifle faster $sub->Interval_Substitute($vec,0,$sub->Size(),$from,$to-$from+1); Note that "Interval_Substitute" is the same for bit vectors as what "splice" is for Perl arrays. This alternate solution is not easier to read in this example, but might be more helpful in other circumstances than the use of "Interval_Copy". And yes, Bit::Vector is somewhat "wordy" - but hey, it's a module for low-level functions in the first place! By the way, you can always write a very short little method yourself which does it (put at the top of your program): package Bit::Vector; sub Interval { my($self,$from,$to) = @_; # You should add some parameter checking here of course! my $sub = Bit::Vector->new($to-$from+1); $sub->Interval_Copy($vec, 0, $from, $to-$from+1); return $sub; } package WhateverYouLike; # Your program goes here And you're done! :-) Same goes of course for the "Interval_Norm" method you mentioned above. Hope this helps.
Subject: Re: [rt.cpan.org #38997] New method: Interval_Norm()
Date: Fri, 5 Sep 2008 07:01:38 -0500
To: bug-Bit-Vector [...] rt.cpan.org
From: "Ken Williams" <kenahoo [...] gmail.com>
Download (untitled) / with headers
text/plain 535b
On Thu, Sep 4, 2008 at 11:16 PM, Steffen_Beyer via RT <bug-Bit-Vector@rt.cpan.org> wrote: Show quoted text
> > There is at least a shorter solution: > > $temp = $vec->Clone(); > $temp->Interval_Empty(0,$from-1) unless ($from-1 < 0); > $temp->Interval_Empty($to+1,$temp->Size()-1) unless ($to+1 > > $temp->Size()-1); > $norm = $temp->Norm();
That's unpleasant if, say, $vec has length 10 million and you want to examine 3 bits somewhere in the middle. Surely it should be possible to count bits without copying anything to a new vector, right? -Ken
Download (untitled) / with headers
text/plain 940b
On Fri Sep 05 08:01:58 2008, kenahoo@gmail.com wrote: Show quoted text
> > There is at least a shorter solution: > > > > $temp = $vec->Clone(); > > $temp->Interval_Empty(0,$from-1) unless ($from-1 < 0); > > $temp->Interval_Empty($to+1,$temp->Size()-1) unless ($to+1 > > > $temp->Size()-1); > > $norm = $temp->Norm();
> > That's unpleasant if, say, $vec has length 10 million and you want to > examine 3 bits somewhere in the middle. Surely it should be possible > to count bits without copying anything to a new vector, right?
In that case copying the area of interest (similar to your earlier example) only would of course be the currently fastest solution. Eliminating the need for copying altogether would of course be better, but I'm reluctant to create a myriad of special routines for special needs, and it's also too much work (developing, testing, writing test cases, documenting, repackaging and submitting) for just one small niche feature...
Sorry, this wish is unfortunately rejected, at least for the time being.


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.