Mailing List Archive

r3666 - in trunk: c_src/KinoSearch/Util perl/lib/KinoSearch/Util perl/t
Author: creamyg
Date: 2008-07-29 15:41:50 -0700 (Tue, 29 Jul 2008)
New Revision: 3666

Modified:
trunk/c_src/KinoSearch/Util/BitVector.bp
trunk/c_src/KinoSearch/Util/BitVector.c
trunk/perl/lib/KinoSearch/Util/BitVector.pm
trunk/perl/t/013-bit_vector.t
Log:
Add BitVec_Copy().


Modified: trunk/c_src/KinoSearch/Util/BitVector.bp
===================================================================
--- trunk/c_src/KinoSearch/Util/BitVector.bp 2008-07-29 21:45:43 UTC (rev 3665)
+++ trunk/c_src/KinoSearch/Util/BitVector.bp 2008-07-29 22:41:50 UTC (rev 3666)
@@ -58,6 +58,13 @@
void
Grow(BitVector *self, u32_t capacity);

+ /** Duplicate the contents of another BitVector.
+ *
+ * @param other Another BitVector.
+ */
+ void
+ Copy(BitVector *self, BitVector *other);
+
/** Modify the BitVector so that only bits which remain set are those
* which 1) were already set in this BitVector, and 2) were also set in
* the other BitVector.

Modified: trunk/c_src/KinoSearch/Util/BitVector.c
===================================================================
--- trunk/c_src/KinoSearch/Util/BitVector.c 2008-07-29 21:45:43 UTC (rev 3665)
+++ trunk/c_src/KinoSearch/Util/BitVector.c 2008-07-29 22:41:50 UTC (rev 3666)
@@ -94,6 +94,21 @@
}

void
+BitVec_copy(BitVector *self, BitVector *other)
+{
+ const u32_t my_byte_size = (u32_t)ceil(self->cap / 8.0);
+ const u32_t other_byte_size = (u32_t)ceil(other->cap / 8.0);
+ if (my_byte_size > other_byte_size) {
+ u32_t space = my_byte_size - other_byte_size;
+ memset(self->bits + other_byte_size, 0, space);
+ }
+ else {
+ BitVec_Grow(self, other->cap);
+ }
+ memcpy(self->bits, other->bits, other_byte_size);
+}
+
+void
BitVec_grow(BitVector *self, u32_t new_max)
{
if (new_max >= self->cap) {

Modified: trunk/perl/lib/KinoSearch/Util/BitVector.pm
===================================================================
--- trunk/perl/lib/KinoSearch/Util/BitVector.pm 2008-07-29 21:45:43 UTC (rev 3665)
+++ trunk/perl/lib/KinoSearch/Util/BitVector.pm 2008-07-29 22:41:50 UTC (rev 3666)
@@ -22,7 +22,7 @@

{ "KinoSearch::Util::BitVector" => {
bind_methods => [.
- qw( get set clear clear_all grow count and or
+ qw( get set clear clear_all grow count copy and or
and_not xor flip flip_block to_array )
],
make_getters => [qw( cap count )],
@@ -31,7 +31,7 @@
synopsis => $synopsis,
constructor => { sample => $constructor },
methods => [.
- qw( get set clear clear_all grow count and or
+ qw( get set clear clear_all grow count copy and or
and_not xor flip flip_block to_array )
],
}

Modified: trunk/perl/t/013-bit_vector.t
===================================================================
--- trunk/perl/t/013-bit_vector.t 2008-07-29 21:45:43 UTC (rev 3665)
+++ trunk/perl/t/013-bit_vector.t 2008-07-29 22:41:50 UTC (rev 3666)
@@ -1,7 +1,7 @@
use strict;
use warnings;

-use Test::More tests => 342;
+use Test::More tests => 666;
use List::Util qw( shuffle );

use KinoSearch::Util::BitVector;
@@ -59,6 +59,17 @@
}
}

+for my $foo ( 0 .. 17 ) {
+ for my $bar ( 0 .. 17 ) {
+ my $foo_vec = KinoSearch::Util::BitVector->new;
+ my $bar_vec = KinoSearch::Util::BitVector->new;
+ $foo_vec->set($foo);
+ $bar_vec->set($bar);
+ $foo_vec->copy($bar_vec);
+ is_deeply( $foo_vec->to_arrayref, [$bar], "copy foo=$foo bar=$bar" );
+ }
+}
+
my @set_1 = ( 1 .. 3, 10, 20, 30 );
my @set_2 = ( 2 .. 10, 25 .. 35 );



_______________________________________________
kinosearch-commits mailing list
kinosearch-commits@rectangular.com
http://www.rectangular.com/mailman/listinfo/kinosearch-commits