Rename some methods in SortExternal. Replace "cache" with "buffer" in a few method names.
Project: http://git-wip-us.apache.org/repos/asf/lucy/repo Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/06ab08d7 Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/06ab08d7 Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/06ab08d7 Branch: refs/heads/sortex_ptr_only Commit: 06ab08d701598b2ac8ae32b0389ca20a0488a345 Parents: 0398aae Author: Marvin Humphrey <[email protected]> Authored: Fri Jan 11 15:06:45 2013 -0800 Committer: Marvin Humphrey <[email protected]> Committed: Fri Jan 11 15:06:45 2013 -0800 ---------------------------------------------------------------------- core/Lucy/Index/PostingPool.c | 16 ++++++++-------- core/Lucy/Index/SortFieldWriter.c | 28 ++++++++++++++-------------- core/Lucy/Index/SortFieldWriter.cfh | 2 +- core/Lucy/Test/Util/BBSortEx.c | 26 +++++++++++++------------- core/Lucy/Test/Util/BBSortEx.cfh | 2 +- core/Lucy/Util/SortExternal.c | 28 ++++++++++++++-------------- core/Lucy/Util/SortExternal.cfh | 8 ++++---- perl/t/015-sort_external.t | 20 ++++++++++---------- 8 files changed, 65 insertions(+), 65 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucy/blob/06ab08d7/core/Lucy/Index/PostingPool.c ---------------------------------------------------------------------- diff --git a/core/Lucy/Index/PostingPool.c b/core/Lucy/Index/PostingPool.c index ff0b5a0..b01ef00 100644 --- a/core/Lucy/Index/PostingPool.c +++ b/core/Lucy/Index/PostingPool.c @@ -186,16 +186,16 @@ PostPool_flip(PostingPool *self) { DECREF(post_temp_path); } - PostPool_Sort_Cache(self); + PostPool_Sort_Buffer(self); if (num_runs && (self->buf_max - self->buf_tick) > 0) { - uint32_t num_items = PostPool_Cache_Count(self); + uint32_t num_items = PostPool_Buffer_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_Grow_Cache(run, num_items); + PostPool_Grow_Buffer(run, num_items); memcpy(run->buffer, (self->buffer + self->buf_tick), num_items * sizeof(Obj*)); run->buf_max = num_items; @@ -254,7 +254,7 @@ PostPool_add_segment(PostingPool *self, SegReader *reader, I32Array *doc_map, void PostPool_flush(PostingPool *self) { // Don't add a run unless we have data to put in it. - if (PostPool_Cache_Count(self) == 0) { return; } + if (PostPool_Buffer_Count(self) == 0) { return; } PostingPool *run = PostPool_new(self->schema, self->snapshot, self->segment, @@ -277,7 +277,7 @@ PostPool_flush(PostingPool *self) { self->lex_temp_out); run->lex_start = OutStream_Tell(self->lex_temp_out); run->post_start = OutStream_Tell(self->post_temp_out); - PostPool_Sort_Cache(self); + PostPool_Sort_Buffer(self); S_write_terms_and_postings(run, post_writer, NULL); run->lex_end = OutStream_Tell(self->lex_temp_out); @@ -289,7 +289,7 @@ PostPool_flush(PostingPool *self) { run->buf_tick = 0; run->buf_max = 0; run->buf_cap = 0; - PostPool_Clear_Cache(self); + PostPool_Clear_Buffer(self); // Add the run to the array. PostPool_Add_Run(self, (SortExternal*)run); @@ -494,7 +494,7 @@ PostPool_refill(PostingPool *self) { // Add to the run's cache. if (num_elems >= self->buf_cap) { size_t new_cap = Memory_oversize(num_elems + 1, sizeof(Obj*)); - PostPool_Grow_Cache(self, new_cap); + PostPool_Grow_Buffer(self, new_cap); } self->buffer[num_elems] = (Obj*)raw_posting; num_elems++; @@ -521,7 +521,7 @@ S_fresh_flip(PostingPool *self, InStream *lex_temp_in, self->flipped = true; // Sort RawPostings in cache, if any. - PostPool_Sort_Cache(self); + PostPool_Sort_Buffer(self); // Bail if never flushed. if (self->lex_end == 0) { return; } http://git-wip-us.apache.org/repos/asf/lucy/blob/06ab08d7/core/Lucy/Index/SortFieldWriter.c ---------------------------------------------------------------------- diff --git a/core/Lucy/Index/SortFieldWriter.c b/core/Lucy/Index/SortFieldWriter.c index 3c78a3f..f780e83 100644 --- a/core/Lucy/Index/SortFieldWriter.c +++ b/core/Lucy/Index/SortFieldWriter.c @@ -125,13 +125,13 @@ SortFieldWriter_init(SortFieldWriter *self, Schema *schema, } void -SortFieldWriter_clear_cache(SortFieldWriter *self) { +SortFieldWriter_clear_buffer(SortFieldWriter *self) { if (self->uniq_vals) { Hash_Clear(self->uniq_vals); } - SortFieldWriter_Clear_Cache_t super_clear_cache - = SUPER_METHOD_PTR(self->vtable, Lucy_SortFieldWriter_Clear_Cache); - super_clear_cache(self); + SortFieldWriter_Clear_Buffer_t super_clear_buffer + = SUPER_METHOD_PTR(self->vtable, Lucy_SortFieldWriter_Clear_Buffer); + super_clear_buffer(self); // Note that we have not called MemPool_Release_All() on our memory pool. // This is because the pool is shared amongst multiple SortFieldWriters // which belong to a parent SortWriter; it is the responsibility of the @@ -361,13 +361,13 @@ S_lazy_init_sorted_ids(SortFieldWriter *self) { void SortFieldWriter_flush(SortFieldWriter *self) { // Don't add a run unless we have data to put in it. - if (SortFieldWriter_Cache_Count(self) == 0) { return; } + if (SortFieldWriter_Buffer_Count(self) == 0) { return; } OutStream *const temp_ord_out = self->temp_ord_out; OutStream *const temp_ix_out = self->temp_ix_out; OutStream *const temp_dat_out = self->temp_dat_out; - SortFieldWriter_Sort_Cache(self); + SortFieldWriter_Sort_Buffer(self); SortFieldWriter *run = SortFieldWriter_new(self->schema, self->snapshot, self->segment, self->polyreader, self->field, self->mem_pool, @@ -397,7 +397,7 @@ SortFieldWriter_flush(SortFieldWriter *self) { run->buf_tick = 0; run->buf_cap = 0; self->buf_tick = self->buf_max; - SortFieldWriter_Clear_Cache(self); + SortFieldWriter_Clear_Buffer(self); // Record stream ends. run->ord_end = OutStream_Tell(temp_ord_out); @@ -415,12 +415,12 @@ SortFieldWriter_refill(SortFieldWriter *self) { if (!self->sort_cache) { return 0; } // Sanity check, then reset the cache and prepare to start loading items. - uint32_t cache_count = SortFieldWriter_Cache_Count(self); - if (cache_count) { + uint32_t buf_count = SortFieldWriter_Buffer_Count(self); + if (buf_count) { THROW(ERR, "Refill called but cache contains %u32 items", - cache_count); + buf_count); } - SortFieldWriter_Clear_Cache(self); + SortFieldWriter_Clear_Buffer(self); MemPool_Release_All(self->mem_pool); S_lazy_init_sorted_ids(self); @@ -460,7 +460,7 @@ SortFieldWriter_refill(SortFieldWriter *self) { self->run_tick++; } self->run_ord++; - SortFieldWriter_Sort_Cache(self); + SortFieldWriter_Sort_Buffer(self); if (self->run_ord >= self->run_cardinality) { DECREF(self->sort_cache); @@ -473,7 +473,7 @@ SortFieldWriter_refill(SortFieldWriter *self) { void SortFieldWriter_flip(SortFieldWriter *self) { - uint32_t num_items = SortFieldWriter_Cache_Count(self); + uint32_t num_items = SortFieldWriter_Buffer_Count(self); uint32_t num_runs = VA_Get_Size(self->runs); if (self->flipped) { THROW(ERR, "Can't call Flip() twice"); } @@ -486,7 +486,7 @@ SortFieldWriter_flip(SortFieldWriter *self) { } if (num_items) { - SortFieldWriter_Sort_Cache(self); + SortFieldWriter_Sort_Buffer(self); } else if (num_runs) { Folder *folder = PolyReader_Get_Folder(self->polyreader); http://git-wip-us.apache.org/repos/asf/lucy/blob/06ab08d7/core/Lucy/Index/SortFieldWriter.cfh ---------------------------------------------------------------------- diff --git a/core/Lucy/Index/SortFieldWriter.cfh b/core/Lucy/Index/SortFieldWriter.cfh index 16fa2a4..598d426 100644 --- a/core/Lucy/Index/SortFieldWriter.cfh +++ b/core/Lucy/Index/SortFieldWriter.cfh @@ -87,7 +87,7 @@ class Lucy::Index::SortFieldWriter Compare(SortFieldWriter *self, void *va, void *vb); void - Clear_Cache(SortFieldWriter *self); + Clear_Buffer(SortFieldWriter *self); int32_t Get_Null_Ord(SortFieldWriter *self); http://git-wip-us.apache.org/repos/asf/lucy/blob/06ab08d7/core/Lucy/Test/Util/BBSortEx.c ---------------------------------------------------------------------- diff --git a/core/Lucy/Test/Util/BBSortEx.c b/core/Lucy/Test/Util/BBSortEx.c index 5e08b1f..943b7f1 100644 --- a/core/Lucy/Test/Util/BBSortEx.c +++ b/core/Lucy/Test/Util/BBSortEx.c @@ -47,11 +47,11 @@ BBSortEx_destroy(BBSortEx *self) { } void -BBSortEx_clear_cache(BBSortEx *self) { +BBSortEx_clear_buffer(BBSortEx *self) { self->mem_consumed = 0; - BBSortEx_Clear_Cache_t super_clear_cache - = SUPER_METHOD_PTR(self->vtable, Lucy_BBSortEx_Clear_Cache); - super_clear_cache(self); + BBSortEx_Clear_Buffer_t super_clear_buffer + = SUPER_METHOD_PTR(self->vtable, Lucy_BBSortEx_Clear_Buffer); + super_clear_buffer(self); } void @@ -70,15 +70,15 @@ BBSortEx_feed(BBSortEx *self, Obj *item) { void BBSortEx_flush(BBSortEx *self) { - uint32_t cache_count = self->buf_max - self->buf_tick; + uint32_t buf_count = self->buf_max - self->buf_tick; Obj **buffer = self->buffer; VArray *elems; - if (!cache_count) { return; } - else { elems = VA_new(cache_count); } + if (!buf_count) { return; } + else { elems = VA_new(buf_count); } // Sort, then create a new run. - BBSortEx_Sort_Cache(self); + BBSortEx_Sort_Buffer(self); for (uint32_t i = self->buf_tick; i < self->buf_max; i++) { VA_Push(elems, buffer[i]); } @@ -87,8 +87,8 @@ BBSortEx_flush(BBSortEx *self) { BBSortEx_Add_Run(self, (SortExternal*)run); // Blank the cache vars. - self->buf_tick += cache_count; - BBSortEx_Clear_Cache(self); + self->buf_tick += buf_count; + BBSortEx_Clear_Buffer(self); } uint32_t @@ -120,9 +120,9 @@ BBSortEx_refill(BBSortEx *self) { } if (self->buf_max == self->buf_cap) { - BBSortEx_Grow_Cache(self, - Memory_oversize(self->buf_max + 1, - sizeof(Obj*))); + BBSortEx_Grow_Buffer(self, + Memory_oversize(self->buf_max + 1, + sizeof(Obj*))); } self->buffer[self->buf_max++] = INCREF(elem); } http://git-wip-us.apache.org/repos/asf/lucy/blob/06ab08d7/core/Lucy/Test/Util/BBSortEx.cfh ---------------------------------------------------------------------- diff --git a/core/Lucy/Test/Util/BBSortEx.cfh b/core/Lucy/Test/Util/BBSortEx.cfh index be097e6..759c04d 100644 --- a/core/Lucy/Test/Util/BBSortEx.cfh +++ b/core/Lucy/Test/Util/BBSortEx.cfh @@ -43,7 +43,7 @@ class Lucy::Test::Util::BBSortEx Refill(BBSortEx *self); void - Clear_Cache(BBSortEx *self); + Clear_Buffer(BBSortEx *self); void Flip(BBSortEx *self); http://git-wip-us.apache.org/repos/asf/lucy/blob/06ab08d7/core/Lucy/Util/SortExternal.c ---------------------------------------------------------------------- diff --git a/core/Lucy/Util/SortExternal.c b/core/Lucy/Util/SortExternal.c index c3242c6..37eba61 100644 --- a/core/Lucy/Util/SortExternal.c +++ b/core/Lucy/Util/SortExternal.c @@ -63,7 +63,7 @@ SortEx_destroy(SortExternal *self) { FREEMEM(self->slice_sizes); FREEMEM(self->slice_starts); if (self->buffer) { - SortEx_Clear_Cache(self); + SortEx_Clear_Buffer(self); FREEMEM(self->buffer); } DECREF(self->runs); @@ -71,7 +71,7 @@ SortEx_destroy(SortExternal *self) { } void -SortEx_clear_cache(SortExternal *self) { +SortEx_clear_buffer(SortExternal *self) { Obj **const buffer = self->buffer; for (uint32_t i = self->buf_tick, max = self->buf_max; i < max; i++) { DECREF(buffer[i]); @@ -84,7 +84,7 @@ void SortEx_feed(SortExternal *self, Obj *item) { if (self->buf_max == self->buf_cap) { size_t amount = Memory_oversize(self->buf_max + 1, sizeof(Obj*)); - SortEx_Grow_Cache(self, amount); + SortEx_Grow_Buffer(self, amount); } self->buffer[self->buf_max] = item; self->buf_max++; @@ -117,9 +117,9 @@ SortEx_peek(SortExternal *self) { } void -SortEx_sort_cache(SortExternal *self) { +SortEx_sort_buffer(SortExternal *self) { if (self->buf_tick != 0) { - THROW(ERR, "Cant Sort_Cache() after fetching %u32 items", self->buf_tick); + THROW(ERR, "Cant Sort_Buffer() after fetching %u32 items", self->buf_tick); } if (self->buf_max != 0) { VTable *vtable = SortEx_Get_VTable(self); @@ -157,16 +157,16 @@ SortEx_add_run(SortExternal *self, SortExternal *run) { void SortEx_shrink(SortExternal *self) { if (self->buf_max - self->buf_tick > 0) { - size_t cache_count = SortEx_Cache_Count(self); - size_t size = cache_count * sizeof(Obj*); + size_t buf_count = SortEx_Buffer_Count(self); + size_t size = buf_count * sizeof(Obj*); if (self->buf_tick > 0) { Obj **start = self->buffer + self->buf_tick; memmove(self->buffer, start, size); } self->buffer = (Obj**)REALLOCATE(self->buffer, size); self->buf_tick = 0; - self->buf_max = cache_count; - self->buf_cap = cache_count; + self->buf_max = buf_count; + self->buf_cap = buf_count; } else { FREEMEM(self->buffer); @@ -188,13 +188,13 @@ SortEx_shrink(SortExternal *self) { static void S_refill_cache(SortExternal *self) { // Reset cache vars. - SortEx_Clear_Cache(self); + SortEx_Clear_Buffer(self); // Make sure all runs have at least one item in the cache. uint32_t i = 0; while (i < VA_Get_Size(self->runs)) { SortExternal *const run = (SortExternal*)VA_Fetch(self->runs, i); - if (SortEx_Cache_Count(run) > 0 || SortEx_Refill(run) > 0) { + if (SortEx_Buffer_Count(run) > 0 || SortEx_Refill(run) > 0) { i++; // Run has some elements, so keep. } else { @@ -261,7 +261,7 @@ S_absorb_slices(SortExternal *self, Obj **endpost) { if (self->buf_max + slice_size > self->buf_cap) { size_t cap = Memory_oversize(self->buf_max + slice_size, sizeof(Obj*)); - SortEx_Grow_Cache(self, cap); + SortEx_Grow_Buffer(self, cap); } memcpy(self->buffer + self->buf_max, run->buffer + run->buf_tick, @@ -323,7 +323,7 @@ S_absorb_slices(SortExternal *self, Obj **endpost) { } void -SortEx_grow_cache(SortExternal *self, uint32_t size) { +SortEx_grow_buffer(SortExternal *self, uint32_t size) { if (size > self->buf_cap) { self->buffer = (Obj**)REALLOCATE(self->buffer, size * sizeof(Obj*)); self->buf_cap = size; @@ -358,7 +358,7 @@ SortEx_set_mem_thresh(SortExternal *self, uint32_t mem_thresh) { } uint32_t -SortEx_cache_count(SortExternal *self) { +SortEx_buffer_count(SortExternal *self) { return self->buf_max - self->buf_tick; } http://git-wip-us.apache.org/repos/asf/lucy/blob/06ab08d7/core/Lucy/Util/SortExternal.cfh ---------------------------------------------------------------------- diff --git a/core/Lucy/Util/SortExternal.cfh b/core/Lucy/Util/SortExternal.cfh index 5c6b3f7..988f61a 100644 --- a/core/Lucy/Util/SortExternal.cfh +++ b/core/Lucy/Util/SortExternal.cfh @@ -109,7 +109,7 @@ abstract class Lucy::Util::SortExternal cnick SortEx /** Sort all items currently in the main cache. */ void - Sort_Cache(SortExternal *self); + Sort_Buffer(SortExternal *self); /** Reset cache variables so that cache gives the appearance of having * been initialized. @@ -117,17 +117,17 @@ abstract class Lucy::Util::SortExternal cnick SortEx * Subclasses may take steps to release items held in cache, if any. */ void - Clear_Cache(SortExternal *self); + Clear_Buffer(SortExternal *self); /** Return the number of items presently in the cache. */ uint32_t - Cache_Count(SortExternal *self); + Buffer_Count(SortExternal *self); /** Allocate more memory to the cache. */ void - Grow_Cache(SortExternal *self, uint32_t new_cache_cap); + Grow_Buffer(SortExternal *self, uint32_t new_cache_cap); void Set_Mem_Thresh(SortExternal *self, uint32_t mem_thresh); http://git-wip-us.apache.org/repos/asf/lucy/blob/06ab08d7/perl/t/015-sort_external.t ---------------------------------------------------------------------- diff --git a/perl/t/015-sort_external.t b/perl/t/015-sort_external.t index 4d8bdad..6be56e1 100644 --- a/perl/t/015-sort_external.t +++ b/perl/t/015-sort_external.t @@ -21,24 +21,24 @@ use List::Util qw( shuffle ); use Lucy::Test; use bytes qw(); -my ( $sortex, $cache, @orig, @sort_output ); +my ( $sortex, $buffer, @orig, @sort_output ); $sortex = Lucy::Test::Util::BBSortEx->new( mem_thresh => 4 ); $sortex->feed( new_bytebuf('c') ); -is( $sortex->cache_count, 1, "feed elem into cache" ); +is( $sortex->buffer_count, 1, "feed elem into buffer" ); $sortex->feed( new_bytebuf('b') ); $sortex->feed( new_bytebuf('d') ); -$sortex->sort_cache; +$sortex->sort_buffer; SKIP: { skip( "Restore when porting test to C", 1 ); - $cache = $sortex->_peek_cache; - is_deeply( $cache, [qw( b c d )], "sort cache" ); + $buffer = $sortex->_peek_buffer; + is_deeply( $buffer, [qw( b c d )], "sort buffer" ); } $sortex->feed( new_bytebuf('a') ); -is( $sortex->cache_count, 0, - "cache flushed automatically when mem_thresh crossed" ); +is( $sortex->buffer_count, 0, + "buffer flushed automatically when mem_thresh crossed" ); #is( $sortex->get_num_runs, 1, "run added" ); my @bytebufs = map { new_bytebuf($_) } qw( x y z ); @@ -55,8 +55,8 @@ is_deeply( \@sort_output, \@orig, "Add_Run" ); $sortex = Lucy::Test::Util::BBSortEx->new( mem_thresh => 4 ); $sortex->feed( new_bytebuf('c') ); -$sortex->clear_cache; -is( $sortex->cache_count, 0, "Clear_Cache" ); +$sortex->clear_buffer; +is( $sortex->buffer_count, 0, "Clear_Buffer" ); $sortex->feed( new_bytebuf('b') ); $sortex->feed( new_bytebuf('a') ); $sortex->flush; @@ -68,7 +68,7 @@ while ( defined( my $result = $sortex->fetch ) ) { push @sort_output, $result; } is_deeply( \@sort_output, \@orig, - "elements cleared via Clear_Cache truly cleared" ); + "elements cleared via Clear_Buffer truly cleared" ); @orig = (); @sort_output = ();
