Mailing List Archive

r3743 - in trunk: c_src/KinoSearch/Search c_src/KinoSearch/Util perl/t
Author: creamyg
Date: 2008-08-22 16:14:17 -0700 (Fri, 22 Aug 2008)
New Revision: 3743

Modified:
trunk/c_src/KinoSearch/Search/FieldDocCollator.bp
trunk/c_src/KinoSearch/Search/FieldDocCollator.c
trunk/c_src/KinoSearch/Search/RangeScorer.c
trunk/c_src/KinoSearch/Search/Scorer.c
trunk/c_src/KinoSearch/Util/IntMap.bp
trunk/c_src/KinoSearch/Util/IntMap.c
trunk/perl/t/210-deldocs.t
Log:
Change behavior of IntMap to throw an exception when presented with an
out-of-bounds tick rather than return -1.


Modified: trunk/c_src/KinoSearch/Search/FieldDocCollator.bp
===================================================================
--- trunk/c_src/KinoSearch/Search/FieldDocCollator.bp 2008-08-22 01:57:21 UTC (rev 3742)
+++ trunk/c_src/KinoSearch/Search/FieldDocCollator.bp 2008-08-22 23:14:17 UTC (rev 3743)
@@ -17,6 +17,7 @@
u32_t size;
IntMap **sort_caches;
bool_t *reversed;
+ u32_t *cache_sizes;

static incremented FieldDocCollator*
new();

Modified: trunk/c_src/KinoSearch/Search/FieldDocCollator.c
===================================================================
--- trunk/c_src/KinoSearch/Search/FieldDocCollator.c 2008-08-22 01:57:21 UTC (rev 3742)
+++ trunk/c_src/KinoSearch/Search/FieldDocCollator.c 2008-08-22 23:14:17 UTC (rev 3743)
@@ -18,6 +18,7 @@
self->size = 0;
self->sort_caches = NULL;
self->reversed = NULL;
+ self->cache_sizes = NULL;

return self;
}
@@ -33,6 +34,7 @@
}
free(self->sort_caches);
free(self->reversed);
+ free(self->cache_sizes);
FREE_OBJ(self);
}

@@ -44,11 +46,13 @@
self->cap += 10;
self->sort_caches
= REALLOCATE(self->sort_caches, self->cap, IntMap*);
- self->reversed = REALLOCATE(self->reversed, self->cap, bool_t);
+ self->reversed = REALLOCATE(self->reversed, self->cap, bool_t);
+ self->cache_sizes = REALLOCATE(self->cache_sizes, self->cap, u32_t);
}

self->sort_caches[ self->size ] = REFCOUNT_INC(sort_cache);
self->reversed[ self->size ] = rev;
+ self->cache_sizes[ self->size ] = sort_cache->size;
self->size++;
}

@@ -68,13 +72,17 @@
u32_t doc_num_b, float score_b)
{
IntMap **const sort_caches = self->sort_caches;
- bool_t *const reversed = self->reversed;
+ bool_t *const reversed = self->reversed;
u32_t i;

for (i = 0; i < self->size; i++) {
- /* TODO: unroll for speed. */
- const i32_t sort_num_a = IntMap_Get(sort_caches[i], doc_num_a);
- const i32_t sort_num_b = IntMap_Get(sort_caches[i], doc_num_b);
+ const u32_t cache_size = self->cache_sizes[i];
+ const i32_t sort_num_a
+ = doc_num_a >= cache_size ? 0
+ : IntMap_Get(sort_caches[i], doc_num_a);
+ const i32_t sort_num_b
+ = doc_num_b >= cache_size ? 0
+ : IntMap_Get(sort_caches[i], doc_num_b);

if (sort_num_a != sort_num_b) {
/* This appears to be backwards, but it isn't. Things have to be

Modified: trunk/c_src/KinoSearch/Search/RangeScorer.c
===================================================================
--- trunk/c_src/KinoSearch/Search/RangeScorer.c 2008-08-22 01:57:21 UTC (rev 3742)
+++ trunk/c_src/KinoSearch/Search/RangeScorer.c 2008-08-22 23:14:17 UTC (rev 3743)
@@ -44,20 +44,22 @@
RangeScorer_next(RangeScorer* self)
{
while(1) {
- const i32_t locus = IntMap_Get(self->sort_cache, ++self->doc_num);
-
- if (locus >= self->lower_bound && locus <= self->upper_bound) {
- /* Note that any deleted document will fetch -1 from the sort
- * cache because the sort cache is generated from a PostingList
- * which takes into account deleted docs. Also, any doc num
- * greater than max_docs will fetch -1.
- */
- break;
- }
- else if (self->doc_num > self->max_docs) {
+ if (++self->doc_num >= self->max_docs) {
self->doc_num--;
return 0;
}
+ else {
+ const i32_t locus = IntMap_Get(self->sort_cache, self->doc_num);
+
+ if (locus >= self->lower_bound && locus <= self->upper_bound) {
+ /* Note that any deleted document will fetch -1 from the sort
+ * cache because the sort cache is generated from a PostingList
+ * which takes into account deleted docs. Also, any doc num
+ * greater than max_docs will fetch -1.
+ */
+ break;
+ }
+ }
}
return self->doc_num;
}

Modified: trunk/c_src/KinoSearch/Search/Scorer.c
===================================================================
--- trunk/c_src/KinoSearch/Search/Scorer.c 2008-08-22 01:57:21 UTC (rev 3742)
+++ trunk/c_src/KinoSearch/Search/Scorer.c 2008-08-22 23:14:17 UTC (rev 3743)
@@ -70,8 +70,10 @@
}
else {
/* Get start of upcoming segment. */
- i32_t next_start = IntMap_get(seg_starts, seg_num + 1);
- i32_t this_start = IntMap_get(seg_starts, seg_num);
+ i32_t next_start = (seg_num + 1) < seg_starts->size
+ ? IntMap_Get(seg_starts, seg_num + 1) : -1;
+ i32_t this_start = seg_num < seg_starts->size
+ ? IntMap_Get(seg_starts, seg_num) : -1;
seg_num++;

/* Skip docs as appropriate if we're pruning. */
@@ -82,7 +84,7 @@
}

/* Set the last doc_num we'll score this upcoming segment. */
- doc_num_thresh = next_start == -1
+ doc_num_thresh = next_start == -1
? limit /* last segment */
: (u32_t)next_start;
}

Modified: trunk/c_src/KinoSearch/Util/IntMap.bp
===================================================================
--- trunk/c_src/KinoSearch/Util/IntMap.bp 2008-08-22 01:57:21 UTC (rev 3742)
+++ trunk/c_src/KinoSearch/Util/IntMap.bp 2008-08-22 23:14:17 UTC (rev 3743)
@@ -13,7 +13,7 @@
init(IntMap *self, i32_t *ints, u32_t size);

/* Return the number present at the index requested. If the requested
- * index is out of range, return -1.
+ * index is out of range, throw an exception.
*/
i32_t
Get(IntMap *self, i32_t num);

Modified: trunk/c_src/KinoSearch/Util/IntMap.c
===================================================================
--- trunk/c_src/KinoSearch/Util/IntMap.c 2008-08-22 01:57:21 UTC (rev 3742)
+++ trunk/c_src/KinoSearch/Util/IntMap.c 2008-08-22 23:14:17 UTC (rev 3743)
@@ -20,8 +20,8 @@
i32_t
IntMap_get(IntMap *self, i32_t num)
{
- if (num >= (i32_t)self->size || num < 0) {
- return -1;
+ if (num < 0 || num >= (i32_t)self->size) {
+ CONFESS("Out of bounds: %i32 > %i32", num, self->size);
}
return self->ints[num];
}

Modified: trunk/perl/t/210-deldocs.t
===================================================================
--- trunk/perl/t/210-deldocs.t 2008-08-22 01:57:21 UTC (rev 3742)
+++ trunk/perl/t/210-deldocs.t 2008-08-22 23:14:17 UTC (rev 3743)
@@ -2,7 +2,7 @@
use warnings;
use lib 'buildlib';

-use Test::More tests => 13;
+use Test::More tests => 12;

use KinoSearch::Index::DelDocs;

@@ -44,7 +44,6 @@
$doc_map = $deldocs->generate_doc_map(100);
is( $doc_map->get(4), 103, "doc map handles offset correctly" );
ok( !$doc_map->get(3), "doc_map handled deletions correctly" );
-ok( !$doc_map->get(6), "doc_map handles out of range doc numbers correctly" );

$deldocs->clear(3);
$deldocs->clear(3);


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