You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by ma...@apache.org on 2013/07/01 18:47:23 UTC
[lucy-commits] [2/9] Migrate Lucy's index classes to IVARS.
http://git-wip-us.apache.org/repos/asf/lucy/blob/7c23ce21/core/Lucy/Index/PostingPool.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/PostingPool.c b/core/Lucy/Index/PostingPool.c
index f2c1146..1580a6a 100644
--- a/core/Lucy/Index/PostingPool.c
+++ b/core/Lucy/Index/PostingPool.c
@@ -76,61 +76,63 @@ PostPool_init(PostingPool *self, Schema *schema, Snapshot *snapshot,
OutStream *skip_out) {
// Init.
SortEx_init((SortExternal*)self, sizeof(Obj*));
- self->doc_base = 0;
- self->last_doc_id = 0;
- self->doc_map = NULL;
- self->post_count = 0;
- self->lexicon = NULL;
- self->plist = NULL;
- self->lex_temp_in = NULL;
- self->post_temp_in = NULL;
- self->lex_start = INT64_MAX;
- self->post_start = INT64_MAX;
- self->lex_end = 0;
- self->post_end = 0;
- self->skip_stepper = SkipStepper_new();
+ PostingPoolIVARS *const ivars = PostPool_IVARS(self);
+ ivars->doc_base = 0;
+ ivars->last_doc_id = 0;
+ ivars->doc_map = NULL;
+ ivars->post_count = 0;
+ ivars->lexicon = NULL;
+ ivars->plist = NULL;
+ ivars->lex_temp_in = NULL;
+ ivars->post_temp_in = NULL;
+ ivars->lex_start = INT64_MAX;
+ ivars->post_start = INT64_MAX;
+ ivars->lex_end = 0;
+ ivars->post_end = 0;
+ ivars->skip_stepper = SkipStepper_new();
// Assign.
- self->schema = (Schema*)INCREF(schema);
- self->snapshot = (Snapshot*)INCREF(snapshot);
- self->segment = (Segment*)INCREF(segment);
- self->polyreader = (PolyReader*)INCREF(polyreader);
- self->lex_writer = (LexiconWriter*)INCREF(lex_writer);
- self->mem_pool = (MemoryPool*)INCREF(mem_pool);
- self->field = CB_Clone(field);
- self->lex_temp_out = (OutStream*)INCREF(lex_temp_out);
- self->post_temp_out = (OutStream*)INCREF(post_temp_out);
- self->skip_out = (OutStream*)INCREF(skip_out);
+ ivars->schema = (Schema*)INCREF(schema);
+ ivars->snapshot = (Snapshot*)INCREF(snapshot);
+ ivars->segment = (Segment*)INCREF(segment);
+ ivars->polyreader = (PolyReader*)INCREF(polyreader);
+ ivars->lex_writer = (LexiconWriter*)INCREF(lex_writer);
+ ivars->mem_pool = (MemoryPool*)INCREF(mem_pool);
+ ivars->field = CB_Clone(field);
+ ivars->lex_temp_out = (OutStream*)INCREF(lex_temp_out);
+ ivars->post_temp_out = (OutStream*)INCREF(post_temp_out);
+ ivars->skip_out = (OutStream*)INCREF(skip_out);
// Derive.
Similarity *sim = Schema_Fetch_Sim(schema, field);
- self->posting = Sim_Make_Posting(sim);
- self->type = (FieldType*)INCREF(Schema_Fetch_Type(schema, field));
- self->field_num = Seg_Field_Num(segment, field);
+ ivars->posting = Sim_Make_Posting(sim);
+ ivars->type = (FieldType*)INCREF(Schema_Fetch_Type(schema, field));
+ ivars->field_num = Seg_Field_Num(segment, field);
return self;
}
void
PostPool_destroy(PostingPool *self) {
- DECREF(self->schema);
- DECREF(self->snapshot);
- DECREF(self->segment);
- DECREF(self->polyreader);
- DECREF(self->lex_writer);
- DECREF(self->mem_pool);
- DECREF(self->field);
- DECREF(self->doc_map);
- DECREF(self->lexicon);
- DECREF(self->plist);
- DECREF(self->lex_temp_out);
- DECREF(self->post_temp_out);
- DECREF(self->skip_out);
- DECREF(self->lex_temp_in);
- DECREF(self->post_temp_in);
- DECREF(self->posting);
- DECREF(self->skip_stepper);
- DECREF(self->type);
+ PostingPoolIVARS *const ivars = PostPool_IVARS(self);
+ DECREF(ivars->schema);
+ DECREF(ivars->snapshot);
+ DECREF(ivars->segment);
+ DECREF(ivars->polyreader);
+ DECREF(ivars->lex_writer);
+ DECREF(ivars->mem_pool);
+ DECREF(ivars->field);
+ DECREF(ivars->doc_map);
+ DECREF(ivars->lexicon);
+ DECREF(ivars->plist);
+ DECREF(ivars->lex_temp_out);
+ DECREF(ivars->post_temp_out);
+ DECREF(ivars->skip_out);
+ DECREF(ivars->lex_temp_in);
+ DECREF(ivars->post_temp_in);
+ DECREF(ivars->posting);
+ DECREF(ivars->skip_stepper);
+ DECREF(ivars->type);
SUPER_DESTROY(self, POSTINGPOOL);
}
@@ -159,27 +161,28 @@ PostPool_compare(PostingPool *self, void *va, void *vb) {
MemoryPool*
PostPool_get_mem_pool(PostingPool *self) {
- return self->mem_pool;
+ return PostPool_IVARS(self)->mem_pool;
}
void
PostPool_flip(PostingPool *self) {
- uint32_t num_runs = VA_Get_Size(self->runs);
+ PostingPoolIVARS *const ivars = PostPool_IVARS(self);
+ uint32_t num_runs = VA_Get_Size(ivars->runs);
uint32_t sub_thresh = num_runs > 0
- ? self->mem_thresh / num_runs
- : self->mem_thresh;
+ ? ivars->mem_thresh / num_runs
+ : ivars->mem_thresh;
if (num_runs) {
- Folder *folder = PolyReader_Get_Folder(self->polyreader);
- CharBuf *seg_name = Seg_Get_Name(self->segment);
+ Folder *folder = PolyReader_Get_Folder(ivars->polyreader);
+ CharBuf *seg_name = Seg_Get_Name(ivars->segment);
CharBuf *lex_temp_path = CB_newf("%o/lextemp", seg_name);
CharBuf *post_temp_path = CB_newf("%o/ptemp", seg_name);
- self->lex_temp_in = Folder_Open_In(folder, lex_temp_path);
- if (!self->lex_temp_in) {
+ ivars->lex_temp_in = Folder_Open_In(folder, lex_temp_path);
+ if (!ivars->lex_temp_in) {
RETHROW(INCREF(Err_get_error()));
}
- self->post_temp_in = Folder_Open_In(folder, post_temp_path);
- if (!self->post_temp_in) {
+ ivars->post_temp_in = Folder_Open_In(folder, post_temp_path);
+ if (!ivars->post_temp_in) {
RETHROW(INCREF(Err_get_error()));
}
DECREF(lex_temp_path);
@@ -187,44 +190,45 @@ PostPool_flip(PostingPool *self) {
}
PostPool_Sort_Cache(self);
- if (num_runs && (self->cache_max - self->cache_tick) > 0) {
+ if (num_runs && (ivars->cache_max - ivars->cache_tick) > 0) {
uint32_t num_items = PostPool_Cache_Count(self);
// Cheap imitation of flush. FIXME.
PostingPool *run
- = PostPool_new(self->schema, self->snapshot, self->segment,
- self->polyreader, self->field, self->lex_writer,
- self->mem_pool, self->lex_temp_out,
- self->post_temp_out, self->skip_out);
+ = PostPool_new(ivars->schema, ivars->snapshot, ivars->segment,
+ ivars->polyreader, ivars->field, ivars->lex_writer,
+ ivars->mem_pool, ivars->lex_temp_out,
+ ivars->post_temp_out, ivars->skip_out);
PostPool_Grow_Cache(run, num_items);
- memcpy(run->cache, ((Obj**)self->cache) + self->cache_tick,
+ memcpy(run->cache, ((Obj**)ivars->cache) + ivars->cache_tick,
num_items * sizeof(Obj*));
run->cache_max = num_items;
PostPool_Add_Run(self, (SortExternal*)run);
- self->cache_tick = 0;
- self->cache_max = 0;
+ ivars->cache_tick = 0;
+ ivars->cache_max = 0;
}
// Assign.
for (uint32_t i = 0; i < num_runs; i++) {
- PostingPool *run = (PostingPool*)VA_Fetch(self->runs, i);
+ PostingPool *run = (PostingPool*)VA_Fetch(ivars->runs, i);
if (run != NULL) {
PostPool_Set_Mem_Thresh(run, sub_thresh);
if (!run->lexicon) {
- S_fresh_flip(run, self->lex_temp_in, self->post_temp_in);
+ S_fresh_flip(run, ivars->lex_temp_in, ivars->post_temp_in);
}
}
}
- self->flipped = true;
+ ivars->flipped = true;
}
void
PostPool_add_segment(PostingPool *self, SegReader *reader, I32Array *doc_map,
int32_t doc_base) {
+ PostingPoolIVARS *const ivars = PostPool_IVARS(self);
LexiconReader *lex_reader = (LexiconReader*)SegReader_Fetch(
reader, VTable_Get_Name(LEXICONREADER));
Lexicon *lexicon = lex_reader
- ? LexReader_Lexicon(lex_reader, self->field, NULL)
+ ? LexReader_Lexicon(lex_reader, ivars->field, NULL)
: NULL;
if (lexicon) {
@@ -232,17 +236,17 @@ PostPool_add_segment(PostingPool *self, SegReader *reader, I32Array *doc_map,
= (PostingListReader*)SegReader_Fetch(
reader, VTable_Get_Name(POSTINGLISTREADER));
PostingList *plist = plist_reader
- ? PListReader_Posting_List(plist_reader, self->field, NULL)
+ ? PListReader_Posting_List(plist_reader, ivars->field, NULL)
: NULL;
if (!plist) {
THROW(ERR, "Got a Lexicon but no PostingList for '%o' in '%o'",
- self->field, SegReader_Get_Seg_Name(reader));
+ ivars->field, SegReader_Get_Seg_Name(reader));
}
PostingPool *run
- = PostPool_new(self->schema, self->snapshot, self->segment,
- self->polyreader, self->field, self->lex_writer,
- self->mem_pool, self->lex_temp_out,
- self->post_temp_out, self->skip_out);
+ = PostPool_new(ivars->schema, ivars->snapshot, ivars->segment,
+ ivars->polyreader, ivars->field, ivars->lex_writer,
+ ivars->mem_pool, ivars->lex_temp_out,
+ ivars->post_temp_out, ivars->skip_out);
run->lexicon = lexicon;
run->plist = plist;
run->doc_base = doc_base;
@@ -253,28 +257,29 @@ PostPool_add_segment(PostingPool *self, SegReader *reader, I32Array *doc_map,
void
PostPool_shrink(PostingPool *self) {
- if (self->cache_max - self->cache_tick > 0) {
+ PostingPoolIVARS *const ivars = PostPool_IVARS(self);
+ if (ivars->cache_max - ivars->cache_tick > 0) {
size_t cache_count = PostPool_Cache_Count(self);
size_t size = cache_count * sizeof(Obj*);
- if (self->cache_tick > 0) {
- Obj **start = ((Obj**)self->cache) + self->cache_tick;
- memmove(self->cache, start, size);
+ if (ivars->cache_tick > 0) {
+ Obj **start = ((Obj**)ivars->cache) + ivars->cache_tick;
+ memmove(ivars->cache, start, size);
}
- self->cache = (uint8_t*)REALLOCATE(self->cache, size);
- self->cache_tick = 0;
- self->cache_max = cache_count;
- self->cache_cap = cache_count;
+ ivars->cache = (uint8_t*)REALLOCATE(ivars->cache, size);
+ ivars->cache_tick = 0;
+ ivars->cache_max = cache_count;
+ ivars->cache_cap = cache_count;
}
else {
- FREEMEM(self->cache);
- self->cache = NULL;
- self->cache_tick = 0;
- self->cache_max = 0;
- self->cache_cap = 0;
+ FREEMEM(ivars->cache);
+ ivars->cache = NULL;
+ ivars->cache_tick = 0;
+ ivars->cache_max = 0;
+ ivars->cache_cap = 0;
}
- self->scratch_cap = 0;
- FREEMEM(self->scratch);
- self->scratch = NULL;
+ ivars->scratch_cap = 0;
+ FREEMEM(ivars->scratch);
+ ivars->scratch = NULL;
// It's not necessary to iterate over the runs, because they don't have
// any cache costs until Refill() gets called.
@@ -282,36 +287,38 @@ PostPool_shrink(PostingPool *self) {
void
PostPool_flush(PostingPool *self) {
+ PostingPoolIVARS *const ivars = PostPool_IVARS(self);
+
// Don't add a run unless we have data to put in it.
if (PostPool_Cache_Count(self) == 0) { return; }
PostingPool *run
- = PostPool_new(self->schema, self->snapshot, self->segment,
- self->polyreader, self->field, self->lex_writer,
- self->mem_pool, self->lex_temp_out,
- self->post_temp_out, self->skip_out);
+ = PostPool_new(ivars->schema, ivars->snapshot, ivars->segment,
+ ivars->polyreader, ivars->field, ivars->lex_writer,
+ ivars->mem_pool, ivars->lex_temp_out,
+ ivars->post_temp_out, ivars->skip_out);
PostingWriter *post_writer
- = (PostingWriter*)RawPostWriter_new(self->schema, self->snapshot,
- self->segment, self->polyreader,
- self->post_temp_out);
+ = (PostingWriter*)RawPostWriter_new(ivars->schema, ivars->snapshot,
+ ivars->segment, ivars->polyreader,
+ ivars->post_temp_out);
// Borrow the cache.
- run->cache = self->cache;
- run->cache_tick = self->cache_tick;
- run->cache_max = self->cache_max;
- run->cache_cap = self->cache_cap;
+ run->cache = ivars->cache;
+ run->cache_tick = ivars->cache_tick;
+ run->cache_max = ivars->cache_max;
+ run->cache_cap = ivars->cache_cap;
// Write to temp files.
- LexWriter_Enter_Temp_Mode(self->lex_writer, self->field,
- self->lex_temp_out);
- run->lex_start = OutStream_Tell(self->lex_temp_out);
- run->post_start = OutStream_Tell(self->post_temp_out);
+ LexWriter_Enter_Temp_Mode(ivars->lex_writer, ivars->field,
+ ivars->lex_temp_out);
+ run->lex_start = OutStream_Tell(ivars->lex_temp_out);
+ run->post_start = OutStream_Tell(ivars->post_temp_out);
PostPool_Sort_Cache(self);
S_write_terms_and_postings(run, post_writer, NULL);
- run->lex_end = OutStream_Tell(self->lex_temp_out);
- run->post_end = OutStream_Tell(self->post_temp_out);
- LexWriter_Leave_Temp_Mode(self->lex_writer);
+ run->lex_end = OutStream_Tell(ivars->lex_temp_out);
+ run->post_end = OutStream_Tell(ivars->post_temp_out);
+ LexWriter_Leave_Temp_Mode(ivars->lex_writer);
// Return the cache and empty it.
run->cache = NULL;
@@ -328,32 +335,39 @@ PostPool_flush(PostingPool *self) {
void
PostPool_finish(PostingPool *self) {
+ PostingPoolIVARS *const ivars = PostPool_IVARS(self);
+
// Bail if there's no data.
if (!PostPool_Peek(self)) { return; }
- Similarity *sim = Schema_Fetch_Sim(self->schema, self->field);
+ Similarity *sim = Schema_Fetch_Sim(ivars->schema, ivars->field);
PostingWriter *post_writer
- = Sim_Make_Posting_Writer(sim, self->schema, self->snapshot,
- self->segment, self->polyreader,
- self->field_num);
- LexWriter_Start_Field(self->lex_writer, self->field_num);
- S_write_terms_and_postings(self, post_writer, self->skip_out);
- LexWriter_Finish_Field(self->lex_writer, self->field_num);
+ = Sim_Make_Posting_Writer(sim, ivars->schema, ivars->snapshot,
+ ivars->segment, ivars->polyreader,
+ ivars->field_num);
+ LexWriter_Start_Field(ivars->lex_writer, ivars->field_num);
+ S_write_terms_and_postings(self, post_writer, ivars->skip_out);
+ LexWriter_Finish_Field(ivars->lex_writer, ivars->field_num);
DECREF(post_writer);
}
static void
S_write_terms_and_postings(PostingPool *self, PostingWriter *post_writer,
OutStream *skip_stream) {
- TermInfo *const tinfo = TInfo_new(0);
- TermInfo *const skip_tinfo = TInfo_new(0);
- CharBuf *const last_term_text = CB_new(0);
- LexiconWriter *const lex_writer = self->lex_writer;
- SkipStepper *const skip_stepper = self->skip_stepper;
- int32_t last_skip_doc = 0;
- int64_t last_skip_filepos = 0;
+ PostingPoolIVARS *const ivars = PostPool_IVARS(self);
+ TermInfo *const tinfo = TInfo_new(0);
+ TermInfo *const skip_tinfo = TInfo_new(0);
+ TermInfoIVARS *const tinfo_ivars = TInfo_IVARS(tinfo);
+ TermInfoIVARS *const skip_tinfo_ivars = TInfo_IVARS(skip_tinfo);
+ CharBuf *const last_term_text = CB_new(0);
+ LexiconWriter *const lex_writer = ivars->lex_writer;
+ SkipStepper *const skip_stepper = ivars->skip_stepper;
+ SkipStepperIVARS *const skip_stepper_ivars
+ = SkipStepper_IVARS(skip_stepper);
+ int32_t last_skip_doc = 0;
+ int64_t last_skip_filepos = 0;
const int32_t skip_interval
- = Arch_Skip_Interval(Schema_Get_Architecture(self->schema));
+ = Arch_Skip_Interval(Schema_Get_Architecture(ivars->schema));
// Prime heldover variables.
RawPosting *posting = (RawPosting*)CERTIFY(
@@ -400,10 +414,10 @@ S_write_terms_and_postings(PostingPool *self, PostingWriter *post_writer,
PostWriter_Start_Term(post_writer, tinfo);
// Init skip data in preparation for the next term.
- skip_stepper->doc_id = 0;
- skip_stepper->filepos = tinfo->post_filepos;
+ skip_stepper_ivars->doc_id = 0;
+ skip_stepper_ivars->filepos = tinfo_ivars->post_filepos;
last_skip_doc = 0;
- last_skip_filepos = tinfo->post_filepos;
+ last_skip_filepos = tinfo_ivars->post_filepos;
// Remember the term_text so we can write string diffs.
CB_Mimic_Str(last_term_text, posting->blob,
@@ -419,24 +433,24 @@ S_write_terms_and_postings(PostingPool *self, PostingWriter *post_writer,
PostWriter_Write_Posting(post_writer, posting);
// Doc freq lags by one iter.
- tinfo->doc_freq++;
+ tinfo_ivars->doc_freq++;
// Write skip data.
if (skip_stream != NULL
&& same_text_as_last
- && tinfo->doc_freq % skip_interval == 0
- && tinfo->doc_freq != 0
+ && tinfo_ivars->doc_freq % skip_interval == 0
+ && tinfo_ivars->doc_freq != 0
) {
// If first skip group, save skip stream pos for term info.
- if (tinfo->doc_freq == skip_interval) {
- tinfo->skip_filepos = OutStream_Tell(skip_stream);
+ if (tinfo_ivars->doc_freq == skip_interval) {
+ tinfo_ivars->skip_filepos = OutStream_Tell(skip_stream);
}
// Write deltas.
- last_skip_doc = skip_stepper->doc_id;
- last_skip_filepos = skip_stepper->filepos;
- skip_stepper->doc_id = posting->doc_id;
+ last_skip_doc = skip_stepper_ivars->doc_id;
+ last_skip_filepos = skip_stepper_ivars->filepos;
+ skip_stepper_ivars->doc_id = posting->doc_id;
PostWriter_Update_Skip_Info(post_writer, skip_tinfo);
- skip_stepper->filepos = skip_tinfo->post_filepos;
+ skip_stepper_ivars->filepos = skip_tinfo_ivars->post_filepos;
SkipStepper_Write_Record(skip_stepper, skip_stream,
last_skip_doc, last_skip_filepos);
}
@@ -458,45 +472,47 @@ S_write_terms_and_postings(PostingPool *self, PostingWriter *post_writer,
uint32_t
PostPool_refill(PostingPool *self) {
- Lexicon *const lexicon = self->lexicon;
- PostingList *const plist = self->plist;
- I32Array *const doc_map = self->doc_map;
- const uint32_t mem_thresh = self->mem_thresh;
- const int32_t doc_base = self->doc_base;
+ PostingPoolIVARS *const ivars = PostPool_IVARS(self);
+ Lexicon *const lexicon = ivars->lexicon;
+ PostingList *const plist = ivars->plist;
+ I32Array *const doc_map = ivars->doc_map;
+ const uint32_t mem_thresh = ivars->mem_thresh;
+ const int32_t doc_base = ivars->doc_base;
uint32_t num_elems = 0; // number of items recovered
- MemoryPool *mem_pool;
CharBuf *term_text = NULL;
- if (self->lexicon == NULL) { return 0; }
+ if (ivars->lexicon == NULL) { return 0; }
else { term_text = (CharBuf*)Lex_Get_Term(lexicon); }
// Make sure cache is empty.
- if (self->cache_max - self->cache_tick > 0) {
+ if (ivars->cache_max - ivars->cache_tick > 0) {
THROW(ERR, "Refill called but cache contains %u32 items",
- self->cache_max - self->cache_tick);
+ ivars->cache_max - ivars->cache_tick);
}
- self->cache_max = 0;
- self->cache_tick = 0;
+ ivars->cache_max = 0;
+ ivars->cache_tick = 0;
// Ditch old MemoryPool and get another.
- DECREF(self->mem_pool);
- self->mem_pool = MemPool_new(0);
- mem_pool = self->mem_pool;
+ DECREF(ivars->mem_pool);
+ ivars->mem_pool = MemPool_new(0);
+ MemoryPool *const mem_pool = ivars->mem_pool;
+ MemoryPoolIVARS *const mem_pool_ivars = MemPool_IVARS(mem_pool);
+
while (1) {
RawPosting *raw_posting;
- if (self->post_count == 0) {
+ if (ivars->post_count == 0) {
// Read a term.
if (Lex_Next(lexicon)) {
- self->post_count = Lex_Doc_Freq(lexicon);
+ ivars->post_count = Lex_Doc_Freq(lexicon);
term_text = (CharBuf*)Lex_Get_Term(lexicon);
if (term_text && !Obj_Is_A((Obj*)term_text, CHARBUF)) {
THROW(ERR, "Only CharBuf terms are supported for now");
}
Posting *posting = PList_Get_Posting(plist);
Post_Set_Doc_ID(posting, doc_base);
- self->last_doc_id = doc_base;
+ ivars->last_doc_id = doc_base;
}
// Bail if we've read everything in this run.
else {
@@ -505,15 +521,15 @@ PostPool_refill(PostingPool *self) {
}
// Bail if we've hit the ceiling for this run's cache.
- if (mem_pool->consumed >= mem_thresh && num_elems > 0) {
+ if (mem_pool_ivars->consumed >= mem_thresh && num_elems > 0) {
break;
}
// Read a posting from the input stream.
- raw_posting = PList_Read_Raw(plist, self->last_doc_id, term_text,
+ raw_posting = PList_Read_Raw(plist, ivars->last_doc_id, term_text,
mem_pool);
- self->last_doc_id = raw_posting->doc_id;
- self->post_count--;
+ ivars->last_doc_id = raw_posting->doc_id;
+ ivars->post_count--;
// Skip deletions.
if (doc_map != NULL) {
@@ -526,18 +542,18 @@ PostPool_refill(PostingPool *self) {
}
// Add to the run's cache.
- if (num_elems >= self->cache_cap) {
+ if (num_elems >= ivars->cache_cap) {
size_t new_cap = Memory_oversize(num_elems + 1, sizeof(Obj*));
PostPool_Grow_Cache(self, new_cap);
}
- Obj **cache = (Obj**)self->cache;
+ Obj **cache = (Obj**)ivars->cache;
cache[num_elems] = (Obj*)raw_posting;
num_elems++;
}
// Reset the cache array position and length; remember file pos.
- self->cache_max = num_elems;
- self->cache_tick = 0;
+ ivars->cache_max = num_elems;
+ ivars->cache_tick = 0;
return num_elems;
}
@@ -545,46 +561,48 @@ PostPool_refill(PostingPool *self) {
void
PostPool_add_inversion(PostingPool *self, Inversion *inversion, int32_t doc_id,
float doc_boost, float length_norm) {
- Post_Add_Inversion_To_Pool(self->posting, self, inversion, self->type,
+ PostingPoolIVARS *const ivars = PostPool_IVARS(self);
+ Post_Add_Inversion_To_Pool(ivars->posting, self, inversion, ivars->type,
doc_id, doc_boost, length_norm);
}
static void
S_fresh_flip(PostingPool *self, InStream *lex_temp_in,
InStream *post_temp_in) {
- if (self->flipped) { THROW(ERR, "Can't Flip twice"); }
- self->flipped = true;
+ PostingPoolIVARS *const ivars = PostPool_IVARS(self);
+ if (ivars->flipped) { THROW(ERR, "Can't Flip twice"); }
+ ivars->flipped = true;
// Sort RawPostings in cache, if any.
PostPool_Sort_Cache(self);
// Bail if never flushed.
- if (self->lex_end == 0) { return; }
+ if (ivars->lex_end == 0) { return; }
// Get a Lexicon.
CharBuf *lex_alias = CB_newf("%o-%i64-to-%i64",
InStream_Get_Filename(lex_temp_in),
- self->lex_start, self->lex_end);
+ ivars->lex_start, ivars->lex_end);
InStream *lex_temp_in_dupe = InStream_Reopen(
- lex_temp_in, lex_alias, self->lex_start,
- self->lex_end - self->lex_start);
- self->lexicon = (Lexicon*)RawLex_new(
- self->schema, self->field, lex_temp_in_dupe, 0,
- self->lex_end - self->lex_start);
+ lex_temp_in, lex_alias, ivars->lex_start,
+ ivars->lex_end - ivars->lex_start);
+ ivars->lexicon = (Lexicon*)RawLex_new(
+ ivars->schema, ivars->field, lex_temp_in_dupe, 0,
+ ivars->lex_end - ivars->lex_start);
DECREF(lex_alias);
DECREF(lex_temp_in_dupe);
// Get a PostingList.
CharBuf *post_alias
= CB_newf("%o-%i64-to-%i64", InStream_Get_Filename(post_temp_in),
- self->post_start, self->post_end);
+ ivars->post_start, ivars->post_end);
InStream *post_temp_in_dupe
- = InStream_Reopen(post_temp_in, post_alias, self->post_start,
- self->post_end - self->post_start);
- self->plist
- = (PostingList*)RawPList_new(self->schema, self->field,
+ = InStream_Reopen(post_temp_in, post_alias, ivars->post_start,
+ ivars->post_end - ivars->post_start);
+ ivars->plist
+ = (PostingList*)RawPList_new(ivars->schema, ivars->field,
post_temp_in_dupe, 0,
- self->post_end - self->post_start);
+ ivars->post_end - ivars->post_start);
DECREF(post_alias);
DECREF(post_temp_in_dupe);
}
http://git-wip-us.apache.org/repos/asf/lucy/blob/7c23ce21/core/Lucy/Index/RawLexicon.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/RawLexicon.c b/core/Lucy/Index/RawLexicon.c
index eef6eac..49e4e20 100644
--- a/core/Lucy/Index/RawLexicon.c
+++ b/core/Lucy/Index/RawLexicon.c
@@ -37,47 +37,52 @@ RawLex_init(RawLexicon *self, Schema *schema, const CharBuf *field,
InStream *instream, int64_t start, int64_t end) {
FieldType *type = Schema_Fetch_Type(schema, field);
Lex_init((Lexicon*)self, field);
+ RawLexiconIVARS *const ivars = RawLex_IVARS(self);
// Assign
- self->start = start;
- self->end = end;
- self->len = end - start;
- self->instream = (InStream*)INCREF(instream);
+ ivars->start = start;
+ ivars->end = end;
+ ivars->len = end - start;
+ ivars->instream = (InStream*)INCREF(instream);
// Get ready to begin.
- InStream_Seek(self->instream, self->start);
+ InStream_Seek(ivars->instream, ivars->start);
// Get steppers.
- self->term_stepper = FType_Make_Term_Stepper(type);
- self->tinfo_stepper = (TermStepper*)MatchTInfoStepper_new(schema);
+ ivars->term_stepper = FType_Make_Term_Stepper(type);
+ ivars->tinfo_stepper = (TermStepper*)MatchTInfoStepper_new(schema);
return self;
}
void
RawLex_destroy(RawLexicon *self) {
- DECREF(self->instream);
- DECREF(self->term_stepper);
- DECREF(self->tinfo_stepper);
+ RawLexiconIVARS *const ivars = RawLex_IVARS(self);
+ DECREF(ivars->instream);
+ DECREF(ivars->term_stepper);
+ DECREF(ivars->tinfo_stepper);
SUPER_DESTROY(self, RAWLEXICON);
}
bool
RawLex_next(RawLexicon *self) {
- if (InStream_Tell(self->instream) >= self->len) { return false; }
- TermStepper_Read_Delta(self->term_stepper, self->instream);
- TermStepper_Read_Delta(self->tinfo_stepper, self->instream);
+ RawLexiconIVARS *const ivars = RawLex_IVARS(self);
+ if (InStream_Tell(ivars->instream) >= ivars->len) { return false; }
+ TermStepper_Read_Delta(ivars->term_stepper, ivars->instream);
+ TermStepper_Read_Delta(ivars->tinfo_stepper, ivars->instream);
return true;
}
Obj*
RawLex_get_term(RawLexicon *self) {
- return TermStepper_Get_Value(self->term_stepper);
+ RawLexiconIVARS *const ivars = RawLex_IVARS(self);
+ return TermStepper_Get_Value(ivars->term_stepper);
}
int32_t
RawLex_doc_freq(RawLexicon *self) {
- TermInfo *tinfo = (TermInfo*)TermStepper_Get_Value(self->tinfo_stepper);
+ RawLexiconIVARS *const ivars = RawLex_IVARS(self);
+ TermInfo *tinfo = (TermInfo*)TermStepper_Get_Value(ivars->tinfo_stepper);
return tinfo ? TInfo_Get_Doc_Freq(tinfo) : 0;
}
http://git-wip-us.apache.org/repos/asf/lucy/blob/7c23ce21/core/Lucy/Index/RawPostingList.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/RawPostingList.c b/core/Lucy/Index/RawPostingList.c
index a22a015..9d5dd0a 100644
--- a/core/Lucy/Index/RawPostingList.c
+++ b/core/Lucy/Index/RawPostingList.c
@@ -36,32 +36,35 @@ RawPostingList*
RawPList_init(RawPostingList *self, Schema *schema, const CharBuf *field,
InStream *instream, int64_t start, int64_t end) {
PList_init((PostingList*)self);
- self->start = start;
- self->end = end;
- self->len = end - start;
- self->instream = (InStream*)INCREF(instream);
- Similarity *sim = Schema_Fetch_Sim(schema, field);
- self->posting = Sim_Make_Posting(sim);
- InStream_Seek(self->instream, self->start);
+ RawPostingListIVARS *const ivars = RawPList_IVARS(self);
+ ivars->start = start;
+ ivars->end = end;
+ ivars->len = end - start;
+ ivars->instream = (InStream*)INCREF(instream);
+ Similarity *sim = Schema_Fetch_Sim(schema, field);
+ ivars->posting = Sim_Make_Posting(sim);
+ InStream_Seek(ivars->instream, ivars->start);
return self;
}
void
RawPList_destroy(RawPostingList *self) {
- DECREF(self->instream);
- DECREF(self->posting);
+ RawPostingListIVARS *const ivars = RawPList_IVARS(self);
+ DECREF(ivars->instream);
+ DECREF(ivars->posting);
SUPER_DESTROY(self, RAWPOSTINGLIST);
}
Posting*
RawPList_get_posting(RawPostingList *self) {
- return self->posting;
+ return RawPList_IVARS(self)->posting;
}
RawPosting*
RawPList_read_raw(RawPostingList *self, int32_t last_doc_id, CharBuf *term_text,
MemoryPool *mem_pool) {
- return Post_Read_Raw(self->posting, self->instream,
+ RawPostingListIVARS *const ivars = RawPList_IVARS(self);
+ return Post_Read_Raw(ivars->posting, ivars->instream,
last_doc_id, term_text, mem_pool);
}
http://git-wip-us.apache.org/repos/asf/lucy/blob/7c23ce21/core/Lucy/Index/SegLexicon.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/SegLexicon.c b/core/Lucy/Index/SegLexicon.c
index 06704f2..3a6523f 100644
--- a/core/Lucy/Index/SegLexicon.c
+++ b/core/Lucy/Index/SegLexicon.c
@@ -58,6 +58,7 @@ SegLex_init(SegLexicon *self, Schema *schema, Folder *folder,
CharBuf *filename = CB_newf("%o/lexicon-%i32.dat", seg_name, field_num);
Lex_init((Lexicon*)self, field);
+ SegLexiconIVARS *const ivars = SegLex_IVARS(self);
// Check format.
if (!format) { THROW(ERR, "Missing 'format'"); }
@@ -72,19 +73,19 @@ SegLex_init(SegLexicon *self, Schema *schema, Folder *folder,
if (!counts) { THROW(ERR, "Failed to extract 'counts'"); }
else {
Obj *count = CERTIFY(Hash_Fetch(counts, (Obj*)field), OBJ);
- self->size = (int32_t)Obj_To_I64(count);
+ ivars->size = (int32_t)Obj_To_I64(count);
}
// Assign.
- self->segment = (Segment*)INCREF(segment);
+ ivars->segment = (Segment*)INCREF(segment);
// Derive.
- self->lex_index = LexIndex_new(schema, folder, segment, field);
- self->field_num = field_num;
- self->index_interval = Arch_Index_Interval(arch);
- self->skip_interval = Arch_Skip_Interval(arch);
- self->instream = Folder_Open_In(folder, filename);
- if (!self->instream) {
+ ivars->lex_index = LexIndex_new(schema, folder, segment, field);
+ ivars->field_num = field_num;
+ ivars->index_interval = Arch_Index_Interval(arch);
+ ivars->skip_interval = Arch_Skip_Interval(arch);
+ ivars->instream = Folder_Open_In(folder, filename);
+ if (!ivars->instream) {
Err *error = (Err*)INCREF(Err_get_error());
DECREF(filename);
DECREF(self);
@@ -93,28 +94,30 @@ SegLex_init(SegLexicon *self, Schema *schema, Folder *folder,
DECREF(filename);
// Define the term_num as "not yet started".
- self->term_num = -1;
+ ivars->term_num = -1;
// Get steppers.
- self->term_stepper = FType_Make_Term_Stepper(type);
- self->tinfo_stepper = (TermStepper*)MatchTInfoStepper_new(schema);
+ ivars->term_stepper = FType_Make_Term_Stepper(type);
+ ivars->tinfo_stepper = (TermStepper*)MatchTInfoStepper_new(schema);
return self;
}
void
SegLex_destroy(SegLexicon *self) {
- DECREF(self->segment);
- DECREF(self->term_stepper);
- DECREF(self->tinfo_stepper);
- DECREF(self->lex_index);
- DECREF(self->instream);
+ SegLexiconIVARS *const ivars = SegLex_IVARS(self);
+ DECREF(ivars->segment);
+ DECREF(ivars->term_stepper);
+ DECREF(ivars->tinfo_stepper);
+ DECREF(ivars->lex_index);
+ DECREF(ivars->instream);
SUPER_DESTROY(self, SEGLEXICON);
}
void
SegLex_seek(SegLexicon *self, Obj *target) {
- LexIndex *const lex_index = self->lex_index;
+ SegLexiconIVARS *const ivars = SegLex_IVARS(self);
+ LexIndex *const lex_index = ivars->lex_index;
// Reset upon null term.
if (target == NULL) {
@@ -126,13 +129,13 @@ SegLex_seek(SegLexicon *self, Obj *target) {
LexIndex_Seek(lex_index, target);
TermInfo *target_tinfo = LexIndex_Get_Term_Info(lex_index);
TermInfo *my_tinfo
- = (TermInfo*)TermStepper_Get_Value(self->tinfo_stepper);
+ = (TermInfo*)TermStepper_Get_Value(ivars->tinfo_stepper);
Obj *lex_index_term = Obj_Clone(LexIndex_Get_Term(lex_index));
TInfo_Mimic(my_tinfo, (Obj*)target_tinfo);
- TermStepper_Set_Value(self->term_stepper, lex_index_term);
+ TermStepper_Set_Value(ivars->term_stepper, lex_index_term);
DECREF(lex_index_term);
- InStream_Seek(self->instream, TInfo_Get_Lex_FilePos(target_tinfo));
- self->term_num = LexIndex_Get_Term_Num(lex_index);
+ InStream_Seek(ivars->instream, TInfo_Get_Lex_FilePos(target_tinfo));
+ ivars->term_num = LexIndex_Get_Term_Num(lex_index);
// Scan to the precise location.
S_scan_to(self, target);
@@ -140,59 +143,67 @@ SegLex_seek(SegLexicon *self, Obj *target) {
void
SegLex_reset(SegLexicon* self) {
- self->term_num = -1;
- InStream_Seek(self->instream, 0);
- TermStepper_Reset(self->term_stepper);
- TermStepper_Reset(self->tinfo_stepper);
+ SegLexiconIVARS *const ivars = SegLex_IVARS(self);
+ ivars->term_num = -1;
+ InStream_Seek(ivars->instream, 0);
+ TermStepper_Reset(ivars->term_stepper);
+ TermStepper_Reset(ivars->tinfo_stepper);
}
int32_t
SegLex_get_field_num(SegLexicon *self) {
- return self->field_num;
+ return SegLex_IVARS(self)->field_num;
}
Obj*
SegLex_get_term(SegLexicon *self) {
- return TermStepper_Get_Value(self->term_stepper);
+ SegLexiconIVARS *const ivars = SegLex_IVARS(self);
+ return TermStepper_Get_Value(ivars->term_stepper);
}
int32_t
SegLex_doc_freq(SegLexicon *self) {
- TermInfo *tinfo = (TermInfo*)TermStepper_Get_Value(self->tinfo_stepper);
+ SegLexiconIVARS *const ivars = SegLex_IVARS(self);
+ TermInfo *tinfo = (TermInfo*)TermStepper_Get_Value(ivars->tinfo_stepper);
return tinfo ? TInfo_Get_Doc_Freq(tinfo) : 0;
}
TermInfo*
SegLex_get_term_info(SegLexicon *self) {
- return (TermInfo*)TermStepper_Get_Value(self->tinfo_stepper);
+ SegLexiconIVARS *const ivars = SegLex_IVARS(self);
+ return (TermInfo*)TermStepper_Get_Value(ivars->tinfo_stepper);
}
Segment*
SegLex_get_segment(SegLexicon *self) {
- return self->segment;
+ return SegLex_IVARS(self)->segment;
}
bool
SegLex_next(SegLexicon *self) {
+ SegLexiconIVARS *const ivars = SegLex_IVARS(self);
+
// If we've run out of terms, null out and return.
- if (++self->term_num >= self->size) {
- self->term_num = self->size; // don't keep growing
- TermStepper_Reset(self->term_stepper);
- TermStepper_Reset(self->tinfo_stepper);
+ if (++ivars->term_num >= ivars->size) {
+ ivars->term_num = ivars->size; // don't keep growing
+ TermStepper_Reset(ivars->term_stepper);
+ TermStepper_Reset(ivars->tinfo_stepper);
return false;
}
// Read next term/terminfo.
- TermStepper_Read_Delta(self->term_stepper, self->instream);
- TermStepper_Read_Delta(self->tinfo_stepper, self->instream);
+ TermStepper_Read_Delta(ivars->term_stepper, ivars->instream);
+ TermStepper_Read_Delta(ivars->tinfo_stepper, ivars->instream);
return true;
}
static void
S_scan_to(SegLexicon *self, Obj *target) {
+ SegLexiconIVARS *const ivars = SegLex_IVARS(self);
+
// (mildly evil encapsulation violation, since value can be null)
- Obj *current = TermStepper_Get_Value(self->term_stepper);
+ Obj *current = TermStepper_Get_Value(ivars->term_stepper);
if (!Obj_Is_A(target, Obj_Get_VTable(current))) {
THROW(ERR, "Target is a %o, and not comparable to a %o",
Obj_Get_Class_Name(target), Obj_Get_Class_Name(current));
@@ -201,7 +212,7 @@ S_scan_to(SegLexicon *self, Obj *target) {
// Keep looping until the term text is ge target.
do {
const int32_t comparison = Obj_Compare_To(current, target);
- if (comparison >= 0 && self->term_num != -1) { break; }
+ if (comparison >= 0 && ivars->term_num != -1) { break; }
} while (SegLex_Next(self));
}
http://git-wip-us.apache.org/repos/asf/lucy/blob/7c23ce21/core/Lucy/Index/SegPostingList.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/SegPostingList.c b/core/Lucy/Index/SegPostingList.c
index ae9122e..bebd52d 100644
--- a/core/Lucy/Index/SegPostingList.c
+++ b/core/Lucy/Index/SegPostingList.c
@@ -51,6 +51,7 @@ SegPList_new(PostingListReader *plist_reader, const CharBuf *field) {
SegPostingList*
SegPList_init(SegPostingList *self, PostingListReader *plist_reader,
const CharBuf *field) {
+ SegPostingListIVARS *const ivars = SegPList_IVARS(self);
Schema *const schema = PListReader_Get_Schema(plist_reader);
Folder *const folder = PListReader_Get_Folder(plist_reader);
Segment *const segment = PListReader_Get_Segment(plist_reader);
@@ -62,36 +63,36 @@ SegPList_init(SegPostingList *self, PostingListReader *plist_reader,
CharBuf *skip_file = CB_newf("%o/postings.skip", seg_name);
// Init.
- self->doc_freq = 0;
- self->count = 0;
+ ivars->doc_freq = 0;
+ ivars->count = 0;
// Init skipping vars.
- self->skip_stepper = SkipStepper_new();
- self->skip_count = 0;
- self->num_skips = 0;
+ ivars->skip_stepper = SkipStepper_new();
+ ivars->skip_count = 0;
+ ivars->num_skips = 0;
// Assign.
- self->plist_reader = (PostingListReader*)INCREF(plist_reader);
- self->field = CB_Clone(field);
- self->skip_interval = Arch_Skip_Interval(arch);
+ ivars->plist_reader = (PostingListReader*)INCREF(plist_reader);
+ ivars->field = CB_Clone(field);
+ ivars->skip_interval = Arch_Skip_Interval(arch);
// Derive.
- Similarity *sim = Schema_Fetch_Sim(schema, field);
- self->posting = Sim_Make_Posting(sim);
- self->field_num = field_num;
+ Similarity *sim = Schema_Fetch_Sim(schema, field);
+ ivars->posting = Sim_Make_Posting(sim);
+ ivars->field_num = field_num;
// Open both a main stream and a skip stream if the field exists.
if (Folder_Exists(folder, post_file)) {
- self->post_stream = Folder_Open_In(folder, post_file);
- if (!self->post_stream) {
+ ivars->post_stream = Folder_Open_In(folder, post_file);
+ if (!ivars->post_stream) {
Err *error = (Err*)INCREF(Err_get_error());
DECREF(post_file);
DECREF(skip_file);
DECREF(self);
RETHROW(error);
}
- self->skip_stream = Folder_Open_In(folder, skip_file);
- if (!self->skip_stream) {
+ ivars->skip_stream = Folder_Open_In(folder, skip_file);
+ if (!ivars->skip_stream) {
Err *error = (Err*)INCREF(Err_get_error());
DECREF(post_file);
DECREF(skip_file);
@@ -101,8 +102,8 @@ SegPList_init(SegPostingList *self, PostingListReader *plist_reader,
}
else {
// Empty, so don't bother with these.
- self->post_stream = NULL;
- self->skip_stream = NULL;
+ ivars->post_stream = NULL;
+ ivars->skip_stream = NULL;
}
DECREF(post_file);
DECREF(skip_file);
@@ -112,16 +113,17 @@ SegPList_init(SegPostingList *self, PostingListReader *plist_reader,
void
SegPList_destroy(SegPostingList *self) {
- DECREF(self->plist_reader);
- DECREF(self->posting);
- DECREF(self->skip_stepper);
- DECREF(self->field);
-
- if (self->post_stream != NULL) {
- InStream_Close(self->post_stream);
- InStream_Close(self->skip_stream);
- DECREF(self->post_stream);
- DECREF(self->skip_stream);
+ SegPostingListIVARS *const ivars = SegPList_IVARS(self);
+ DECREF(ivars->plist_reader);
+ DECREF(ivars->posting);
+ DECREF(ivars->skip_stepper);
+ DECREF(ivars->field);
+
+ if (ivars->post_stream != NULL) {
+ InStream_Close(ivars->post_stream);
+ InStream_Close(ivars->skip_stream);
+ DECREF(ivars->post_stream);
+ DECREF(ivars->skip_stream);
}
SUPER_DESTROY(self, SEGPOSTINGLIST);
@@ -129,56 +131,61 @@ SegPList_destroy(SegPostingList *self) {
Posting*
SegPList_get_posting(SegPostingList *self) {
- return self->posting;
+ return SegPList_IVARS(self)->posting;
}
uint32_t
SegPList_get_doc_freq(SegPostingList *self) {
- return self->doc_freq;
+ return SegPList_IVARS(self)->doc_freq;
}
int32_t
SegPList_get_doc_id(SegPostingList *self) {
- return self->posting->doc_id;
+ SegPostingListIVARS *const ivars = SegPList_IVARS(self);
+ return Post_IVARS(ivars->posting)->doc_id;
}
uint32_t
SegPList_get_count(SegPostingList *self) {
- return self->count;
+ return SegPList_IVARS(self)->count;
}
InStream*
SegPList_get_post_stream(SegPostingList *self) {
- return self->post_stream;
+ return SegPList_IVARS(self)->post_stream;
}
int32_t
SegPList_next(SegPostingList *self) {
- InStream *const post_stream = self->post_stream;
- Posting *const posting = self->posting;
+ SegPostingListIVARS *const ivars = SegPList_IVARS(self);
+ InStream *const post_stream = ivars->post_stream;
+ Posting *const posting = ivars->posting;
// Bail if we're out of docs.
- if (self->count >= self->doc_freq) {
+ if (ivars->count >= ivars->doc_freq) {
Post_Reset(posting);
return 0;
}
- self->count++;
+ ivars->count++;
Post_Read_Record(posting, post_stream);
- return posting->doc_id;
+ return Post_IVARS(posting)->doc_id;
}
int32_t
SegPList_advance(SegPostingList *self, int32_t target) {
- Posting *posting = self->posting;
- const uint32_t skip_interval = self->skip_interval;
-
- if (self->doc_freq >= skip_interval) {
- InStream *post_stream = self->post_stream;
- InStream *skip_stream = self->skip_stream;
- SkipStepper *const skip_stepper = self->skip_stepper;
- uint32_t new_doc_id = skip_stepper->doc_id;
+ SegPostingListIVARS *const ivars = SegPList_IVARS(self);
+ PostingIVARS *const posting_ivars = Post_IVARS(ivars->posting);
+ const uint32_t skip_interval = ivars->skip_interval;
+
+ if (ivars->doc_freq >= skip_interval) {
+ InStream *post_stream = ivars->post_stream;
+ InStream *skip_stream = ivars->skip_stream;
+ SkipStepper *const skip_stepper = ivars->skip_stepper;
+ SkipStepperIVARS *const skip_stepper_ivars
+ = SkipStepper_IVARS(skip_stepper);
+ uint32_t new_doc_id = skip_stepper_ivars->doc_id;
int64_t new_filepos = InStream_Tell(post_stream);
/* Assuming the default skip_interval of 16...
@@ -188,28 +195,28 @@ SegPList_advance(SegPostingList *self, int32_t target) {
* yet, but we'll have already gone past 5 of the 16 skip docs --
* ergo, the modulus in the following formula.
*/
- int32_t num_skipped = 0 - (self->count % skip_interval);
- if (num_skipped == 0 && self->count != 0) {
+ int32_t num_skipped = 0 - (ivars->count % skip_interval);
+ if (num_skipped == 0 && ivars->count != 0) {
num_skipped = 0 - skip_interval;
}
// See if there's anything to skip.
- while (target > skip_stepper->doc_id) {
- new_doc_id = skip_stepper->doc_id;
- new_filepos = skip_stepper->filepos;
+ while (target > skip_stepper_ivars->doc_id) {
+ new_doc_id = skip_stepper_ivars->doc_id;
+ new_filepos = skip_stepper_ivars->filepos;
- if (skip_stepper->doc_id != 0
- && skip_stepper->doc_id >= posting->doc_id
+ if (skip_stepper_ivars->doc_id != 0
+ && skip_stepper_ivars->doc_id >= posting_ivars->doc_id
) {
num_skipped += skip_interval;
}
- if (self->skip_count >= self->num_skips) {
+ if (ivars->skip_count >= ivars->num_skips) {
break;
}
SkipStepper_Read_Record(skip_stepper, skip_stream);
- self->skip_count++;
+ ivars->skip_count++;
}
// If we found something to skip, skip it.
@@ -219,10 +226,10 @@ SegPList_advance(SegPostingList *self, int32_t target) {
InStream_Seek(post_stream, new_filepos);
// Jump to the new doc id.
- posting->doc_id = new_doc_id;
+ posting_ivars->doc_id = new_doc_id;
// Increase count by the number of docs we skipped over.
- self->count += num_skipped;
+ ivars->count += num_skipped;
}
}
@@ -237,22 +244,25 @@ SegPList_advance(SegPostingList *self, int32_t target) {
void
SegPList_seek(SegPostingList *self, Obj *target) {
- LexiconReader *lex_reader = PListReader_Get_Lex_Reader(self->plist_reader);
+ SegPostingListIVARS *const ivars = SegPList_IVARS(self);
+ LexiconReader *lex_reader = PListReader_Get_Lex_Reader(ivars->plist_reader);
TermInfo *tinfo = LexReader_Fetch_Term_Info(lex_reader,
- self->field, target);
+ ivars->field, target);
S_seek_tinfo(self, tinfo);
DECREF(tinfo);
}
void
SegPList_seek_lex(SegPostingList *self, Lexicon *lexicon) {
+ SegPostingListIVARS *const ivars = SegPList_IVARS(self);
+
// Maybe true, maybe not.
SegLexicon *const seg_lexicon = (SegLexicon*)lexicon;
// Optimized case.
if (Obj_Is_A((Obj*)lexicon, SEGLEXICON)
&& (SegLex_Get_Segment(seg_lexicon)
- == PListReader_Get_Segment(self->plist_reader)) // i.e. same segment
+ == PListReader_Get_Segment(ivars->plist_reader)) // i.e. same segment
) {
S_seek_tinfo(self, SegLex_Get_Term_Info(seg_lexicon));
}
@@ -266,40 +276,43 @@ SegPList_seek_lex(SegPostingList *self, Lexicon *lexicon) {
static void
S_seek_tinfo(SegPostingList *self, TermInfo *tinfo) {
- self->count = 0;
+ SegPostingListIVARS *const ivars = SegPList_IVARS(self);
+ ivars->count = 0;
if (tinfo == NULL) {
// Next will return false; other methods invalid now.
- self->doc_freq = 0;
+ ivars->doc_freq = 0;
}
else {
// Transfer doc_freq, seek main stream.
int64_t post_filepos = TInfo_Get_Post_FilePos(tinfo);
- self->doc_freq = TInfo_Get_Doc_Freq(tinfo);
- InStream_Seek(self->post_stream, post_filepos);
+ ivars->doc_freq = TInfo_Get_Doc_Freq(tinfo);
+ InStream_Seek(ivars->post_stream, post_filepos);
// Prepare posting.
- Post_Reset(self->posting);
+ Post_Reset(ivars->posting);
// Prepare to skip.
- self->skip_count = 0;
- self->num_skips = self->doc_freq / self->skip_interval;
- SkipStepper_Set_ID_And_Filepos(self->skip_stepper, 0, post_filepos);
- InStream_Seek(self->skip_stream, TInfo_Get_Skip_FilePos(tinfo));
+ ivars->skip_count = 0;
+ ivars->num_skips = ivars->doc_freq / ivars->skip_interval;
+ SkipStepper_Set_ID_And_Filepos(ivars->skip_stepper, 0, post_filepos);
+ InStream_Seek(ivars->skip_stream, TInfo_Get_Skip_FilePos(tinfo));
}
}
Matcher*
SegPList_make_matcher(SegPostingList *self, Similarity *sim,
Compiler *compiler, bool need_score) {
- return Post_Make_Matcher(self->posting, sim, (PostingList*)self, compiler,
+ SegPostingListIVARS *const ivars = SegPList_IVARS(self);
+ return Post_Make_Matcher(ivars->posting, sim, (PostingList*)self, compiler,
need_score);
}
RawPosting*
SegPList_read_raw(SegPostingList *self, int32_t last_doc_id, CharBuf *term_text,
MemoryPool *mem_pool) {
- return Post_Read_Raw(self->posting, self->post_stream,
+ SegPostingListIVARS *const ivars = SegPList_IVARS(self);
+ return Post_Read_Raw(ivars->posting, ivars->post_stream,
last_doc_id, term_text, mem_pool);
}
http://git-wip-us.apache.org/repos/asf/lucy/blob/7c23ce21/core/Lucy/Index/SegReader.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/SegReader.c b/core/Lucy/Index/SegReader.c
index ad803b2..e9a1ba6 100644
--- a/core/Lucy/Index/SegReader.c
+++ b/core/Lucy/Index/SegReader.c
@@ -47,11 +47,12 @@ SegReader_init(SegReader *self, Schema *schema, Folder *folder,
IxReader_init((IndexReader*)self, schema, folder, snapshot, segments,
seg_tick, NULL);
+ SegReaderIVARS *const ivars = SegReader_IVARS(self);
segment = SegReader_Get_Segment(self);
- self->doc_max = (int32_t)Seg_Get_Count(segment);
- self->seg_name = (CharBuf*)INCREF(Seg_Get_Name(segment));
- self->seg_num = Seg_Get_Number(segment);
+ ivars->doc_max = (int32_t)Seg_Get_Count(segment);
+ ivars->seg_name = (CharBuf*)INCREF(Seg_Get_Name(segment));
+ ivars->seg_num = Seg_Get_Number(segment);
Err *error = Err_trap(S_try_init_components, self);
if (error) {
// An error occurred, so clean up self and rethrow the exception.
@@ -61,8 +62,8 @@ SegReader_init(SegReader *self, Schema *schema, Folder *folder,
DeletionsReader *del_reader
= (DeletionsReader*)Hash_Fetch(
- self->components, (Obj*)VTable_Get_Name(DELETIONSREADER));
- self->del_count = del_reader ? DelReader_Del_Count(del_reader) : 0;
+ ivars->components, (Obj*)VTable_Get_Name(DELETIONSREADER));
+ ivars->del_count = del_reader ? DelReader_Del_Count(del_reader) : 0;
return self;
}
@@ -77,43 +78,46 @@ S_try_init_components(void *context) {
void
SegReader_destroy(SegReader *self) {
- DECREF(self->seg_name);
+ SegReaderIVARS *const ivars = SegReader_IVARS(self);
+ DECREF(ivars->seg_name);
SUPER_DESTROY(self, SEGREADER);
}
void
SegReader_register(SegReader *self, const CharBuf *api,
DataReader *component) {
- if (Hash_Fetch(self->components, (Obj*)api)) {
+ SegReaderIVARS *const ivars = SegReader_IVARS(self);
+ if (Hash_Fetch(ivars->components, (Obj*)api)) {
THROW(ERR, "Interface '%o' already registered");
}
CERTIFY(component, DATAREADER);
- Hash_Store(self->components, (Obj*)api, (Obj*)component);
+ Hash_Store(ivars->components, (Obj*)api, (Obj*)component);
}
CharBuf*
SegReader_get_seg_name(SegReader *self) {
- return self->seg_name;
+ return SegReader_IVARS(self)->seg_name;
}
int64_t
SegReader_get_seg_num(SegReader *self) {
- return self->seg_num;
+ return SegReader_IVARS(self)->seg_num;
}
int32_t
SegReader_del_count(SegReader *self) {
- return self->del_count;
+ return SegReader_IVARS(self)->del_count;
}
int32_t
SegReader_doc_max(SegReader *self) {
- return self->doc_max;
+ return SegReader_IVARS(self)->doc_max;
}
int32_t
SegReader_doc_count(SegReader *self) {
- return self->doc_max - self->del_count;
+ SegReaderIVARS *const ivars = SegReader_IVARS(self);
+ return ivars->doc_max - ivars->del_count;
}
I32Array*
http://git-wip-us.apache.org/repos/asf/lucy/blob/7c23ce21/core/Lucy/Index/SegWriter.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/SegWriter.c b/core/Lucy/Index/SegWriter.c
index 02fe391..6280664 100644
--- a/core/Lucy/Index/SegWriter.c
+++ b/core/Lucy/Index/SegWriter.c
@@ -42,46 +42,52 @@ SegWriter_init(SegWriter *self, Schema *schema, Snapshot *snapshot,
Segment *segment, PolyReader *polyreader) {
Architecture *arch = Schema_Get_Architecture(schema);
DataWriter_init((DataWriter*)self, schema, snapshot, segment, polyreader);
- self->by_api = Hash_new(0);
- self->inverter = Inverter_new(schema, segment);
- self->writers = VA_new(16);
+ SegWriterIVARS *const ivars = SegWriter_IVARS(self);
+ ivars->by_api = Hash_new(0);
+ ivars->inverter = Inverter_new(schema, segment);
+ ivars->writers = VA_new(16);
Arch_Init_Seg_Writer(arch, self);
return self;
}
void
SegWriter_destroy(SegWriter *self) {
- DECREF(self->inverter);
- DECREF(self->writers);
- DECREF(self->by_api);
- DECREF(self->del_writer);
+ SegWriterIVARS *const ivars = SegWriter_IVARS(self);
+ DECREF(ivars->inverter);
+ DECREF(ivars->writers);
+ DECREF(ivars->by_api);
+ DECREF(ivars->del_writer);
SUPER_DESTROY(self, SEGWRITER);
}
void
SegWriter_register(SegWriter *self, const CharBuf *api,
DataWriter *component) {
+ SegWriterIVARS *const ivars = SegWriter_IVARS(self);
CERTIFY(component, DATAWRITER);
- if (Hash_Fetch(self->by_api, (Obj*)api)) {
+ if (Hash_Fetch(ivars->by_api, (Obj*)api)) {
THROW(ERR, "API %o already registered", api);
}
- Hash_Store(self->by_api, (Obj*)api, (Obj*)component);
+ Hash_Store(ivars->by_api, (Obj*)api, (Obj*)component);
}
Obj*
SegWriter_fetch(SegWriter *self, const CharBuf *api) {
- return Hash_Fetch(self->by_api, (Obj*)api);
+ SegWriterIVARS *const ivars = SegWriter_IVARS(self);
+ return Hash_Fetch(ivars->by_api, (Obj*)api);
}
void
SegWriter_add_writer(SegWriter *self, DataWriter *writer) {
- VA_Push(self->writers, (Obj*)writer);
+ SegWriterIVARS *const ivars = SegWriter_IVARS(self);
+ VA_Push(ivars->writers, (Obj*)writer);
}
void
SegWriter_prep_seg_dir(SegWriter *self) {
+ SegWriterIVARS *const ivars = SegWriter_IVARS(self);
Folder *folder = SegWriter_Get_Folder(self);
- CharBuf *seg_name = Seg_Get_Name(self->segment);
+ CharBuf *seg_name = Seg_Get_Name(ivars->segment);
// Clear stale segment files from crashed indexing sessions.
if (Folder_Exists(folder, seg_name)) {
@@ -98,17 +104,19 @@ SegWriter_prep_seg_dir(SegWriter *self) {
void
SegWriter_add_doc(SegWriter *self, Doc *doc, float boost) {
- int32_t doc_id = (int32_t)Seg_Increment_Count(self->segment, 1);
- Inverter_Invert_Doc(self->inverter, doc);
- Inverter_Set_Boost(self->inverter, boost);
- SegWriter_Add_Inverted_Doc(self, self->inverter, doc_id);
+ SegWriterIVARS *const ivars = SegWriter_IVARS(self);
+ int32_t doc_id = (int32_t)Seg_Increment_Count(ivars->segment, 1);
+ Inverter_Invert_Doc(ivars->inverter, doc);
+ Inverter_Set_Boost(ivars->inverter, boost);
+ SegWriter_Add_Inverted_Doc(self, ivars->inverter, doc_id);
}
void
SegWriter_add_inverted_doc(SegWriter *self, Inverter *inverter,
int32_t doc_id) {
- for (uint32_t i = 0, max = VA_Get_Size(self->writers); i < max; i++) {
- DataWriter *writer = (DataWriter*)VA_Fetch(self->writers, i);
+ SegWriterIVARS *const ivars = SegWriter_IVARS(self);
+ for (uint32_t i = 0, max = VA_Get_Size(ivars->writers); i < max; i++) {
+ DataWriter *writer = (DataWriter*)VA_Fetch(ivars->writers, i);
DataWriter_Add_Inverted_Doc(writer, inverter, doc_id);
}
}
@@ -118,24 +126,27 @@ SegWriter_add_inverted_doc(SegWriter *self, Inverter *inverter,
// probably out of sync.
static void
S_adjust_doc_id(SegWriter *self, SegReader *reader, I32Array *doc_map) {
+ SegWriterIVARS *const ivars = SegWriter_IVARS(self);
uint32_t doc_count = SegReader_Doc_Max(reader);
for (uint32_t i = 1, max = I32Arr_Get_Size(doc_map); i < max; i++) {
if (I32Arr_Get(doc_map, i) == 0) { doc_count--; }
}
- Seg_Increment_Count(self->segment, doc_count);
+ Seg_Increment_Count(ivars->segment, doc_count);
}
void
SegWriter_add_segment(SegWriter *self, SegReader *reader, I32Array *doc_map) {
+ SegWriterIVARS *const ivars = SegWriter_IVARS(self);
+
// Bulk add the slab of documents to the various writers.
- for (uint32_t i = 0, max = VA_Get_Size(self->writers); i < max; i++) {
- DataWriter *writer = (DataWriter*)VA_Fetch(self->writers, i);
+ for (uint32_t i = 0, max = VA_Get_Size(ivars->writers); i < max; i++) {
+ DataWriter *writer = (DataWriter*)VA_Fetch(ivars->writers, i);
DataWriter_Add_Segment(writer, reader, doc_map);
}
// Bulk add the segment to the DeletionsWriter, so that it can merge
// previous segment files as necessary.
- DelWriter_Add_Segment(self->del_writer, reader, doc_map);
+ DelWriter_Add_Segment(ivars->del_writer, reader, doc_map);
// Adust the document id.
S_adjust_doc_id(self, reader, doc_map);
@@ -144,15 +155,16 @@ SegWriter_add_segment(SegWriter *self, SegReader *reader, I32Array *doc_map) {
void
SegWriter_merge_segment(SegWriter *self, SegReader *reader,
I32Array *doc_map) {
+ SegWriterIVARS *const ivars = SegWriter_IVARS(self);
Snapshot *snapshot = SegWriter_Get_Snapshot(self);
CharBuf *seg_name = Seg_Get_Name(SegReader_Get_Segment(reader));
// Have all the sub-writers merge the segment.
- for (uint32_t i = 0, max = VA_Get_Size(self->writers); i < max; i++) {
- DataWriter *writer = (DataWriter*)VA_Fetch(self->writers, i);
+ for (uint32_t i = 0, max = VA_Get_Size(ivars->writers); i < max; i++) {
+ DataWriter *writer = (DataWriter*)VA_Fetch(ivars->writers, i);
DataWriter_Merge_Segment(writer, reader, doc_map);
}
- DelWriter_Merge_Segment(self->del_writer, reader, doc_map);
+ DelWriter_Merge_Segment(ivars->del_writer, reader, doc_map);
// Remove seg directory from snapshot.
Snapshot_Delete_Entry(snapshot, seg_name);
@@ -163,15 +175,16 @@ SegWriter_merge_segment(SegWriter *self, SegReader *reader,
void
SegWriter_delete_segment(SegWriter *self, SegReader *reader) {
+ SegWriterIVARS *const ivars = SegWriter_IVARS(self);
Snapshot *snapshot = SegWriter_Get_Snapshot(self);
CharBuf *seg_name = Seg_Get_Name(SegReader_Get_Segment(reader));
// Have all the sub-writers delete the segment.
- for (uint32_t i = 0, max = VA_Get_Size(self->writers); i < max; i++) {
- DataWriter *writer = (DataWriter*)VA_Fetch(self->writers, i);
+ for (uint32_t i = 0, max = VA_Get_Size(ivars->writers); i < max; i++) {
+ DataWriter *writer = (DataWriter*)VA_Fetch(ivars->writers, i);
DataWriter_Delete_Segment(writer, reader);
}
- DelWriter_Delete_Segment(self->del_writer, reader);
+ DelWriter_Delete_Segment(ivars->del_writer, reader);
// Remove seg directory from snapshot.
Snapshot_Delete_Entry(snapshot, seg_name);
@@ -179,39 +192,42 @@ SegWriter_delete_segment(SegWriter *self, SegReader *reader) {
void
SegWriter_finish(SegWriter *self) {
- CharBuf *seg_name = Seg_Get_Name(self->segment);
+ SegWriterIVARS *const ivars = SegWriter_IVARS(self);
+ CharBuf *seg_name = Seg_Get_Name(ivars->segment);
// Finish off children.
- for (uint32_t i = 0, max = VA_Get_Size(self->writers); i < max; i++) {
- DataWriter *writer = (DataWriter*)VA_Fetch(self->writers, i);
+ for (uint32_t i = 0, max = VA_Get_Size(ivars->writers); i < max; i++) {
+ DataWriter *writer = (DataWriter*)VA_Fetch(ivars->writers, i);
DataWriter_Finish(writer);
}
// Write segment metadata and add the segment directory to the snapshot.
Snapshot *snapshot = SegWriter_Get_Snapshot(self);
CharBuf *segmeta_filename = CB_newf("%o/segmeta.json", seg_name);
- Seg_Write_File(self->segment, self->folder);
+ Seg_Write_File(ivars->segment, ivars->folder);
Snapshot_Add_Entry(snapshot, seg_name);
DECREF(segmeta_filename);
// Collapse segment files into compound file.
- Folder_Consolidate(self->folder, seg_name);
+ Folder_Consolidate(ivars->folder, seg_name);
}
void
SegWriter_add_data_writer(SegWriter *self, DataWriter *writer) {
- VA_Push(self->writers, (Obj*)writer);
+ SegWriterIVARS *const ivars = SegWriter_IVARS(self);
+ VA_Push(ivars->writers, (Obj*)writer);
}
void
SegWriter_set_del_writer(SegWriter *self, DeletionsWriter *del_writer) {
- DECREF(self->del_writer);
- self->del_writer = (DeletionsWriter*)INCREF(del_writer);
+ SegWriterIVARS *const ivars = SegWriter_IVARS(self);
+ DECREF(ivars->del_writer);
+ ivars->del_writer = (DeletionsWriter*)INCREF(del_writer);
}
DeletionsWriter*
SegWriter_get_del_writer(SegWriter *self) {
- return self->del_writer;
+ return SegWriter_IVARS(self)->del_writer;
}
http://git-wip-us.apache.org/repos/asf/lucy/blob/7c23ce21/core/Lucy/Index/Segment.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/Segment.c b/core/Lucy/Index/Segment.c
index 69365ed..ddcebee 100644
--- a/core/Lucy/Index/Segment.c
+++ b/core/Lucy/Index/Segment.c
@@ -33,23 +33,25 @@ Seg_new(int64_t number) {
Segment*
Seg_init(Segment *self, int64_t number) {
+ SegmentIVARS *const ivars = Seg_IVARS(self);
+
// Validate.
if (number < 0) { THROW(ERR, "Segment number %i64 less than 0", number); }
// Init.
- self->metadata = Hash_new(0);
- self->count = 0;
- self->by_num = VA_new(2);
- self->by_name = Hash_new(0);
+ ivars->metadata = Hash_new(0);
+ ivars->count = 0;
+ ivars->by_num = VA_new(2);
+ ivars->by_name = Hash_new(0);
// Start field numbers at 1, not 0.
- VA_Push(self->by_num, (Obj*)CB_newf(""));
+ VA_Push(ivars->by_num, (Obj*)CB_newf(""));
// Assign.
- self->number = number;
+ ivars->number = number;
// Derive.
- self->name = Seg_num_to_name(number);
+ ivars->name = Seg_num_to_name(number);
return self;
}
@@ -77,16 +79,18 @@ Seg_valid_seg_name(const CharBuf *name) {
void
Seg_destroy(Segment *self) {
- DECREF(self->name);
- DECREF(self->metadata);
- DECREF(self->by_name);
- DECREF(self->by_num);
+ SegmentIVARS *const ivars = Seg_IVARS(self);
+ DECREF(ivars->name);
+ DECREF(ivars->metadata);
+ DECREF(ivars->by_name);
+ DECREF(ivars->by_num);
SUPER_DESTROY(self, SEGMENT);
}
bool
Seg_read_file(Segment *self, Folder *folder) {
- CharBuf *filename = CB_newf("%o/segmeta.json", self->name);
+ SegmentIVARS *const ivars = Seg_IVARS(self);
+ CharBuf *filename = CB_newf("%o/segmeta.json", ivars->name);
Hash *metadata = (Hash*)Json_slurp_json(folder, filename);
Hash *my_metadata;
@@ -96,16 +100,16 @@ Seg_read_file(Segment *self, Folder *folder) {
CERTIFY(metadata, HASH);
// Grab metadata for the Segment object itself.
- DECREF(self->metadata);
- self->metadata = metadata;
+ DECREF(ivars->metadata);
+ ivars->metadata = metadata;
my_metadata
- = (Hash*)CERTIFY(Hash_Fetch_Str(self->metadata, "segmeta", 7), HASH);
+ = (Hash*)CERTIFY(Hash_Fetch_Str(ivars->metadata, "segmeta", 7), HASH);
// Assign.
Obj *count = Hash_Fetch_Str(my_metadata, "count", 5);
if (!count) { count = Hash_Fetch_Str(my_metadata, "doc_count", 9); }
if (!count) { THROW(ERR, "Missing 'count'"); }
- else { self->count = Obj_To_I64(count); }
+ else { ivars->count = Obj_To_I64(count); }
// Get list of field nums.
VArray *source_by_num = (VArray*)Hash_Fetch_Str(my_metadata,
@@ -116,10 +120,10 @@ Seg_read_file(Segment *self, Folder *folder) {
}
// Init.
- DECREF(self->by_num);
- DECREF(self->by_name);
- self->by_num = VA_new(num_fields);
- self->by_name = Hash_new(num_fields);
+ DECREF(ivars->by_num);
+ DECREF(ivars->by_name);
+ ivars->by_num = VA_new(num_fields);
+ ivars->by_name = Hash_new(num_fields);
// Copy the list of fields from the source.
for (uint32_t i = 0; i < num_fields; i++) {
@@ -132,68 +136,72 @@ Seg_read_file(Segment *self, Folder *folder) {
void
Seg_write_file(Segment *self, Folder *folder) {
+ SegmentIVARS *const ivars = Seg_IVARS(self);
Hash *my_metadata = Hash_new(16);
// Store metadata specific to this Segment object.
Hash_Store_Str(my_metadata, "count", 5,
- (Obj*)CB_newf("%i64", self->count));
- Hash_Store_Str(my_metadata, "name", 4, (Obj*)CB_Clone(self->name));
- Hash_Store_Str(my_metadata, "field_names", 11, INCREF(self->by_num));
+ (Obj*)CB_newf("%i64", ivars->count));
+ Hash_Store_Str(my_metadata, "name", 4, (Obj*)CB_Clone(ivars->name));
+ Hash_Store_Str(my_metadata, "field_names", 11, INCREF(ivars->by_num));
Hash_Store_Str(my_metadata, "format", 6, (Obj*)CB_newf("%i32", 1));
- Hash_Store_Str(self->metadata, "segmeta", 7, (Obj*)my_metadata);
+ Hash_Store_Str(ivars->metadata, "segmeta", 7, (Obj*)my_metadata);
- CharBuf *filename = CB_newf("%o/segmeta.json", self->name);
- bool result = Json_spew_json((Obj*)self->metadata, folder, filename);
+ CharBuf *filename = CB_newf("%o/segmeta.json", ivars->name);
+ bool result = Json_spew_json((Obj*)ivars->metadata, folder, filename);
DECREF(filename);
if (!result) { RETHROW(INCREF(Err_get_error())); }
}
int32_t
Seg_add_field(Segment *self, const CharBuf *field) {
- Integer32 *num = (Integer32*)Hash_Fetch(self->by_name, (Obj*)field);
+ SegmentIVARS *const ivars = Seg_IVARS(self);
+ Integer32 *num = (Integer32*)Hash_Fetch(ivars->by_name, (Obj*)field);
if (num) {
return Int32_Get_Value(num);
}
else {
- int32_t field_num = VA_Get_Size(self->by_num);
- Hash_Store(self->by_name, (Obj*)field, (Obj*)Int32_new(field_num));
- VA_Push(self->by_num, (Obj*)CB_Clone(field));
+ int32_t field_num = VA_Get_Size(ivars->by_num);
+ Hash_Store(ivars->by_name, (Obj*)field, (Obj*)Int32_new(field_num));
+ VA_Push(ivars->by_num, (Obj*)CB_Clone(field));
return field_num;
}
}
CharBuf*
Seg_get_name(Segment *self) {
- return self->name;
+ return Seg_IVARS(self)->name;
}
int64_t
Seg_get_number(Segment *self) {
- return self->number;
+ return Seg_IVARS(self)->number;
}
void
Seg_set_count(Segment *self, int64_t count) {
- self->count = count;
+ Seg_IVARS(self)->count = count;
}
int64_t
Seg_get_count(Segment *self) {
- return self->count;
+ return Seg_IVARS(self)->count;
}
int64_t
Seg_increment_count(Segment *self, int64_t increment) {
- self->count += increment;
- return self->count;
+ SegmentIVARS *const ivars = Seg_IVARS(self);
+ ivars->count += increment;
+ return ivars->count;
}
void
Seg_store_metadata(Segment *self, const CharBuf *key, Obj *value) {
- if (Hash_Fetch(self->metadata, (Obj*)key)) {
+ SegmentIVARS *const ivars = Seg_IVARS(self);
+ if (Hash_Fetch(ivars->metadata, (Obj*)key)) {
THROW(ERR, "Metadata key '%o' already registered", key);
}
- Hash_Store(self->metadata, (Obj*)key, value);
+ Hash_Store(ivars->metadata, (Obj*)key, value);
}
void
@@ -205,31 +213,36 @@ Seg_store_metadata_str(Segment *self, const char *key, size_t key_len,
Obj*
Seg_fetch_metadata(Segment *self, const CharBuf *key) {
- return Hash_Fetch(self->metadata, (Obj*)key);
+ SegmentIVARS *const ivars = Seg_IVARS(self);
+ return Hash_Fetch(ivars->metadata, (Obj*)key);
}
Obj*
Seg_fetch_metadata_str(Segment *self, const char *key, size_t len) {
- return Hash_Fetch_Str(self->metadata, key, len);
+ SegmentIVARS *const ivars = Seg_IVARS(self);
+ return Hash_Fetch_Str(ivars->metadata, key, len);
}
Hash*
Seg_get_metadata(Segment *self) {
- return self->metadata;
+ return Seg_IVARS(self)->metadata;
}
int32_t
Seg_compare_to(Segment *self, Obj *other) {
Segment *other_seg = (Segment*)CERTIFY(other, SEGMENT);
- if (self->number < other_seg->number) { return -1; }
- else if (self->number == other_seg->number) { return 0; }
- else { return 1; }
+ SegmentIVARS *const ivars = Seg_IVARS(self);
+ SegmentIVARS *const ovars = Seg_IVARS(other_seg);
+ if (ivars->number < ovars->number) { return -1; }
+ else if (ivars->number == ovars->number) { return 0; }
+ else { return 1; }
}
CharBuf*
Seg_field_name(Segment *self, int32_t field_num) {
+ SegmentIVARS *const ivars = Seg_IVARS(self);
return field_num
- ? (CharBuf*)VA_Fetch(self->by_num, field_num)
+ ? (CharBuf*)VA_Fetch(ivars->by_num, field_num)
: NULL;
}
@@ -239,7 +252,8 @@ Seg_field_num(Segment *self, const CharBuf *field) {
return 0;
}
else {
- Integer32 *num = (Integer32*)Hash_Fetch(self->by_name, (Obj*)field);
+ SegmentIVARS *const ivars = Seg_IVARS(self);
+ Integer32 *num = (Integer32*)Hash_Fetch(ivars->by_name, (Obj*)field);
return num ? Int32_Get_Value(num) : 0;
}
}
http://git-wip-us.apache.org/repos/asf/lucy/blob/7c23ce21/core/Lucy/Index/Similarity.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/Similarity.c b/core/Lucy/Index/Similarity.c
index 2118cdc..a583ef1 100644
--- a/core/Lucy/Index/Similarity.c
+++ b/core/Lucy/Index/Similarity.c
@@ -39,14 +39,16 @@ Sim_new() {
Similarity*
Sim_init(Similarity *self) {
- self->norm_decoder = NULL;
+ SimilarityIVARS *const ivars = Sim_IVARS(self);
+ ivars->norm_decoder = NULL;
return self;
}
void
Sim_destroy(Similarity *self) {
- if (self->norm_decoder) {
- FREEMEM(self->norm_decoder);
+ SimilarityIVARS *const ivars = Sim_IVARS(self);
+ if (ivars->norm_decoder) {
+ FREEMEM(ivars->norm_decoder);
}
SUPER_DESTROY(self, SIMILARITY);
}
@@ -67,14 +69,15 @@ Sim_make_posting_writer(Similarity *self, Schema *schema, Snapshot *snapshot,
float*
Sim_get_norm_decoder(Similarity *self) {
- if (!self->norm_decoder) {
+ SimilarityIVARS *const ivars = Sim_IVARS(self);
+ if (!ivars->norm_decoder) {
// Cache decoded boost bytes.
- self->norm_decoder = (float*)MALLOCATE(256 * sizeof(float));
+ ivars->norm_decoder = (float*)MALLOCATE(256 * sizeof(float));
for (uint32_t i = 0; i < 256; i++) {
- self->norm_decoder[i] = Sim_Decode_Norm(self, i);
+ ivars->norm_decoder[i] = Sim_Decode_Norm(self, i);
}
}
- return self->norm_decoder;
+ return ivars->norm_decoder;
}
Obj*
http://git-wip-us.apache.org/repos/asf/lucy/blob/7c23ce21/core/Lucy/Index/SkipStepper.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/SkipStepper.c b/core/Lucy/Index/SkipStepper.c
index f07b9f3..33ce450 100644
--- a/core/Lucy/Index/SkipStepper.c
+++ b/core/Lucy/Index/SkipStepper.c
@@ -27,10 +27,11 @@
SkipStepper*
SkipStepper_new() {
SkipStepper *self = (SkipStepper*)VTable_Make_Obj(SKIPSTEPPER);
+ SkipStepperIVARS *const ivars = SkipStepper_IVARS(self);
// Init.
- self->doc_id = 0;
- self->filepos = 0;
+ ivars->doc_id = 0;
+ ivars->filepos = 0;
return self;
}
@@ -38,29 +39,33 @@ SkipStepper_new() {
void
SkipStepper_set_id_and_filepos(SkipStepper *self, int32_t doc_id,
int64_t filepos) {
- self->doc_id = doc_id;
- self->filepos = filepos;
+ SkipStepperIVARS *const ivars = SkipStepper_IVARS(self);
+ ivars->doc_id = doc_id;
+ ivars->filepos = filepos;
}
void
SkipStepper_read_record(SkipStepper *self, InStream *instream) {
- self->doc_id += InStream_Read_C32(instream);
- self->filepos += InStream_Read_C64(instream);
+ SkipStepperIVARS *const ivars = SkipStepper_IVARS(self);
+ ivars->doc_id += InStream_Read_C32(instream);
+ ivars->filepos += InStream_Read_C64(instream);
}
CharBuf*
SkipStepper_to_string(SkipStepper *self) {
+ SkipStepperIVARS *const ivars = SkipStepper_IVARS(self);
char *ptr = (char*)MALLOCATE(60);
size_t len = sprintf(ptr, "skip doc: %u file pointer: %" PRId64,
- self->doc_id, self->filepos);
+ ivars->doc_id, ivars->filepos);
return CB_new_steal_from_trusted_str(ptr, len, 60);
}
void
SkipStepper_write_record(SkipStepper *self, OutStream *outstream,
int32_t last_doc_id, int64_t last_filepos) {
- const int32_t delta_doc_id = self->doc_id - last_doc_id;
- const int64_t delta_filepos = self->filepos - last_filepos;
+ SkipStepperIVARS *const ivars = SkipStepper_IVARS(self);
+ const int32_t delta_doc_id = ivars->doc_id - last_doc_id;
+ const int64_t delta_filepos = ivars->filepos - last_filepos;
// Write delta doc id.
OutStream_Write_C32(outstream, delta_doc_id);
http://git-wip-us.apache.org/repos/asf/lucy/blob/7c23ce21/core/Lucy/Index/Snapshot.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/Snapshot.c b/core/Lucy/Index/Snapshot.c
index beca285..4bae50f 100644
--- a/core/Lucy/Index/Snapshot.c
+++ b/core/Lucy/Index/Snapshot.c
@@ -38,10 +38,11 @@ Snapshot_new() {
static void
S_zero_out(Snapshot *self) {
- DECREF(self->entries);
- DECREF(self->path);
- self->entries = Hash_new(0);
- self->path = NULL;
+ SnapshotIVARS *const ivars = Snapshot_IVARS(self);
+ DECREF(ivars->entries);
+ DECREF(ivars->path);
+ ivars->entries = Hash_new(0);
+ ivars->path = NULL;
}
Snapshot*
@@ -52,19 +53,22 @@ Snapshot_init(Snapshot *self) {
void
Snapshot_destroy(Snapshot *self) {
- DECREF(self->entries);
- DECREF(self->path);
+ SnapshotIVARS *const ivars = Snapshot_IVARS(self);
+ DECREF(ivars->entries);
+ DECREF(ivars->path);
SUPER_DESTROY(self, SNAPSHOT);
}
void
Snapshot_add_entry(Snapshot *self, const CharBuf *entry) {
- Hash_Store(self->entries, (Obj*)entry, (Obj*)CFISH_TRUE);
+ SnapshotIVARS *const ivars = Snapshot_IVARS(self);
+ Hash_Store(ivars->entries, (Obj*)entry, (Obj*)CFISH_TRUE);
}
bool
Snapshot_delete_entry(Snapshot *self, const CharBuf *entry) {
- Obj *val = Hash_Delete(self->entries, (Obj*)entry);
+ SnapshotIVARS *const ivars = Snapshot_IVARS(self);
+ Obj *val = Hash_Delete(ivars->entries, (Obj*)entry);
if (val) {
Obj_Dec_RefCount(val);
return true;
@@ -76,34 +80,39 @@ Snapshot_delete_entry(Snapshot *self, const CharBuf *entry) {
VArray*
Snapshot_list(Snapshot *self) {
- return Hash_Keys(self->entries);
+ SnapshotIVARS *const ivars = Snapshot_IVARS(self);
+ return Hash_Keys(ivars->entries);
}
uint32_t
Snapshot_num_entries(Snapshot *self) {
- return Hash_Get_Size(self->entries);
+ SnapshotIVARS *const ivars = Snapshot_IVARS(self);
+ return Hash_Get_Size(ivars->entries);
}
void
Snapshot_set_path(Snapshot *self, const CharBuf *path) {
- DECREF(self->path);
- self->path = path ? CB_Clone(path) : NULL;
+ SnapshotIVARS *const ivars = Snapshot_IVARS(self);
+ DECREF(ivars->path);
+ ivars->path = path ? CB_Clone(path) : NULL;
}
CharBuf*
Snapshot_get_path(Snapshot *self) {
- return self->path;
+ return Snapshot_IVARS(self)->path;
}
Snapshot*
Snapshot_read_file(Snapshot *self, Folder *folder, const CharBuf *path) {
+ SnapshotIVARS *const ivars = Snapshot_IVARS(self);
+
// Eliminate all prior data. Pick a snapshot file.
S_zero_out(self);
- self->path = path ? CB_Clone(path) : IxFileNames_latest_snapshot(folder);
+ ivars->path = path ? CB_Clone(path) : IxFileNames_latest_snapshot(folder);
- if (self->path) {
+ if (ivars->path) {
Hash *snap_data
- = (Hash*)CERTIFY(Json_slurp_json(folder, self->path), HASH);
+ = (Hash*)CERTIFY(Json_slurp_json(folder, ivars->path), HASH);
Obj *format_obj
= CERTIFY(Hash_Fetch_Str(snap_data, "format", 6), OBJ);
int32_t format = (int32_t)Obj_To_I64(format_obj);
@@ -128,11 +137,11 @@ Snapshot_read_file(Snapshot *self, Folder *folder, const CharBuf *path) {
DECREF(list);
list = cleaned;
}
- Hash_Clear(self->entries);
+ Hash_Clear(ivars->entries);
for (uint32_t i = 0, max = VA_Get_Size(list); i < max; i++) {
CharBuf *entry
= (CharBuf*)CERTIFY(VA_Fetch(list, i), CHARBUF);
- Hash_Store(self->entries, (Obj*)entry, (Obj*)CFISH_TRUE);
+ Hash_Store(ivars->entries, (Obj*)entry, (Obj*)CFISH_TRUE);
}
DECREF(list);
@@ -163,26 +172,27 @@ S_clean_segment_contents(VArray *orig) {
void
Snapshot_write_file(Snapshot *self, Folder *folder, const CharBuf *path) {
+ SnapshotIVARS *const ivars = Snapshot_IVARS(self);
Hash *all_data = Hash_new(0);
VArray *list = Snapshot_List(self);
// Update path.
- DECREF(self->path);
+ DECREF(ivars->path);
if (path) {
- self->path = CB_Clone(path);
+ ivars->path = CB_Clone(path);
}
else {
CharBuf *latest = IxFileNames_latest_snapshot(folder);
uint64_t gen = latest ? IxFileNames_extract_gen(latest) + 1 : 1;
char base36[StrHelp_MAX_BASE36_BYTES];
StrHelp_to_base36(gen, &base36);
- self->path = CB_newf("snapshot_%s.json", &base36);
+ ivars->path = CB_newf("snapshot_%s.json", &base36);
DECREF(latest);
}
// Don't overwrite.
- if (Folder_Exists(folder, self->path)) {
- THROW(ERR, "Snapshot file '%o' already exists", self->path);
+ if (Folder_Exists(folder, ivars->path)) {
+ THROW(ERR, "Snapshot file '%o' already exists", ivars->path);
}
// Sort, then store file names.
@@ -196,7 +206,7 @@ Snapshot_write_file(Snapshot *self, Folder *folder, const CharBuf *path) {
(Obj*)CB_newf("%i32", (int32_t)Snapshot_current_file_subformat));
// Write out JSON-ized data to the new file.
- Json_spew_json((Obj*)all_data, folder, self->path);
+ Json_spew_json((Obj*)all_data, folder, ivars->path);
DECREF(all_data);
}
http://git-wip-us.apache.org/repos/asf/lucy/blob/7c23ce21/core/Lucy/Index/SortCache.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/SortCache.c b/core/Lucy/Index/SortCache.c
index 00d41b2..31975ad 100644
--- a/core/Lucy/Index/SortCache.c
+++ b/core/Lucy/Index/SortCache.c
@@ -24,20 +24,22 @@ SortCache*
SortCache_init(SortCache *self, const CharBuf *field, FieldType *type,
void *ords, int32_t cardinality, int32_t doc_max, int32_t null_ord,
int32_t ord_width) {
+ SortCacheIVARS *const ivars = SortCache_IVARS(self);
+
// Init.
- self->native_ords = false;
+ ivars->native_ords = false;
// Assign.
if (!FType_Sortable(type)) {
THROW(ERR, "Non-sortable FieldType for %o", field);
}
- self->field = CB_Clone(field);
- self->type = (FieldType*)INCREF(type);
- self->ords = ords;
- self->cardinality = cardinality;
- self->doc_max = doc_max;
- self->null_ord = null_ord;
- self->ord_width = ord_width;
+ ivars->field = CB_Clone(field);
+ ivars->type = (FieldType*)INCREF(type);
+ ivars->ords = ords;
+ ivars->cardinality = cardinality;
+ ivars->doc_max = doc_max;
+ ivars->null_ord = null_ord;
+ ivars->ord_width = ord_width;
ABSTRACT_CLASS_CHECK(self, SORTCACHE);
return self;
@@ -45,56 +47,58 @@ SortCache_init(SortCache *self, const CharBuf *field, FieldType *type,
void
SortCache_destroy(SortCache *self) {
- DECREF(self->field);
- DECREF(self->type);
+ SortCacheIVARS *const ivars = SortCache_IVARS(self);
+ DECREF(ivars->field);
+ DECREF(ivars->type);
SUPER_DESTROY(self, SORTCACHE);
}
bool
SortCache_get_native_ords(SortCache *self) {
- return self->native_ords;
+ return SortCache_IVARS(self)->native_ords;
}
void
SortCache_set_native_ords(SortCache *self, bool native_ords) {
- self->native_ords = native_ords;
+ SortCache_IVARS(self)->native_ords = native_ords;
}
int32_t
SortCache_ordinal(SortCache *self, int32_t doc_id) {
- if ((uint32_t)doc_id > (uint32_t)self->doc_max) {
- THROW(ERR, "Out of range: %i32 > %i32", doc_id, self->doc_max);
+ SortCacheIVARS *const ivars = SortCache_IVARS(self);
+ if ((uint32_t)doc_id > (uint32_t)ivars->doc_max) {
+ THROW(ERR, "Out of range: %i32 > %i32", doc_id, ivars->doc_max);
}
- switch (self->ord_width) {
- case 1: return NumUtil_u1get(self->ords, doc_id);
- case 2: return NumUtil_u2get(self->ords, doc_id);
- case 4: return NumUtil_u4get(self->ords, doc_id);
+ switch (ivars->ord_width) {
+ case 1: return NumUtil_u1get(ivars->ords, doc_id);
+ case 2: return NumUtil_u2get(ivars->ords, doc_id);
+ case 4: return NumUtil_u4get(ivars->ords, doc_id);
case 8: {
- uint8_t *ints = (uint8_t*)self->ords;
+ uint8_t *ints = (uint8_t*)ivars->ords;
return ints[doc_id];
}
case 16:
- if (self->native_ords) {
- uint16_t *ints = (uint16_t*)self->ords;
+ if (ivars->native_ords) {
+ uint16_t *ints = (uint16_t*)ivars->ords;
return ints[doc_id];
}
else {
- uint8_t *bytes = (uint8_t*)self->ords;
+ uint8_t *bytes = (uint8_t*)ivars->ords;
bytes += doc_id * sizeof(uint16_t);
return NumUtil_decode_bigend_u16(bytes);
}
case 32:
- if (self->native_ords) {
- uint32_t *ints = (uint32_t*)self->ords;
+ if (ivars->native_ords) {
+ uint32_t *ints = (uint32_t*)ivars->ords;
return ints[doc_id];
}
else {
- uint8_t *bytes = (uint8_t*)self->ords;
+ uint8_t *bytes = (uint8_t*)ivars->ords;
bytes += doc_id * sizeof(uint32_t);
return NumUtil_decode_bigend_u32(bytes);
}
default: {
- THROW(ERR, "Invalid ord width: %i32", self->ord_width);
+ THROW(ERR, "Invalid ord width: %i32", ivars->ord_width);
UNREACHABLE_RETURN(int32_t);
}
}
@@ -102,9 +106,10 @@ SortCache_ordinal(SortCache *self, int32_t doc_id) {
int32_t
SortCache_find(SortCache *self, Obj *term) {
- FieldType *const type = self->type;
+ SortCacheIVARS *const ivars = SortCache_IVARS(self);
+ FieldType *const type = ivars->type;
int32_t lo = 0;
- int32_t hi = self->cardinality - 1;
+ int32_t hi = ivars->cardinality - 1;
int32_t result = -100;
Obj *blank = SortCache_Make_Blank(self);
@@ -113,7 +118,7 @@ SortCache_find(SortCache *self, Obj *term) {
&& !Obj_Is_A(blank, Obj_Get_VTable(term))
) {
THROW(ERR, "SortCache error for field %o: term is a %o, and not "
- "comparable to a %o", self->field, Obj_Get_Class_Name(term),
+ "comparable to a %o", ivars->field, Obj_Get_Class_Name(term),
Obj_Get_Class_Name(blank));
}
@@ -151,22 +156,22 @@ SortCache_find(SortCache *self, Obj *term) {
void*
SortCache_get_ords(SortCache *self) {
- return self->ords;
+ return SortCache_IVARS(self)->ords;
}
int32_t
SortCache_get_cardinality(SortCache *self) {
- return self->cardinality;
+ return SortCache_IVARS(self)->cardinality;
}
int32_t
SortCache_get_null_ord(SortCache *self) {
- return self->null_ord;
+ return SortCache_IVARS(self)->null_ord;
}
int32_t
SortCache_get_ord_width(SortCache *self) {
- return self->ord_width;
+ return SortCache_IVARS(self)->ord_width;
}