Use object-based elements within SortFieldWriter. Use objects rather than structs as an elements within SortFieldWriter, harmonizing with all other subclasses of SortExternal.
Project: http://git-wip-us.apache.org/repos/asf/lucy/repo Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/c2d48b32 Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/c2d48b32 Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/c2d48b32 Branch: refs/heads/sortex_ptr_only Commit: c2d48b32a00e72c3d508d885c1029128203b1c44 Parents: 7310e77 Author: Marvin Humphrey <[email protected]> Authored: Fri Jan 4 14:19:27 2013 -0800 Committer: Marvin Humphrey <[email protected]> Committed: Fri Jan 4 14:25:36 2013 -0800 ---------------------------------------------------------------------- core/Lucy/Index/SortFieldWriter.c | 51 ++++++++++++++++++++++++----- core/Lucy/Index/SortFieldWriter.cfh | 19 +++++++++++ 2 files changed, 61 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucy/blob/c2d48b32/core/Lucy/Index/SortFieldWriter.c ---------------------------------------------------------------------- diff --git a/core/Lucy/Index/SortFieldWriter.c b/core/Lucy/Index/SortFieldWriter.c index 461482f..b4d38bf 100644 --- a/core/Lucy/Index/SortFieldWriter.c +++ b/core/Lucy/Index/SortFieldWriter.c @@ -15,6 +15,7 @@ */ #define C_LUCY_SORTFIELDWRITER +#define C_LUCY_SFWRITERELEM #include "Lucy/Util/ToolSet.h" #include <math.h> @@ -49,11 +50,11 @@ static int32_t S_write_files(SortFieldWriter *self, OutStream *ord_out, OutStream *ix_out, OutStream *dat_out); -typedef struct lucy_SFWriterElem { - Obj *value; - int32_t doc_id; -} lucy_SFWriterElem; -#define SFWriterElem lucy_SFWriterElem +// Create an element for the sort pool. Both the `value` and the object +// allocation itself will come from the MemoryPool, so the the element will be +// deallocated via MemPool_Release_All(). +static SFWriterElem* +S_SFWriterElem_create(MemoryPool *mem_pool, Obj *value, int32_t doc_id); SortFieldWriter* SortFieldWriter_new(Schema *schema, Snapshot *snapshot, Segment *segment, @@ -185,10 +186,8 @@ S_find_unique_value(Hash *uniq_vals, Obj *val) { void SortFieldWriter_add(SortFieldWriter *self, int32_t doc_id, Obj *value) { // Uniq-ify the value, and record it for this document. - SFWriterElem *elem - = (SFWriterElem*)MemPool_Grab(self->mem_pool, sizeof(SFWriterElem)); - elem->value = S_find_unique_value(self->uniq_vals, value); - elem->doc_id = doc_id; + Obj *copy = S_find_unique_value(self->uniq_vals, value); + SFWriterElem *elem = S_SFWriterElem_create(self->mem_pool, copy, doc_id); SortFieldWriter_Feed(self, &elem); self->count++; } @@ -715,4 +714,38 @@ S_flip_run(SortFieldWriter *run, size_t sub_thresh, InStream *ord_in, DECREF(dat_in_dupe); } +/***************************************************************************/ + +static SFWriterElem* +S_SFWriterElem_create(MemoryPool *mem_pool, Obj *value, int32_t doc_id) { + size_t size = VTable_Get_Obj_Alloc_Size(SFWRITERELEM); + SFWriterElem *self = (SFWriterElem*)MemPool_Grab(mem_pool, size); + VTable_Init_Obj(SFWRITERELEM, (Obj*)self); + self->value = value; + self->doc_id = doc_id; + return self; +} + +void +SFWriterElem_destroy(SFWriterElem *self) { + UNUSED_VAR(self); + THROW(ERR, "Illegal attempt to destroy SFWriterElem object"); +} + +uint32_t +SFWriterElem_get_refcount(SFWriterElem* self) { + UNUSED_VAR(self); + return 1; +} + +SFWriterElem* +SFWriterElem_inc_refcount(SFWriterElem* self) { + return self; +} + +uint32_t +SFWriterElem_dec_refcount(SFWriterElem* self) { + UNUSED_VAR(self); + return 1; +} http://git-wip-us.apache.org/repos/asf/lucy/blob/c2d48b32/core/Lucy/Index/SortFieldWriter.cfh ---------------------------------------------------------------------- diff --git a/core/Lucy/Index/SortFieldWriter.cfh b/core/Lucy/Index/SortFieldWriter.cfh index 210be85..16fa2a4 100644 --- a/core/Lucy/Index/SortFieldWriter.cfh +++ b/core/Lucy/Index/SortFieldWriter.cfh @@ -99,4 +99,23 @@ class Lucy::Index::SortFieldWriter Destroy(SortFieldWriter *self); } +class Lucy::Index::SortFieldWriter::SFWriterElem inherits Clownfish::Obj { + int32_t doc_id; + Obj *value; + + uint32_t + Get_RefCount(SFWriterElem* self); + + incremented SFWriterElem* + Inc_RefCount(SFWriterElem* self); + + uint32_t + Dec_RefCount(SFWriterElem* self); + + /** Throws an error. + */ + public void + Destroy(SFWriterElem *self); +} +
