Mailing List Archive

r3695 - in trunk: c_src/KinoSearch/Util perl/lib/KinoSearch/Util perl/t
Author: creamyg
Date: 2008-08-02 21:42:13 -0700 (Sat, 02 Aug 2008)
New Revision: 3695

Modified:
trunk/c_src/KinoSearch/Util/VArray.bp
trunk/c_src/KinoSearch/Util/VArray.c
trunk/perl/lib/KinoSearch/Util/VArray.pm
trunk/perl/t/016-varray.t
Log:
Add VA_Resize().


Modified: trunk/c_src/KinoSearch/Util/VArray.bp
===================================================================
--- trunk/c_src/KinoSearch/Util/VArray.bp 2008-08-02 22:00:15 UTC (rev 3694)
+++ trunk/c_src/KinoSearch/Util/VArray.bp 2008-08-03 04:42:13 UTC (rev 3695)
@@ -92,6 +92,13 @@
void
Sort(VArray *self, Obj_compare_t compare);

+ /** Set the size for the VArray. If the new size is larger than the
+ * current size, grow the object to accommodate NULL elements; if smaller
+ * than the current size, discard any existing elements.
+ */
+ void
+ Resize(VArray *self, u32_t size);
+
public void
Serialize(VArray *self, OutStream *outstream);


Modified: trunk/c_src/KinoSearch/Util/VArray.c
===================================================================
--- trunk/c_src/KinoSearch/Util/VArray.c 2008-08-02 22:00:15 UTC (rev 3694)
+++ trunk/c_src/KinoSearch/Util/VArray.c 2008-08-03 04:42:13 UTC (rev 3695)
@@ -262,6 +262,18 @@
}

void
+VA_resize(VArray *self, u32_t size)
+{
+ if (size < self->size) {
+ VA_Splice(self, size, self->size - size);
+ }
+ else if (size > self->size) {
+ VA_Grow(self, size);
+ }
+ self->size = size;
+}
+
+void
VA_sort(VArray *self, Obj_compare_t compare)
{
qsort(self->elems, self->size, sizeof(void*), compare);

Modified: trunk/perl/lib/KinoSearch/Util/VArray.pm
===================================================================
--- trunk/perl/lib/KinoSearch/Util/VArray.pm 2008-08-02 22:00:15 UTC (rev 3694)
+++ trunk/perl/lib/KinoSearch/Util/VArray.pm 2008-08-03 04:42:13 UTC (rev 3695)
@@ -28,6 +28,7 @@
delete
splice
fetch
+ resize
shallow_copy )
],
make_getters => [qw( size )],

Modified: trunk/perl/t/016-varray.t
===================================================================
--- trunk/perl/t/016-varray.t 2008-08-02 22:00:15 UTC (rev 3694)
+++ trunk/perl/t/016-varray.t 2008-08-03 04:42:13 UTC (rev 3695)
@@ -1,7 +1,7 @@
use strict;
use warnings;

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

use KinoSearch::Util::VArray;
@@ -77,3 +77,10 @@
$evil_twin = $varray->clone;
is_deeply( $evil_twin->to_perl, $varray->to_perl, "clone" );

+$varray = KinoSearch::Util::VArray->new( capacity => 3 );
+$varray->push( KinoSearch::Util::CharBuf->new($_) ) for 1 .. 3;
+$varray->resize(4);
+is_deeply( $varray->to_perl, [ 1, 2, 3, undef ], "resize up" );
+$varray->resize(2);
+is_deeply( $varray->to_perl, [ 1, 2 ], "resize down" );
+


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