lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject [lucy-commits] [1/3] git commit: refs/heads/sortex_ptr_only - Rename some vars in SortExternal.
Date Thu, 17 Jan 2013 23:15:48 GMT
Rename some vars in SortExternal.

Use "buffer" instead of "cache", plus "buf_max" instead "cache_max",
etc.


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

Branch: refs/heads/sortex_ptr_only
Commit: 0398aae4b1e05a3be920144f9263a7c6a87bff48
Parents: 22d40ec
Author: Marvin Humphrey <marvin@rectangular.com>
Authored: Wed Jan 9 13:14:00 2013 -0800
Committer: Marvin Humphrey <marvin@rectangular.com>
Committed: Wed Jan 9 16:23:52 2013 -0800

----------------------------------------------------------------------
 core/Lucy/Index/PostingPool.c     |   42 ++++++------
 core/Lucy/Index/SortFieldWriter.c |   18 +++---
 core/Lucy/Test/Util/BBSortEx.c    |   26 ++++----
 core/Lucy/Util/SortExternal.c     |  122 ++++++++++++++++----------------
 core/Lucy/Util/SortExternal.cfh   |    8 +-
 5 files changed, 108 insertions(+), 108 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/0398aae4/core/Lucy/Index/PostingPool.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/PostingPool.c b/core/Lucy/Index/PostingPool.c
index 1092310..ff0b5a0 100644
--- a/core/Lucy/Index/PostingPool.c
+++ b/core/Lucy/Index/PostingPool.c
@@ -187,7 +187,7 @@ PostPool_flip(PostingPool *self) {
     }
 
     PostPool_Sort_Cache(self);
-    if (num_runs && (self->cache_max - self->cache_tick) > 0) {
+    if (num_runs && (self->buf_max - self->buf_tick) > 0) {
         uint32_t num_items = PostPool_Cache_Count(self);
         // Cheap imitation of flush. FIXME.
         PostingPool *run
@@ -196,12 +196,12 @@ PostPool_flip(PostingPool *self) {
                            self->mem_pool, self->lex_temp_out,
                            self->post_temp_out, self->skip_out);
         PostPool_Grow_Cache(run, num_items);
-        memcpy(run->cache, (self->cache + self->cache_tick),
+        memcpy(run->buffer, (self->buffer + self->buf_tick),
                num_items * sizeof(Obj*));
-        run->cache_max = num_items;
+        run->buf_max = num_items;
         PostPool_Add_Run(self, (SortExternal*)run);
-        self->cache_tick = 0;
-        self->cache_max = 0;
+        self->buf_tick = 0;
+        self->buf_max = 0;
     }
 
     // Assign.
@@ -267,10 +267,10 @@ PostPool_flush(PostingPool *self) {
                                             self->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->buffer   = self->buffer;
+    run->buf_tick = self->buf_tick;
+    run->buf_max  = self->buf_max;
+    run->buf_cap  = self->buf_cap;
 
     // Write to temp files.
     LexWriter_Enter_Temp_Mode(self->lex_writer, self->field,
@@ -285,10 +285,10 @@ PostPool_flush(PostingPool *self) {
     LexWriter_Leave_Temp_Mode(self->lex_writer);
 
     // Return the cache and empty it.
-    run->cache      = NULL;
-    run->cache_tick = 0;
-    run->cache_max  = 0;
-    run->cache_cap  = 0;
+    run->buffer   = NULL;
+    run->buf_tick = 0;
+    run->buf_max  = 0;
+    run->buf_cap  = 0;
     PostPool_Clear_Cache(self);
 
     // Add the run to the array.
@@ -437,12 +437,12 @@ PostPool_refill(PostingPool *self) {
     else { term_text = (CharBuf*)Lex_Get_Term(lexicon); }
 
     // Make sure cache is empty.
-    if (self->cache_max - self->cache_tick > 0) {
+    if (self->buf_max - self->buf_tick > 0) {
         THROW(ERR, "Refill called but cache contains %u32 items",
-              self->cache_max - self->cache_tick);
+              self->buf_max - self->buf_tick);
     }
-    self->cache_max  = 0;
-    self->cache_tick = 0;
+    self->buf_max  = 0;
+    self->buf_tick = 0;
 
     // Ditch old MemoryPool and get another.
     DECREF(self->mem_pool);
@@ -492,17 +492,17 @@ PostPool_refill(PostingPool *self) {
         }
 
         // Add to the run's cache.
-        if (num_elems >= self->cache_cap) {
+        if (num_elems >= self->buf_cap) {
             size_t new_cap = Memory_oversize(num_elems + 1, sizeof(Obj*));
             PostPool_Grow_Cache(self, new_cap);
         }
-        self->cache[num_elems] = (Obj*)raw_posting;
+        self->buffer[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;
+    self->buf_max  = num_elems;
+    self->buf_tick = 0;
 
     return num_elems;
 }

http://git-wip-us.apache.org/repos/asf/lucy/blob/0398aae4/core/Lucy/Index/SortFieldWriter.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/SortFieldWriter.c b/core/Lucy/Index/SortFieldWriter.c
index 545b031..3c78a3f 100644
--- a/core/Lucy/Index/SortFieldWriter.c
+++ b/core/Lucy/Index/SortFieldWriter.c
@@ -381,10 +381,10 @@ SortFieldWriter_flush(SortFieldWriter *self) {
     run->dat_start = OutStream_Align(temp_dat_out, sizeof(int64_t));
 
     // Have the run borrow the array of elems.
-    run->cache      = self->cache;
-    run->cache_max  = self->cache_max;
-    run->cache_tick = self->cache_tick;
-    run->cache_cap  = self->cache_cap;
+    run->buffer   = self->buffer;
+    run->buf_max  = self->buf_max;
+    run->buf_tick = self->buf_tick;
+    run->buf_cap  = self->buf_cap;
 
     // Write files, record stats.
     run->run_max = (int32_t)Seg_Get_Count(self->segment);
@@ -392,11 +392,11 @@ SortFieldWriter_flush(SortFieldWriter *self) {
                                          temp_dat_out);
 
     // Reclaim the buffer from the run and empty it.
-    run->cache       = NULL;
-    run->cache_max   = 0;
-    run->cache_tick  = 0;
-    run->cache_cap   = 0;
-    self->cache_tick = self->cache_max;
+    run->buffer    = NULL;
+    run->buf_max   = 0;
+    run->buf_tick  = 0;
+    run->buf_cap   = 0;
+    self->buf_tick = self->buf_max;
     SortFieldWriter_Clear_Cache(self);
 
     // Record stream ends.

http://git-wip-us.apache.org/repos/asf/lucy/blob/0398aae4/core/Lucy/Test/Util/BBSortEx.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Test/Util/BBSortEx.c b/core/Lucy/Test/Util/BBSortEx.c
index 24ed70f..5e08b1f 100644
--- a/core/Lucy/Test/Util/BBSortEx.c
+++ b/core/Lucy/Test/Util/BBSortEx.c
@@ -70,8 +70,8 @@ BBSortEx_feed(BBSortEx *self, Obj *item) {
 
 void
 BBSortEx_flush(BBSortEx *self) {
-    uint32_t     cache_count = self->cache_max - self->cache_tick;
-    Obj        **cache = self->cache;
+    uint32_t     cache_count = self->buf_max - self->buf_tick;
+    Obj        **buffer = self->buffer;
     VArray      *elems;
 
     if (!cache_count) { return; }
@@ -79,27 +79,27 @@ BBSortEx_flush(BBSortEx *self) {
 
     // Sort, then create a new run.
     BBSortEx_Sort_Cache(self);
-    for (uint32_t i = self->cache_tick; i < self->cache_max; i++) {
-        VA_Push(elems, cache[i]);
+    for (uint32_t i = self->buf_tick; i < self->buf_max; i++) {
+        VA_Push(elems, buffer[i]);
     }
     BBSortEx *run = BBSortEx_new(0, elems);
     DECREF(elems);
     BBSortEx_Add_Run(self, (SortExternal*)run);
 
     // Blank the cache vars.
-    self->cache_tick += cache_count;
+    self->buf_tick += cache_count;
     BBSortEx_Clear_Cache(self);
 }
 
 uint32_t
 BBSortEx_refill(BBSortEx *self) {
     // Make sure cache is empty, then set cache tick vars.
-    if (self->cache_max - self->cache_tick > 0) {
+    if (self->buf_max - self->buf_tick > 0) {
         THROW(ERR, "Refill called but cache contains %u32 items",
-              self->cache_max - self->cache_tick);
+              self->buf_max - self->buf_tick);
     }
-    self->cache_tick = 0;
-    self->cache_max  = 0;
+    self->buf_tick = 0;
+    self->buf_max  = 0;
 
     // Read in elements.
     while (1) {
@@ -119,15 +119,15 @@ BBSortEx_refill(BBSortEx *self) {
             self->mem_consumed += BB_Get_Size(elem);
         }
 
-        if (self->cache_max == self->cache_cap) {
+        if (self->buf_max == self->buf_cap) {
             BBSortEx_Grow_Cache(self,
-                                Memory_oversize(self->cache_max + 1,
+                                Memory_oversize(self->buf_max + 1,
                                                 sizeof(Obj*)));
         }
-        self->cache[self->cache_max++] = INCREF(elem);
+        self->buffer[self->buf_max++] = INCREF(elem);
     }
 
-    return self->cache_max;
+    return self->buf_max;
 }
 
 void

http://git-wip-us.apache.org/repos/asf/lucy/blob/0398aae4/core/Lucy/Util/SortExternal.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Util/SortExternal.c b/core/Lucy/Util/SortExternal.c
index 1e7e143..c3242c6 100644
--- a/core/Lucy/Util/SortExternal.c
+++ b/core/Lucy/Util/SortExternal.c
@@ -41,10 +41,10 @@ S_find_slice_size(SortExternal *self, Obj **endpost);
 SortExternal*
 SortEx_init(SortExternal *self) {
     self->mem_thresh   = UINT32_MAX;
-    self->cache        = NULL;
-    self->cache_cap    = 0;
-    self->cache_max    = 0;
-    self->cache_tick   = 0;
+    self->buffer       = NULL;
+    self->buf_cap      = 0;
+    self->buf_max      = 0;
+    self->buf_tick     = 0;
     self->scratch      = NULL;
     self->scratch_cap  = 0;
     self->runs         = VA_new(0);
@@ -62,9 +62,9 @@ SortEx_destroy(SortExternal *self) {
     FREEMEM(self->scratch);
     FREEMEM(self->slice_sizes);
     FREEMEM(self->slice_starts);
-    if (self->cache) {
+    if (self->buffer) {
         SortEx_Clear_Cache(self);
-        FREEMEM(self->cache);
+        FREEMEM(self->buffer);
     }
     DECREF(self->runs);
     SUPER_DESTROY(self, SORTEXTERNAL);
@@ -72,32 +72,32 @@ SortEx_destroy(SortExternal *self) {
 
 void
 SortEx_clear_cache(SortExternal *self) {
-    Obj **const cache = self->cache;
-    for (uint32_t i = self->cache_tick, max = self->cache_max; i < max; i++) {
-        DECREF(cache[i]);
+    Obj **const buffer = self->buffer;
+    for (uint32_t i = self->buf_tick, max = self->buf_max; i < max; i++) {
+        DECREF(buffer[i]);
     }
-    self->cache_max    = 0;
-    self->cache_tick   = 0;
+    self->buf_max  = 0;
+    self->buf_tick = 0;
 }
 
 void
 SortEx_feed(SortExternal *self, Obj *item) {
-    if (self->cache_max == self->cache_cap) {
-        size_t amount = Memory_oversize(self->cache_max + 1, sizeof(Obj*));
+    if (self->buf_max == self->buf_cap) {
+        size_t amount = Memory_oversize(self->buf_max + 1, sizeof(Obj*));
         SortEx_Grow_Cache(self, amount);
     }
-    self->cache[self->cache_max] = item;
-    self->cache_max++;
+    self->buffer[self->buf_max] = item;
+    self->buf_max++;
 }
 
 static INLINE Obj*
 SI_peek(SortExternal *self) {
-    if (self->cache_tick >= self->cache_max) {
+    if (self->buf_tick >= self->buf_max) {
         S_refill_cache(self);
     }
 
-    if (self->cache_max > 0) {
-        return self->cache[self->cache_tick];
+    if (self->buf_max > 0) {
+        return self->buffer[self->buf_tick];
     }
     else {
         return NULL;
@@ -107,7 +107,7 @@ SI_peek(SortExternal *self) {
 Obj*
 SortEx_fetch(SortExternal *self) {
     Obj *item = SI_peek(self);
-    self->cache_tick++;
+    self->buf_tick++;
     return item;
 }
 
@@ -118,20 +118,20 @@ SortEx_peek(SortExternal *self) {
 
 void
 SortEx_sort_cache(SortExternal *self) {
-    if (self->cache_tick != 0) {
-        THROW(ERR, "Cant Sort_Cache() after fetching %u32 items", self->cache_tick);
+    if (self->buf_tick != 0) {
+        THROW(ERR, "Cant Sort_Cache() after fetching %u32 items", self->buf_tick);
     }
-    if (self->cache_max != 0) {
+    if (self->buf_max != 0) {
         VTable *vtable = SortEx_Get_VTable(self);
         Lucy_Sort_Compare_t compare
             = (Lucy_Sort_Compare_t)METHOD_PTR(vtable, Lucy_SortEx_Compare);
-        if (self->scratch_cap < self->cache_cap) {
-            self->scratch_cap = self->cache_cap;
+        if (self->scratch_cap < self->buf_cap) {
+            self->scratch_cap = self->buf_cap;
             self->scratch = (Obj**)REALLOCATE(
                                 self->scratch,
                                 self->scratch_cap * sizeof(Obj*));
         }
-        Sort_mergesort(self->cache, self->scratch, self->cache_max,
+        Sort_mergesort(self->buffer, self->scratch, self->buf_max,
                        sizeof(Obj*), compare, self);
     }
 }
@@ -156,24 +156,24 @@ SortEx_add_run(SortExternal *self, SortExternal *run) {
 
 void
 SortEx_shrink(SortExternal *self) {
-    if (self->cache_max - self->cache_tick > 0) {
+    if (self->buf_max - self->buf_tick > 0) {
         size_t cache_count = SortEx_Cache_Count(self);
         size_t size        = cache_count * sizeof(Obj*);
-        if (self->cache_tick > 0) {
-            Obj **start = self->cache + self->cache_tick;
-            memmove(self->cache, start, size);
+        if (self->buf_tick > 0) {
+            Obj **start = self->buffer + self->buf_tick;
+            memmove(self->buffer, start, size);
         }
-        self->cache      = (Obj**)REALLOCATE(self->cache, size);
-        self->cache_tick = 0;
-        self->cache_max  = cache_count;
-        self->cache_cap  = cache_count;
+        self->buffer   = (Obj**)REALLOCATE(self->buffer, size);
+        self->buf_tick = 0;
+        self->buf_max  = cache_count;
+        self->buf_cap  = cache_count;
     }
     else {
-        FREEMEM(self->cache);
-        self->cache      = NULL;
-        self->cache_tick = 0;
-        self->cache_max  = 0;
-        self->cache_cap  = 0;
+        FREEMEM(self->buffer);
+        self->buffer   = NULL;
+        self->buf_tick = 0;
+        self->buf_max  = 0;
+        self->buf_cap  = 0;
     }
     self->scratch_cap = 0;
     FREEMEM(self->scratch);
@@ -216,15 +216,15 @@ S_find_endpost(SortExternal *self) {
     for (uint32_t i = 0, max = VA_Get_Size(self->runs); i < max; i++) {
         // Get a run and retrieve the last item in its cache.
         SortExternal *const run = (SortExternal*)VA_Fetch(self->runs, i);
-        const uint32_t tick = run->cache_max - 1;
-        if (tick >= run->cache_cap || run->cache_max < 1) {
+        const uint32_t tick = run->buf_max - 1;
+        if (tick >= run->buf_cap || run->buf_max < 1) {
             THROW(ERR, "Invalid SortExternal cache access: %u32 %u32 %u32", tick,
-                  run->cache_max, run->cache_cap);
+                  run->buf_max, run->buf_cap);
         }
         else {
             // Cache item with the highest sort value currently held in memory
             // by the run.
-            Obj **candidate = run->cache + tick;
+            Obj **candidate = run->buffer + tick;
 
             // If it's the first run, item is automatically the new endpost.
             if (i == 0) {
@@ -249,7 +249,7 @@ S_absorb_slices(SortExternal *self, Obj **endpost) {
     Lucy_Sort_Compare_t compare
         = (Lucy_Sort_Compare_t)METHOD_PTR(vtable, Lucy_SortEx_Compare);
 
-    if (self->cache_max != 0) { THROW(ERR, "Can't refill unless empty"); }
+    if (self->buf_max != 0) { THROW(ERR, "Can't refill unless empty"); }
 
     // Move all the elements in range into the main cache as slices.
     for (uint32_t i = 0; i < num_runs; i++) {
@@ -258,16 +258,16 @@ S_absorb_slices(SortExternal *self, Obj **endpost) {
 
         if (slice_size) {
             // Move slice content from run cache to main cache.
-            if (self->cache_max + slice_size > self->cache_cap) {
-                size_t cap = Memory_oversize(self->cache_max + slice_size,
+            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);
             }
-            memcpy(self->cache + self->cache_max,
-                   run->cache + run->cache_tick,
+            memcpy(self->buffer + self->buf_max,
+                   run->buffer + run->buf_tick,
                    slice_size * sizeof(Obj*));
-            run->cache_tick += slice_size;
-            self->cache_max += slice_size;
+            run->buf_tick += slice_size;
+            self->buf_max += slice_size;
 
             // Track number of slices and slice sizes.
             slice_sizes[self->num_slices++] = slice_size;
@@ -277,14 +277,14 @@ S_absorb_slices(SortExternal *self, Obj **endpost) {
     // Transform slice starts from ticks to pointers.
     uint32_t total = 0;
     for (uint32_t i = 0; i < self->num_slices; i++) {
-        slice_starts[i] = self->cache + total;
+        slice_starts[i] = self->buffer + total;
         total += slice_sizes[i];
     }
 
     // The main cache now consists of several slices.  Sort the main cache,
     // but exploit the fact that each slice is already sorted.
-    if (self->scratch_cap < self->cache_cap) {
-        self->scratch_cap = self->cache_cap;
+    if (self->scratch_cap < self->buf_cap) {
+        self->scratch_cap = self->buf_cap;
         self->scratch = (Obj**)REALLOCATE(
                             self->scratch, self->scratch_cap * sizeof(Obj*));
     }
@@ -324,24 +324,24 @@ S_absorb_slices(SortExternal *self, Obj **endpost) {
 
 void
 SortEx_grow_cache(SortExternal *self, uint32_t size) {
-    if (size > self->cache_cap) {
-        self->cache = (Obj**)REALLOCATE(self->cache, size * sizeof(Obj*));
-        self->cache_cap = size;
+    if (size > self->buf_cap) {
+        self->buffer = (Obj**)REALLOCATE(self->buffer, size * sizeof(Obj*));
+        self->buf_cap = size;
     }
 }
 
 static uint32_t
 S_find_slice_size(SortExternal *self, Obj **endpost) {
-    int32_t          lo      = self->cache_tick - 1;
-    int32_t          hi      = self->cache_max;
-    Obj            **cache   = self->cache;
+    int32_t          lo     = self->buf_tick - 1;
+    int32_t          hi     = self->buf_max;
+    Obj            **buffer = self->buffer;
     SortEx_Compare_t compare
         = METHOD_PTR(SortEx_Get_VTable(self), Lucy_SortEx_Compare);
 
     // Binary search.
     while (hi - lo > 1) {
         const int32_t mid   = lo + ((hi - lo) / 2);
-        const int32_t delta = compare(self, cache + mid, endpost);
+        const int32_t delta = compare(self, buffer + mid, endpost);
         if (delta > 0) { hi = mid; }
         else           { lo = mid; }
     }
@@ -349,7 +349,7 @@ S_find_slice_size(SortExternal *self, Obj **endpost) {
     // If lo is still -1, we didn't find anything.
     return lo == -1
            ? 0
-           : (lo - self->cache_tick) + 1;
+           : (lo - self->buf_tick) + 1;
 }
 
 void
@@ -359,7 +359,7 @@ SortEx_set_mem_thresh(SortExternal *self, uint32_t mem_thresh) {
 
 uint32_t
 SortEx_cache_count(SortExternal *self) {
-    return self->cache_max - self->cache_tick;
+    return self->buf_max - self->buf_tick;
 }
 
 

http://git-wip-us.apache.org/repos/asf/lucy/blob/0398aae4/core/Lucy/Util/SortExternal.cfh
----------------------------------------------------------------------
diff --git a/core/Lucy/Util/SortExternal.cfh b/core/Lucy/Util/SortExternal.cfh
index 1288f2e..5c6b3f7 100644
--- a/core/Lucy/Util/SortExternal.cfh
+++ b/core/Lucy/Util/SortExternal.cfh
@@ -38,10 +38,10 @@ parcel Lucy;
 abstract class Lucy::Util::SortExternal cnick SortEx
     inherits Clownfish::Obj {
 
-    Obj          **cache;
-    uint32_t       cache_cap;
-    uint32_t       cache_max;
-    uint32_t       cache_tick;
+    Obj          **buffer;
+    uint32_t       buf_cap;
+    uint32_t       buf_max;
+    uint32_t       buf_tick;
     Obj          **scratch;
     uint32_t       scratch_cap;
     VArray        *runs;


Mime
View raw message