Mailing List Archive

r3744 - in trunk: c_src/KinoSearch/Index c_src/KinoSearch/Search c_src/KinoSearch/Util perl/lib/KinoSearch/Util
Author: creamyg
Date: 2008-08-22 16:39:36 -0700 (Fri, 22 Aug 2008)
New Revision: 3744

Modified:
trunk/c_src/KinoSearch/Index/DelDocs.c
trunk/c_src/KinoSearch/Index/DocVector.c
trunk/c_src/KinoSearch/Index/MultiLexicon.c
trunk/c_src/KinoSearch/Index/MultiReader.c
trunk/c_src/KinoSearch/Index/SegLexicon.c
trunk/c_src/KinoSearch/Index/SegReader.c
trunk/c_src/KinoSearch/Index/TermVector.c
trunk/c_src/KinoSearch/Search/MultiSearcher.c
trunk/c_src/KinoSearch/Util/BitVector.c
trunk/c_src/KinoSearch/Util/IntMap.bp
trunk/c_src/KinoSearch/Util/IntMap.c
trunk/perl/lib/KinoSearch/Util/IntMap.pm
Log:
Give IntMap a new constructor indicating that it will take possession of the
supplied array, IntMap_new_steal(). Update XS binding to reflect new behavior
of IntMap_Get().


Modified: trunk/c_src/KinoSearch/Index/DelDocs.c
===================================================================
--- trunk/c_src/KinoSearch/Index/DelDocs.c 2008-08-22 23:14:17 UTC (rev 3743)
+++ trunk/c_src/KinoSearch/Index/DelDocs.c 2008-08-22 23:39:36 UTC (rev 3744)
@@ -133,7 +133,7 @@
doc_map[i] = offset + new_doc_num++;
}

- return IntMap_new(doc_map, max + 1);
+ return IntMap_new_steal(doc_map, max + 1);
}

void

Modified: trunk/c_src/KinoSearch/Index/DocVector.c
===================================================================
--- trunk/c_src/KinoSearch/Index/DocVector.c 2008-08-22 23:14:17 UTC (rev 3743)
+++ trunk/c_src/KinoSearch/Index/DocVector.c 2008-08-22 23:39:36 UTC (rev 3744)
@@ -184,9 +184,9 @@
CONFESS("Bad encoding of posdata");
}
else {
- IntMap *posits_map = IntMap_new(positions, num_pos);
- IntMap *starts_map = IntMap_new(starts, num_pos);
- IntMap *ends_map = IntMap_new(ends, num_pos);
+ IntMap *posits_map = IntMap_new_steal(positions, num_pos);
+ IntMap *starts_map = IntMap_new_steal(starts, num_pos);
+ IntMap *ends_map = IntMap_new_steal(ends, num_pos);
retval = TV_new(field, term_text, posits_map, starts_map, ends_map);
REFCOUNT_DEC(posits_map);
REFCOUNT_DEC(starts_map);

Modified: trunk/c_src/KinoSearch/Index/MultiLexicon.c
===================================================================
--- trunk/c_src/KinoSearch/Index/MultiLexicon.c 2008-08-22 23:14:17 UTC (rev 3743)
+++ trunk/c_src/KinoSearch/Index/MultiLexicon.c 2008-08-22 23:39:36 UTC (rev 3744)
@@ -211,7 +211,7 @@
REFCOUNT_DEC(term_texts);
REFCOUNT_DEC(last_term_text);

- return IntMap_new(ints, max_docs + 1);
+ return IntMap_new_steal(ints, max_docs + 1);
}

void

Modified: trunk/c_src/KinoSearch/Index/MultiReader.c
===================================================================
--- trunk/c_src/KinoSearch/Index/MultiReader.c 2008-08-22 23:14:17 UTC (rev 3743)
+++ trunk/c_src/KinoSearch/Index/MultiReader.c 2008-08-22 23:39:36 UTC (rev 3744)
@@ -42,7 +42,7 @@
starts[i] = self->max_docs;
self->max_docs += SegReader_Max_Docs(seg_reader);
}
- self->starts = IntMap_new(starts, sub_readers->size);
+ self->starts = IntMap_new_steal(starts, sub_readers->size);
return self;
}


Modified: trunk/c_src/KinoSearch/Index/SegLexicon.c
===================================================================
--- trunk/c_src/KinoSearch/Index/SegLexicon.c 2008-08-22 23:14:17 UTC (rev 3743)
+++ trunk/c_src/KinoSearch/Index/SegLexicon.c 2008-08-22 23:39:36 UTC (rev 3744)
@@ -238,7 +238,7 @@
term_num++;
}

- return IntMap_new(ints, max_docs + 1);
+ return IntMap_new_steal(ints, max_docs + 1);
}

void

Modified: trunk/c_src/KinoSearch/Index/SegReader.c
===================================================================
--- trunk/c_src/KinoSearch/Index/SegReader.c 2008-08-22 23:14:17 UTC (rev 3743)
+++ trunk/c_src/KinoSearch/Index/SegReader.c 2008-08-22 23:39:36 UTC (rev 3744)
@@ -147,9 +147,9 @@
IntMap*
SegReader_seg_starts(SegReader *self)
{
- i32_t *ints = CALLOCATE(1, i32_t);
+ i32_t start = 0;
UNUSED_VAR(self);
- return IntMap_new(ints, 1);
+ return IntMap_new(&start, 1);
}

VArray*

Modified: trunk/c_src/KinoSearch/Index/TermVector.c
===================================================================
--- trunk/c_src/KinoSearch/Index/TermVector.c 2008-08-22 23:14:17 UTC (rev 3743)
+++ trunk/c_src/KinoSearch/Index/TermVector.c 2008-08-22 23:39:36 UTC (rev 3744)
@@ -80,9 +80,9 @@
starts[i] = InStream_Read_C32(instream);
ends[i] = InStream_Read_C32(instream);
}
- positions = IntMap_new(posits, num_pos);
- start_offsets = IntMap_new(starts, num_pos);
- end_offsets = IntMap_new(ends, num_pos);
+ positions = IntMap_new_steal(posits, num_pos);
+ start_offsets = IntMap_new_steal(starts, num_pos);
+ end_offsets = IntMap_new_steal(ends, num_pos);

self = self ? self : (TermVector*)CREATE(NULL, TERMVECTOR);
self = TV_init(self, field, text, positions, start_offsets, end_offsets);

Modified: trunk/c_src/KinoSearch/Search/MultiSearcher.c
===================================================================
--- trunk/c_src/KinoSearch/Search/MultiSearcher.c 2008-08-22 23:14:17 UTC (rev 3743)
+++ trunk/c_src/KinoSearch/Search/MultiSearcher.c 2008-08-22 23:39:36 UTC (rev 3744)
@@ -57,7 +57,7 @@
}

self->max_docs = max_docs;
- self->starts = IntMap_new(starts_array, searchables->size);
+ self->starts = IntMap_new_steal(starts_array, searchables->size);

return self;
}

Modified: trunk/c_src/KinoSearch/Util/BitVector.c
===================================================================
--- trunk/c_src/KinoSearch/Util/BitVector.c 2008-08-22 23:14:17 UTC (rev 3743)
+++ trunk/c_src/KinoSearch/Util/BitVector.c 2008-08-22 23:39:36 UTC (rev 3744)
@@ -366,7 +366,7 @@
} while (++num % 8);
}

- return IntMap_new((i32_t*)array, count);
+ return IntMap_new_steal((i32_t*)array, count);
}

/* Copyright 2006-2008 Marvin Humphrey

Modified: trunk/c_src/KinoSearch/Util/IntMap.bp
===================================================================
--- trunk/c_src/KinoSearch/Util/IntMap.bp 2008-08-22 23:14:17 UTC (rev 3743)
+++ trunk/c_src/KinoSearch/Util/IntMap.bp 2008-08-22 23:39:36 UTC (rev 3744)
@@ -4,11 +4,12 @@
i32_t *ints;
u32_t size;

- /* Constructors.
- */
static incremented IntMap*
new(i32_t *ints, u32_t size);

+ static incremented IntMap*
+ new_steal(i32_t *ints, u32_t size);
+
static IntMap*
init(IntMap *self, i32_t *ints, u32_t size);


Modified: trunk/c_src/KinoSearch/Util/IntMap.c
===================================================================
--- trunk/c_src/KinoSearch/Util/IntMap.c 2008-08-22 23:14:17 UTC (rev 3743)
+++ trunk/c_src/KinoSearch/Util/IntMap.c 2008-08-22 23:39:36 UTC (rev 3744)
@@ -6,6 +6,15 @@
IntMap_new(i32_t *ints, u32_t size)
{
IntMap *self = (IntMap*)CREATE(NULL, INTMAP);
+ i32_t *ints_copy = MALLOCATE(size, i32_t);
+ memcpy(ints_copy, ints, size * sizeof(i32_t));
+ return IntMap_init(self, ints_copy, size);
+}
+
+IntMap*
+IntMap_new_steal(i32_t *ints, u32_t size)
+{
+ IntMap *self = (IntMap*)CREATE(NULL, INTMAP);
return IntMap_init(self, ints, size);
}


Modified: trunk/perl/lib/KinoSearch/Util/IntMap.pm
===================================================================
--- trunk/perl/lib/KinoSearch/Util/IntMap.pm 2008-08-22 23:14:17 UTC (rev 3743)
+++ trunk/perl/lib/KinoSearch/Util/IntMap.pm 2008-08-22 23:39:36 UTC (rev 3744)
@@ -25,7 +25,7 @@

for (i = 0; i < size; i++) {
SV **const sv_ptr = av_fetch(ints_av, i, 0);
- ints[i] = (sv_ptr && SvOK(*sv_ptr)) ? SvIV(*sv_ptr) : -1;
+ ints[i] = (sv_ptr && SvOK(*sv_ptr)) ? SvIV(*sv_ptr) : 0;
}
self = (kino_IntMap*)KINO_CREATE((kino_CharBuf*)&class_name, KINO_INTMAP);
kino_IntMap_init(self, ints, size);
@@ -38,24 +38,6 @@
}
OUTPUT: RETVAL

-=for comment
-
-Return either the remapped number, or undef if the number is negative (as
-would be the case if the index is out of range).
-
-=cut
-
-SV *
-get(self, num)
- kino_IntMap *self;
- chy_i32_t num;
-CODE:
-{
- chy_i32_t result = Kino_IntMap_Get(self, num);
- RETVAL = result == -1 ? newSV(0) : newSViv(result);
-}
-OUTPUT: RETVAL
-
SV*
to_arrayref(self)
kino_IntMap *self;
@@ -77,7 +59,8 @@
__AUTO_XS__

{ "KinoSearch::Util::IntMap" => {
- make_getters => [qw( size )],
+ bind_methods => [qw( get )],
+ make_getters => [qw( size )],
}
}



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