Mailing List Archive

r3686 - in trunk/c_src/KinoSearch: Highlight Search
Author: creamyg
Date: 2008-07-30 20:01:32 -0700 (Wed, 30 Jul 2008)
New Revision: 3686

Modified:
trunk/c_src/KinoSearch/Highlight/HeatMap.c
trunk/c_src/KinoSearch/Highlight/Highlighter.bp
trunk/c_src/KinoSearch/Highlight/Highlighter.c
trunk/c_src/KinoSearch/Search/Span.bp
trunk/c_src/KinoSearch/Search/Span.c
Log:
Use i32_t for Span offset and length.


Modified: trunk/c_src/KinoSearch/Highlight/HeatMap.c
===================================================================
--- trunk/c_src/KinoSearch/Highlight/HeatMap.c 2008-07-31 02:24:12 UTC (rev 3685)
+++ trunk/c_src/KinoSearch/Highlight/HeatMap.c 2008-07-31 03:01:32 UTC (rev 3686)
@@ -38,9 +38,9 @@
}

static int
-compare_u32(const void *va, const void *vb)
+compare_i32(const void *va, const void *vb)
{
- return *(u32_t*)va - *(u32_t*)vb;
+ return *(i32_t*)va - *(i32_t*)vb;
}

/* Create all the spans needed by HeatMap_Flatten_Spans, based on the source
@@ -50,10 +50,10 @@
{
VArray *flattened;
u32_t num_spans = spans->size;
- u32_t *bounds = MALLOCATE(num_spans * 2, u32_t);
+ i32_t *bounds = MALLOCATE(num_spans * 2, i32_t);
u32_t num_bounds;
u32_t i;
- u32_t last;
+ i32_t last;

/* Assemble a list of all unique start/end boundaries. */
for (i = 0; i < num_spans; i++) {
@@ -61,7 +61,7 @@
bounds[i] = span->offset;
bounds[i + num_spans] = span->offset + span->length;
}
- qsort(bounds, num_spans * 2, sizeof(u32_t), compare_u32);
+ qsort(bounds, num_spans * 2, sizeof(u32_t), compare_i32);
for (i = 0, num_bounds = 0, last = U32_MAX; i < num_spans * 2; i++) {
if (bounds[i] != last) {
bounds[num_bounds++] = bounds[i];
@@ -72,8 +72,8 @@
/* Create one Span for each zone between two bounds. */
flattened = VA_new(num_bounds - 1);
for (i = 0; i < num_bounds - 1; i++) {
- u32_t start = bounds[i];
- u32_t length = bounds[i + 1] - start;
+ i32_t start = bounds[i];
+ i32_t length = bounds[i + 1] - start;
Span *span = Span_new(start, length, 0.0f);
VA_Push(flattened, (Obj*)span);
REFCOUNT_DEC(span);
@@ -101,7 +101,7 @@
for (i = 0; i < spans->size; i++) {
Span *source_span = (Span*)VA_Fetch(spans, i);
u32_t j;
- u32_t source_span_end = source_span->offset + source_span->length;
+ i32_t source_span_end = source_span->offset + source_span->length;

/* Get the location of the flattened span that shares the source
* span's offset. */
@@ -145,12 +145,12 @@
Span *lower = comparison <= 0 ? span1 : span2;
Span *upper = comparison >= 0 ? span1 : span2;
i32_t lower_end_offset = lower->offset + lower->length;
- i32_t distance = (i32_t)upper->offset - lower_end_offset;
+ i32_t distance = upper->offset - lower_end_offset;

/* If spans overlap, set distance to 0. */
if (distance < 0) distance = 0;

- if ((u32_t)distance > self->window) {
+ if (distance > (i32_t)self->window) {
return 0.0f;
}
else {
@@ -180,7 +180,7 @@
break;
}
else {
- u32_t length = (span2->offset - span1->offset)
+ i32_t length = (span2->offset - span1->offset)
+ span2->length;
Span *boost_span = Span_new(span1->offset, length,
prox_score);

Modified: trunk/c_src/KinoSearch/Highlight/Highlighter.bp
===================================================================
--- trunk/c_src/KinoSearch/Highlight/Highlighter.bp 2008-07-31 02:24:12 UTC (rev 3685)
+++ trunk/c_src/KinoSearch/Highlight/Highlighter.bp 2008-07-31 03:01:32 UTC (rev 3686)
@@ -38,8 +38,8 @@
* until the end of the string.
*/
incremented IntMap*
- Find_Sentence_Boundaries(Highlighter *self, CharBuf *text, u32_t offset = 0,
- u32_t length = 0);
+ Find_Sentence_Boundaries(Highlighter *self, CharBuf *text, i32_t offset = 0,
+ i32_t length = 0);

public incremented CharBuf*
Highlight(Highlighter *self, const CharBuf *text);
@@ -62,7 +62,7 @@
*
* (Helper function for Create_Excerpt only exposed for testing purposes.)
*/
- u32_t
+ i32_t
Find_Best_Fragment(Highlighter *self, const CharBuf *field_val,
ViewCharBuf *fragment, HeatMap *heat_map);

@@ -72,9 +72,9 @@
*
* (Helper function for Create_Excerpt only exposed for testing purposes.)
*/
- u32_t
+ i32_t
Raw_Excerpt(Highlighter *self, const CharBuf *field_val,
- const CharBuf *fragment, CharBuf *raw_excerpt, u32_t top,
+ const CharBuf *fragment, CharBuf *raw_excerpt, i32_t top,
IntMap *edges);

/* Take the text in raw_excerpt, add highlight tags, encode, and place the
@@ -84,7 +84,7 @@
*/
void
Highlight_Excerpt(Highlighter *self, VArray *spans,
- CharBuf *raw_excerpt, CharBuf *highlighted, u32_t top);
+ CharBuf *raw_excerpt, CharBuf *highlighted, i32_t top);

void
Destroy(Highlighter *self);

Modified: trunk/c_src/KinoSearch/Highlight/Highlighter.c
===================================================================
--- trunk/c_src/KinoSearch/Highlight/Highlighter.c 2008-07-31 02:24:12 UTC (rev 3685)
+++ trunk/c_src/KinoSearch/Highlight/Highlighter.c 2008-07-31 03:01:32 UTC (rev 3686)
@@ -100,7 +100,7 @@
self->searchable, doc_vec, self->field);
HeatMap *heat_map = HeatMap_new(score_spans,
self->excerpt_length * 0.6666);
- u32_t top = Highlighter_Find_Best_Fragment(self, (CharBuf*)field_val,
+ i32_t top = Highlighter_Find_Best_Fragment(self, (CharBuf*)field_val,
(ViewCharBuf*)&fragment, heat_map);
IntMap *edges = Highlighter_Find_Sentence_Boundaries(self,
(CharBuf*)field_val, top, self->window_width);
@@ -121,12 +121,12 @@
}
}

-static u32_t
+static i32_t
hottest(HeatMap *heat_map)
{
u32_t i;
float max_score = 0.0f;
- u32_t retval = 0;
+ i32_t retval = 0;
for (i = heat_map->spans->size; i--; ) {
Span *span = (Span*)VA_Fetch(heat_map->spans, i);
if (span->weight >= max_score) {
@@ -137,27 +137,27 @@
return retval;
}

-u32_t
+i32_t
Highlighter_find_best_fragment(Highlighter *self, const CharBuf *field_val,
ViewCharBuf *fragment, HeatMap *heat_map)
{
/* Window is 1.66 * excerpt_length, with the loc in the middle. */
- u32_t best_location = hottest(heat_map);
+ i32_t best_location = hottest(heat_map);

- if (best_location < self->slop) {
+ if (best_location < (i32_t)self->slop) {
/* If the beginning of the string falls within the window centered
* around the hottest point in the field, start the fragment at the
* beginning. */
- u32_t top;
+ i32_t top;
ViewCB_Assign(fragment, (CharBuf*)field_val);
top = ViewCB_Trim_Top(fragment);
ViewCB_Truncate(fragment, self->window_width);
return top;
}
else {
- u32_t top = best_location - self->slop;
- u32_t chars_left;
- u32_t overrun;
+ i32_t top = best_location - self->slop;
+ i32_t chars_left;
+ i32_t overrun;

ViewCB_Assign(fragment, (CharBuf*)field_val);
ViewCB_Nip(fragment, top);
@@ -191,23 +191,23 @@
}
}

-u32_t
+i32_t
Highlighter_raw_excerpt(Highlighter *self, const CharBuf *field_val,
const CharBuf *fragment, CharBuf *raw_excerpt,
- u32_t top, IntMap *edges)
+ i32_t top, IntMap *edges)
{
bool_t found_starting_edge = false;
bool_t found_ending_edge = false;
- u32_t start = top;
- u32_t end = 0;
- u32_t this_excerpt_len;
+ i32_t start = top;
+ i32_t end = 0;
+ i32_t this_excerpt_len;

/* Try to find a starting sentence boundary. */
if (edges->size) {
u32_t i;

for (i = 0; i < edges->size; i++) {
- u32_t candidate = (u32_t)IntMap_Get(edges, i);
+ i32_t candidate = IntMap_Get(edges, i);

if (candidate < top){
continue;
@@ -241,13 +241,13 @@
ZCB_Nip(&start_trimmed, start - top);

for (i = edges->size; i--; ) {
- u32_t last_edge = (u32_t)IntMap_Get(edges, i);
+ i32_t last_edge = IntMap_Get(edges, i);

if (last_edge <= start) {
/* Sanity. */
break;
}
- else if (last_edge - start > self->excerpt_length) {
+ else if (last_edge - start > (i32_t)self->excerpt_length) {
continue;
}
else {
@@ -270,7 +270,7 @@
}
this_excerpt_len = found_ending_edge
? end - start
- : self->excerpt_length;
+ : (i32_t)self->excerpt_length;
if (!this_excerpt_len) return start;

if (found_starting_edge) {
@@ -307,7 +307,7 @@
* we don't know a solid end point yet. */
break;
}
- else if (this_excerpt_len <= self->excerpt_length) {
+ else if (this_excerpt_len <= (i32_t)self->excerpt_length) {
break;
}
}
@@ -339,7 +339,7 @@
void
Highlighter_highlight_excerpt(Highlighter *self, VArray *spans,
CharBuf *raw_excerpt, CharBuf *highlighted,
- u32_t top)
+ i32_t top)
{
u32_t i;
i32_t last_end = 0;
@@ -394,24 +394,24 @@
}

static INLINE void
-add_bound(u32_t pos, ByteBuf *bounds_bb) {
- if (bounds_bb->cap - bounds_bb->len < sizeof(u32_t)) {
- BB_Grow(bounds_bb, bounds_bb->len + 10 * sizeof(u32_t));
+add_bound(i32_t pos, ByteBuf *bounds_bb) {
+ if (bounds_bb->cap - bounds_bb->len < sizeof(i32_t)) {
+ BB_Grow(bounds_bb, bounds_bb->len + 10 * sizeof(i32_t));
}
- *(u32_t*)BBEND(bounds_bb) = pos;
+ *(i32_t*)BBEND(bounds_bb) = pos;
bounds_bb->len += sizeof(u32_t);
}

IntMap*
Highlighter_find_sentence_boundaries(Highlighter *self, CharBuf *text,
- u32_t offset, u32_t length)
+ i32_t offset, i32_t length)
{
ByteBuf *bounds_bb = BB_new(10 * sizeof(u32_t));
- u32_t max = length == 0
+ i32_t max = length == 0
? I32_MAX
: offset + length;
ZombieCharBuf substring = ZCB_make(text);
- u32_t pos = ZCB_Trim_Top(&substring);
+ i32_t pos = ZCB_Trim_Top(&substring);
UNUSED_VAR(self);

if (offset <= pos) {

Modified: trunk/c_src/KinoSearch/Search/Span.bp
===================================================================
--- trunk/c_src/KinoSearch/Search/Span.bp 2008-07-31 02:24:12 UTC (rev 3685)
+++ trunk/c_src/KinoSearch/Search/Span.bp 2008-07-31 03:01:32 UTC (rev 3686)
@@ -12,12 +12,12 @@
*/
class KinoSearch::Search::Span extends KinoSearch::Obj {

- u32_t offset;
- u32_t length;
+ i32_t offset;
+ i32_t length;
float weight;

static incremented Span*
- new(u32_t offset, u32_t length, float weight = 0.0);
+ new(i32_t offset, i32_t length, float weight = 0.0);

/**
* @param offset Integer offset, unit is context-dependent.
@@ -25,28 +25,28 @@
* @param weight A floating point weight.
*/
static Span*
- init(Span *self, u32_t offset, u32_t length,
+ init(Span *self, i32_t offset, i32_t length,
float weight = 0.0);

/** Accessor for <code>offset</code> attribute.
*/
- u32_t
+ i32_t
Get_Offset(Span *self);

/** Setter for <code>offset</code> attribute.
*/
void
- Set_Offset(Span *self, u32_t offset);
+ Set_Offset(Span *self, i32_t offset);

/** Accessor for <code>length</code> attribute.
*/
- u32_t
+ i32_t
Get_Length(Span *self);

/** Setter for <code>length</code> attribute.
*/
void
- Set_Length(Span *self, u32_t length);
+ Set_Length(Span *self, i32_t length);

/** Accessor for <code>weight</code> attribute.
*/

Modified: trunk/c_src/KinoSearch/Search/Span.c
===================================================================
--- trunk/c_src/KinoSearch/Search/Span.c 2008-07-31 02:24:12 UTC (rev 3685)
+++ trunk/c_src/KinoSearch/Search/Span.c 2008-07-31 03:01:32 UTC (rev 3686)
@@ -3,14 +3,14 @@
#include "KinoSearch/Search/Span.h"

Span*
-Span_new(u32_t offset, u32_t length, float weight)
+Span_new(i32_t offset, i32_t length, float weight)
{
Span *self = (Span*)CREATE(NULL, SPAN);
return Span_init(self, offset, length, weight);
}

Span*
-Span_init(Span *self, u32_t offset, u32_t length,
+Span_init(Span *self, i32_t offset, i32_t length,
float weight)
{
self->offset = offset;
@@ -19,16 +19,16 @@
return self;
}

-u32_t
+i32_t
Span_get_offset(Span *self) { return self->offset; }
-u32_t
+i32_t
Span_get_length(Span *self) { return self->length; }
float
Span_get_weight(Span *self) { return self->weight; }
void
-Span_set_offset(Span *self, u32_t offset) { self->offset = offset; }
+Span_set_offset(Span *self, i32_t offset) { self->offset = offset; }
void
-Span_set_length(Span *self, u32_t length) { self->length = length; }
+Span_set_length(Span *self, i32_t length) { self->length = length; }
void
Span_set_weight(Span *self, float weight) { self->weight = weight; }



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