lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject [lucy-commits] [07/11] git commit: refs/heads/ivars-wip1 - Fixup Lucy posting classes IVARS glitches.
Date Thu, 11 Jul 2013 22:33:32 GMT
Fixup Lucy posting classes IVARS glitches.

(Will be folded into earlier commit before merging to master.)


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

Branch: refs/heads/ivars-wip1
Commit: fb7d4facd02083ab4a32769a5a7106ea6e364f12
Parents: ea242c8
Author: Marvin Humphrey <marvin@rectangular.com>
Authored: Thu Jul 11 15:04:30 2013 -0700
Committer: Marvin Humphrey <marvin@rectangular.com>
Committed: Thu Jul 11 15:04:30 2013 -0700

----------------------------------------------------------------------
 core/Lucy/Index/Posting/MatchPosting.c | 11 +++++++----
 core/Lucy/Index/Posting/RawPosting.c   |  7 ++++---
 core/Lucy/Index/Posting/RichPosting.c  | 11 +++++++----
 core/Lucy/Index/Posting/ScorePosting.c | 18 +++++++++++-------
 4 files changed, 29 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/fb7d4fac/core/Lucy/Index/Posting/MatchPosting.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/Posting/MatchPosting.c b/core/Lucy/Index/Posting/MatchPosting.c
index f12a4c8..bdb9f97 100644
--- a/core/Lucy/Index/Posting/MatchPosting.c
+++ b/core/Lucy/Index/Posting/MatchPosting.c
@@ -43,8 +43,8 @@
 #include "Lucy/Store/OutStream.h"
 #include "Lucy/Util/MemoryPool.h"
 
-#define MAX_RAW_POSTING_LEN(_text_len) \
-    (              sizeof(RawPosting) \
+#define MAX_RAW_POSTING_LEN(_raw_post_size, _text_len) \
+    (              _raw_post_size \
                    + _text_len + 1            /* term text content */ \
     )
 
@@ -105,7 +105,8 @@ MatchPost_read_raw(MatchPosting *self, InStream *instream, int32_t last_doc_id,
     const uint32_t freq      = (doc_code & 1)
                                ? 1
                                : InStream_Read_C32(instream);
-    size_t raw_post_bytes    = MAX_RAW_POSTING_LEN(text_size);
+    const size_t base_size    = VTable_Get_Obj_Alloc_Size(RAWPOSTING);
+    size_t raw_post_bytes    = MAX_RAW_POSTING_LEN(base_size, text_size);
     void *const allocation   = MemPool_Grab(mem_pool, raw_post_bytes);
     UNUSED_VAR(self);
 
@@ -118,6 +119,7 @@ MatchPost_add_inversion_to_pool(MatchPosting *self, PostingPool *post_pool,
                                 int32_t doc_id, float doc_boost,
                                 float length_norm) {
     MemoryPool  *mem_pool = PostPool_Get_Mem_Pool(post_pool);
+    const size_t base_size = VTable_Get_Obj_Alloc_Size(RAWPOSTING);
     Token      **tokens;
     uint32_t     freq;
 
@@ -129,7 +131,8 @@ MatchPost_add_inversion_to_pool(MatchPosting *self, PostingPool *post_pool,
     Inversion_Reset(inversion);
     while ((tokens = Inversion_Next_Cluster(inversion, &freq)) != NULL) {
         TokenIVARS *const token_ivars = Token_IVARS(*tokens);
-        uint32_t raw_post_bytes = MAX_RAW_POSTING_LEN(token_ivars->len);
+        uint32_t raw_post_bytes
+            = MAX_RAW_POSTING_LEN(base_size, token_ivars->len);
         RawPosting *raw_posting
             = RawPost_new(MemPool_Grab(mem_pool, raw_post_bytes), doc_id,
                           freq, token_ivars->text, token_ivars->len);

http://git-wip-us.apache.org/repos/asf/lucy/blob/fb7d4fac/core/Lucy/Index/Posting/RawPosting.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/Posting/RawPosting.c b/core/Lucy/Index/Posting/RawPosting.c
index 624beda..1fb73be 100644
--- a/core/Lucy/Index/Posting/RawPosting.c
+++ b/core/Lucy/Index/Posting/RawPosting.c
@@ -96,7 +96,8 @@ void
 RawPostWriter_start_term(RawPostingWriter *self, TermInfo *tinfo) {
     RawPostingWriterIVARS *const ivars = RawPostWriter_IVARS(self);
     ivars->last_doc_id   = 0;
-    tinfo->post_filepos = OutStream_Tell(ivars->outstream);
+    TermInfoIVARS *const tinfo_ivars = TInfo_IVARS(tinfo);
+    tinfo_ivars->post_filepos = OutStream_Tell(ivars->outstream);
 }
 
 void
@@ -122,14 +123,14 @@ RawPostWriter_write_posting(RawPostingWriter *self, RawPosting *posting)
{
     const uint32_t   delta_doc   = doc_id - ivars->last_doc_id;
     char  *const     aux_content = posting_ivars->blob
                                    + posting_ivars->content_len;
-    if (posting->freq == 1) {
+    if (posting_ivars->freq == 1) {
         const uint32_t doc_code = (delta_doc << 1) | 1;
         OutStream_Write_C32(outstream, doc_code);
     }
     else {
         const uint32_t doc_code = delta_doc << 1;
         OutStream_Write_C32(outstream, doc_code);
-        OutStream_Write_C32(outstream, posting->freq);
+        OutStream_Write_C32(outstream, posting_ivars->freq);
     }
     OutStream_Write_Bytes(outstream, aux_content, posting_ivars->aux_len);
     ivars->last_doc_id = doc_id;

http://git-wip-us.apache.org/repos/asf/lucy/blob/fb7d4fac/core/Lucy/Index/Posting/RichPosting.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/Posting/RichPosting.c b/core/Lucy/Index/Posting/RichPosting.c
index 40b23b6..9715765 100644
--- a/core/Lucy/Index/Posting/RichPosting.c
+++ b/core/Lucy/Index/Posting/RichPosting.c
@@ -33,8 +33,8 @@
 #include "Lucy/Util/MemoryPool.h"
 
 #define FREQ_MAX_LEN     C32_MAX_BYTES
-#define MAX_RAW_POSTING_LEN(_text_len, _freq) \
-    (              sizeof(RawPosting) \
+#define MAX_RAW_POSTING_LEN(_raw_posting_size, _text_len, _freq) \
+    (              _raw_posting_size \
                    + _text_len                /* term text content */ \
                    + FREQ_MAX_LEN             /* freq c32 */ \
                    + (C32_MAX_BYTES * _freq)  /* positions deltas */ \
@@ -113,13 +113,15 @@ RichPost_add_inversion_to_pool(RichPosting *self, PostingPool *post_pool,
     MemoryPool *mem_pool = PostPool_Get_Mem_Pool(post_pool);
     Similarity *sim = ivars->sim;
     float       field_boost = doc_boost * FType_Get_Boost(type) * length_norm;
+    const size_t base_size = VTable_Get_Obj_Alloc_Size(RAWPOSTING);
     Token     **tokens;
     uint32_t    freq;
 
     Inversion_Reset(inversion);
     while ((tokens = Inversion_Next_Cluster(inversion, &freq)) != NULL) {
         TokenIVARS *const token_ivars = Token_IVARS(*tokens);
-        uint32_t raw_post_bytes = MAX_RAW_POSTING_LEN(token_ivars->len, freq);
+        uint32_t raw_post_bytes
+            = MAX_RAW_POSTING_LEN(base_size, token_ivars->len, freq);
         RawPosting *raw_posting
             = RawPost_new(MemPool_Grab(mem_pool, raw_post_bytes), doc_id,
                           freq, token_ivars->text, token_ivars->len);
@@ -160,7 +162,8 @@ RichPost_read_raw(RichPosting *self, InStream *instream, int32_t last_doc_id,
     const uint32_t freq           = (doc_code & 1)
                                     ? 1
                                     : InStream_Read_C32(instream);
-    size_t raw_post_bytes         = MAX_RAW_POSTING_LEN(text_size, freq);
+    const size_t base_size        = VTable_Get_Obj_Alloc_Size(RAWPOSTING);
+    size_t raw_post_bytes         = MAX_RAW_POSTING_LEN(base_size, text_size, freq);
     void *const allocation        = MemPool_Grab(mem_pool, raw_post_bytes);
     RawPosting *const raw_posting
         = RawPost_new(allocation, doc_id, freq, text_buf, text_size);

http://git-wip-us.apache.org/repos/asf/lucy/blob/fb7d4fac/core/Lucy/Index/Posting/ScorePosting.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/Posting/ScorePosting.c b/core/Lucy/Index/Posting/ScorePosting.c
index 1cba64a..f02de37 100644
--- a/core/Lucy/Index/Posting/ScorePosting.c
+++ b/core/Lucy/Index/Posting/ScorePosting.c
@@ -35,8 +35,8 @@
 
 #define FIELD_BOOST_LEN  1
 #define FREQ_MAX_LEN     C32_MAX_BYTES
-#define MAX_RAW_POSTING_LEN(_text_len, _freq) \
-    (              sizeof(RawPosting) \
+#define MAX_RAW_POSTING_LEN(_raw_post_size, _text_len, _freq) \
+    (              _raw_post_size \
                    + _text_len                /* term text content */ \
                    + FIELD_BOOST_LEN          /* field boost byte */ \
                    + FREQ_MAX_LEN             /* freq c32 */ \
@@ -83,13 +83,15 @@ ScorePost_add_inversion_to_pool(ScorePosting *self, PostingPool *post_pool,
     Similarity     *sim = ivars->sim;
     float           field_boost = doc_boost * FType_Get_Boost(type) * length_norm;
     const uint8_t   field_boost_byte  = Sim_Encode_Norm(sim, field_boost);
+    const size_t    base_size = VTable_Get_Obj_Alloc_Size(RAWPOSTING);
     Token         **tokens;
     uint32_t        freq;
 
     Inversion_Reset(inversion);
     while ((tokens = Inversion_Next_Cluster(inversion, &freq)) != NULL) {
         TokenIVARS *const token_ivars = Token_IVARS(*tokens);
-        uint32_t raw_post_bytes = MAX_RAW_POSTING_LEN(token_ivars->len, freq);
+        uint32_t raw_post_bytes
+            = MAX_RAW_POSTING_LEN(base_size, token_ivars->len, freq);
         RawPosting *raw_posting
             = RawPost_new(MemPool_Grab(mem_pool, raw_post_bytes), doc_id,
                           freq, token_ivars->text, token_ivars->len);
@@ -179,7 +181,8 @@ ScorePost_read_raw(ScorePosting *self, InStream *instream,
     const uint32_t freq           = (doc_code & 1)
                                     ? 1
                                     : InStream_Read_C32(instream);
-    size_t raw_post_bytes         = MAX_RAW_POSTING_LEN(text_size, freq);
+    const size_t base_size        = VTable_Get_Obj_Alloc_Size(RAWPOSTING);
+    size_t raw_post_bytes         = MAX_RAW_POSTING_LEN(base_size, text_size, freq);
     void *const allocation        = MemPool_Grab(mem_pool, raw_post_bytes);
     RawPosting *const raw_posting
         = RawPost_new(allocation, doc_id, freq, text_buf, text_size);
@@ -236,8 +239,9 @@ ScorePostMatcher_init(ScorePostingMatcher *self, Similarity *sim,
 float
 ScorePostMatcher_score(ScorePostingMatcher* self) {
     ScorePostingMatcherIVARS *const ivars = ScorePostMatcher_IVARS(self);
-    ScorePosting *const posting = (ScorePosting*)ivars->posting;
-    const uint32_t freq = posting->freq;
+    ScorePostingIVARS *const posting_ivars
+        = ScorePost_IVARS((ScorePosting*)ivars->posting);
+    const uint32_t freq = posting_ivars->freq;
 
     // Calculate initial score based on frequency of term.
     float score = (freq < TERMMATCHER_SCORE_CACHE_SIZE)
@@ -245,7 +249,7 @@ ScorePostMatcher_score(ScorePostingMatcher* self) {
                   : Sim_TF(ivars->sim, (float)freq) * ivars->weight;
 
     // Factor in field-length normalization and doc/field/prox boost.
-    score *= posting->weight;
+    score *= posting_ivars->weight;
 
     return score;
 }


Mime
View raw message