lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject [lucy-commits] [08/34] git commit: refs/heads/master - Use accessors for Spans.
Date Wed, 17 Jul 2013 14:12:28 GMT
Use accessors for Spans.

Go through accessors when accessing Span member variables from HeatMap
and Highlighter, rather than using direct struct member access.


Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/6827b4fa
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/6827b4fa
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/6827b4fa

Branch: refs/heads/master
Commit: 6827b4fad9c7c911797b52bb4ba464e9383a1f12
Parents: 9645b2e
Author: Marvin Humphrey <marvin@rectangular.com>
Authored: Fri Jun 28 10:15:01 2013 -0700
Committer: Marvin Humphrey <marvin@rectangular.com>
Committed: Tue Jul 16 15:50:07 2013 -0700

----------------------------------------------------------------------
 core/Lucy/Highlight/HeatMap.c     | 34 +++++++++++++++++++---------------
 core/Lucy/Highlight/Highlighter.c | 25 +++++++++++++------------
 2 files changed, 32 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/6827b4fa/core/Lucy/Highlight/HeatMap.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Highlight/HeatMap.c b/core/Lucy/Highlight/HeatMap.c
index 164ca9f..0d976e9 100644
--- a/core/Lucy/Highlight/HeatMap.c
+++ b/core/Lucy/Highlight/HeatMap.c
@@ -15,7 +15,6 @@
  */
 
 #define C_LUCY_HEATMAP
-#define C_LUCY_SPAN
 #include "Lucy/Util/ToolSet.h"
 
 #include "Lucy/Highlight/HeatMap.h"
@@ -70,8 +69,8 @@ S_flattened_but_empty_spans(VArray *spans) {
     // Assemble a list of all unique start/end boundaries.
     for (uint32_t i = 0; i < num_spans; i++) {
         Span *span            = (Span*)VA_Fetch(spans, i);
-        bounds[i]             = span->offset;
-        bounds[i + num_spans] = span->offset + span->length;
+        bounds[i]             = Span_Get_Offset(span);
+        bounds[i + num_spans] = Span_Get_Offset(span) + Span_Get_Length(span);
     }
     Sort_quicksort(bounds, num_spans * 2, sizeof(uint32_t),
                    S_compare_i32, NULL);
@@ -113,14 +112,15 @@ HeatMap_flatten_spans(HeatMap *self, VArray *spans) {
         uint32_t dest_tick = 0;
         for (uint32_t i = 0; i < num_spans; i++) {
             Span *source_span = (Span*)VA_Fetch(spans, i);
-            int32_t source_span_end
-                = source_span->offset + source_span->length;
+            int32_t source_span_offset = Span_Get_Offset(source_span);
+            int32_t source_span_len    = Span_Get_Length(source_span);
+            int32_t source_span_end    = source_span_offset + source_span_len;
 
             // Get the location of the flattened span that shares the source
             // span's offset.
             for (; dest_tick < num_raw_flattened; dest_tick++) {
                 Span *dest_span = (Span*)VA_Fetch(flattened, dest_tick);
-                if (dest_span->offset == source_span->offset) {
+                if (Span_Get_Offset(dest_span) == source_span_offset) {
                     break;
                 }
             }
@@ -128,11 +128,13 @@ HeatMap_flatten_spans(HeatMap *self, VArray *spans) {
             // Fill in scores.
             for (uint32_t j = dest_tick; j < num_raw_flattened; j++) {
                 Span *dest_span = (Span*)VA_Fetch(flattened, j);
-                if (dest_span->offset == source_span_end) {
+                if (Span_Get_Offset(dest_span) == source_span_end) {
                     break;
                 }
                 else {
-                    dest_span->weight += source_span->weight;
+                    float new_weight = Span_Get_Weight(dest_span)
+                                       + Span_Get_Weight(source_span);
+                    Span_Set_Weight(dest_span, new_weight);
                 }
             }
         }
@@ -141,7 +143,7 @@ HeatMap_flatten_spans(HeatMap *self, VArray *spans) {
         dest_tick = 0;
         for (uint32_t i = 0; i < num_raw_flattened; i++) {
             Span *span = (Span*)VA_Fetch(flattened, i);
-            if (span->weight) {
+            if (Span_Get_Weight(span)) {
                 VA_Store(flattened, dest_tick++, INCREF(span));
             }
         }
@@ -156,8 +158,8 @@ HeatMap_calc_proximity_boost(HeatMap *self, Span *span1, Span *span2)
{
     int32_t comparison = Span_Compare_To(span1, (Obj*)span2);
     Span *lower = comparison <= 0 ? span1 : span2;
     Span *upper = comparison >= 0 ? span1 : span2;
-    int32_t lower_end_offset = lower->offset + lower->length;
-    int32_t distance = upper->offset - lower_end_offset;
+    int32_t lower_end_offset = Span_Get_Offset(lower) + Span_Get_Length(lower);
+    int32_t distance = Span_Get_Offset(upper) - lower_end_offset;
 
     // If spans overlap, set distance to 0.
     if (distance < 0) { distance = 0; }
@@ -169,7 +171,7 @@ HeatMap_calc_proximity_boost(HeatMap *self, Span *span1, Span *span2)
{
         float factor = (self->window - distance) / (float)self->window;
         // Damp boost with greater distance.
         factor *= factor;
-        return factor * (lower->weight + upper->weight);
+        return factor * (Span_Get_Weight(lower) + Span_Get_Weight(upper));
     }
 }
 
@@ -190,10 +192,12 @@ HeatMap_generate_proximity_boosts(HeatMap *self, VArray *spans) {
                     break;
                 }
                 else {
-                    int32_t length = (span2->offset - span1->offset)
-                                     + span2->length;
+                    int32_t length = Span_Get_Offset(span2)
+                                     - Span_Get_Offset(span1)
+                                     + Span_Get_Length(span2);
                     VA_Push(boosts,
-                            (Obj*)Span_new(span1->offset, length, prox_score));
+                            (Obj*)Span_new(Span_Get_Offset(span1), length,
+                                           prox_score));
                 }
             }
         }

http://git-wip-us.apache.org/repos/asf/lucy/blob/6827b4fa/core/Lucy/Highlight/Highlighter.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Highlight/Highlighter.c b/core/Lucy/Highlight/Highlighter.c
index 555979f..85afe29 100644
--- a/core/Lucy/Highlight/Highlighter.c
+++ b/core/Lucy/Highlight/Highlighter.c
@@ -15,7 +15,6 @@
  */
 
 #define C_LUCY_HIGHLIGHTER
-#define C_LUCY_SPAN
 #include <ctype.h>
 #include "Lucy/Util/ToolSet.h"
 
@@ -198,9 +197,9 @@ S_hottest(HeatMap *heat_map) {
     VArray *spans = HeatMap_Get_Spans(heat_map);
     for (uint32_t i = VA_Get_Size(spans); i--;) {
         Span *span = (Span*)VA_Fetch(spans, i);
-        if (span->weight >= max_score) {
-            retval = span->offset;
-            max_score = span->weight;
+        if (Span_Get_Weight(span) >= max_score) {
+            retval = Span_Get_Offset(span);
+            max_score = Span_Get_Weight(span);
         }
     }
     return retval;
@@ -269,8 +268,8 @@ S_has_heat(HeatMap *heat_map, int32_t offset, int32_t length) {
 
     for (uint32_t i = 0; i < num_spans; i++) {
         Span *span  = (Span*)VA_Fetch(spans, i);
-        int32_t span_start = span->offset;
-        int32_t span_end   = span_start + span->length;
+        int32_t span_start = Span_Get_Offset(span);
+        int32_t span_end   = span_start + Span_Get_Length(span);;
         if (offset >= span_start && offset <  span_end) { return true; }
         if (end    >  span_start && end    <= span_end) { return true; }
         if (offset <= span_start && end    >= span_end) { return true; }
@@ -298,7 +297,7 @@ Highlighter_raw_excerpt(Highlighter *self, const CharBuf *field_val,
     if (num_sentences) {
         for (uint32_t i = 0; i < num_sentences; i++) {
             Span *sentence = (Span*)VA_Fetch(sentences, i);
-            int32_t candidate = sentence->offset;
+            int32_t candidate = Span_Get_Offset(sentence);;
 
             if (candidate > top + (int32_t)self->window_width) {
                 break;
@@ -328,7 +327,8 @@ Highlighter_raw_excerpt(Highlighter *self, const CharBuf *field_val,
 
         for (uint32_t i = num_sentences; i--;) {
             Span    *sentence  = (Span*)VA_Fetch(sentences, i);
-            int32_t  last_edge = sentence->offset + sentence->length;
+            int32_t  last_edge = Span_Get_Offset(sentence)
+                                 + Span_Get_Length(sentence);
 
             if (last_edge <= start) {
                 break;
@@ -491,15 +491,16 @@ Highlighter_highlight_excerpt(Highlighter *self, VArray *spans,
 
     for (uint32_t i = 0, max = VA_Get_Size(spans); i < max; i++) {
         Span *span = (Span*)VA_Fetch(spans, i);
-        if (span->offset < top) {
+        int32_t offset = Span_Get_Offset(span);
+        if (offset < top) {
             continue;
         }
-        else if (span->offset >= raw_excerpt_end) {
+        else if (offset >= raw_excerpt_end) {
             break;
         }
         else {
-            int32_t relative_start = span->offset - top;
-            int32_t relative_end   = relative_start + span->length;
+            int32_t relative_start = offset - top;
+            int32_t relative_end   = relative_start + Span_Get_Length(span);
 
             if (relative_start <= hl_end) {
                 if (relative_end > hl_end) {


Mime
View raw message