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 2014/06/18 03:06:23 UTC

[lucy-commits] [01/16] git commit: refs/heads/master - Implement Compare_To() for RawPosting.

Repository: lucy
Updated Branches:
  refs/heads/master d4282a9a2 -> c15909359


Implement Compare_To() for RawPosting.


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

Branch: refs/heads/master
Commit: e6d1963ab2e5b9a5c394ff3639a4559cc5b20e0b
Parents: d4282a9
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Wed Jan 2 17:43:16 2013 -0800
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Sat Apr 26 08:56:54 2014 -0700

----------------------------------------------------------------------
 core/Lucy/Index/Posting/RawPosting.c   | 22 ++++++++++++++++++++++
 core/Lucy/Index/Posting/RawPosting.cfh |  3 +++
 2 files changed, 25 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/e6d1963a/core/Lucy/Index/Posting/RawPosting.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/Posting/RawPosting.c b/core/Lucy/Index/Posting/RawPosting.c
index 5f5e8d4..d02cae2 100644
--- a/core/Lucy/Index/Posting/RawPosting.c
+++ b/core/Lucy/Index/Posting/RawPosting.c
@@ -51,6 +51,28 @@ RawPost_Destroy_IMP(RawPosting *self) {
     THROW(ERR, "Illegal attempt to destroy RawPosting object");
 }
 
+int32_t
+RawPost_Compare_To_IMP(RawPosting *self, Obj *other) {
+    RawPostingIVARS *const ivars = RawPost_IVARS(self);
+    RawPostingIVARS *const ovars = RawPost_IVARS((RawPosting*)other);
+    const size_t my_len    = ivars->content_len;
+    const size_t other_len = ovars->content_len;
+    const size_t len       = my_len < other_len ? my_len : other_len;
+    int32_t comparison = memcmp(ivars->blob, ovars->blob, len);
+
+    if (comparison == 0) {
+        // If a is a substring of b, it's less than b, so return a neg num.
+        comparison = (int32_t)((int64_t)my_len - (int64_t)other_len);
+
+        // Break ties by doc id.
+        if (comparison == 0) {
+            comparison = ivars->doc_id - ovars->doc_id;
+        }
+    }
+
+    return comparison;
+}
+
 uint32_t
 RawPost_Get_RefCount_IMP(RawPosting* self) {
     UNUSED_VAR(self);

http://git-wip-us.apache.org/repos/asf/lucy/blob/e6d1963a/core/Lucy/Index/Posting/RawPosting.cfh
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/Posting/RawPosting.cfh b/core/Lucy/Index/Posting/RawPosting.cfh
index b57c285..2fe0286 100644
--- a/core/Lucy/Index/Posting/RawPosting.cfh
+++ b/core/Lucy/Index/Posting/RawPosting.cfh
@@ -59,6 +59,9 @@ class Lucy::Index::RawPosting nickname RawPost
     uint32_t
     Dec_RefCount(RawPosting* self);
 
+    public int32_t
+    Compare_To(RawPosting *self, Obj *other);
+
     /** Throws an error.
      */
     public void


[lucy-commits] [03/16] git commit: refs/heads/master - Eliminate `width` member from SortExternal.

Posted by ma...@apache.org.
Eliminate `width` member from SortExternal.

Remove `width` as a constructor argument and member variable from
SortExternal and its subclasses, replacing it with hard-coded
"sizeof(Obj*)" as needed.


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

Branch: refs/heads/master
Commit: 8369f5f2a6732b32ff730e1f6f6c12b8065d72a5
Parents: 0bf76df
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Fri Jan 4 13:10:56 2013 -0800
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Sat Apr 26 10:19:34 2014 -0700

----------------------------------------------------------------------
 core/Lucy/Index/PostingPool.c     |  2 +-
 core/Lucy/Index/SortFieldWriter.c |  2 +-
 core/Lucy/Util/BBSortEx.c         |  5 ++--
 core/Lucy/Util/SortExternal.c     | 43 ++++++++++++++--------------------
 core/Lucy/Util/SortExternal.cfh   |  3 +--
 5 files changed, 24 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/8369f5f2/core/Lucy/Index/PostingPool.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/PostingPool.c b/core/Lucy/Index/PostingPool.c
index 6cf0d40..57067f2 100644
--- a/core/Lucy/Index/PostingPool.c
+++ b/core/Lucy/Index/PostingPool.c
@@ -76,7 +76,7 @@ PostPool_init(PostingPool *self, Schema *schema, Snapshot *snapshot,
               OutStream *lex_temp_out, OutStream *post_temp_out,
               OutStream *skip_out) {
     // Init.
-    SortEx_init((SortExternal*)self, sizeof(Obj*));
+    SortEx_init((SortExternal*)self);
     PostingPoolIVARS *const ivars = PostPool_IVARS(self);
     ivars->doc_base         = 0;
     ivars->last_doc_id      = 0;

http://git-wip-us.apache.org/repos/asf/lucy/blob/8369f5f2/core/Lucy/Index/SortFieldWriter.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/SortFieldWriter.c b/core/Lucy/Index/SortFieldWriter.c
index 249e6ea..123e7f6 100644
--- a/core/Lucy/Index/SortFieldWriter.c
+++ b/core/Lucy/Index/SortFieldWriter.c
@@ -76,7 +76,7 @@ SortFieldWriter_init(SortFieldWriter *self, Schema *schema,
                      OutStream *temp_ord_out, OutStream *temp_ix_out,
                      OutStream *temp_dat_out) {
     // Init.
-    SortEx_init((SortExternal*)self, sizeof(SFWriterElem*));
+    SortEx_init((SortExternal*)self);
     SortFieldWriterIVARS *const ivars = SortFieldWriter_IVARS(self);
     ivars->null_ord        = -1;
     ivars->count           = 0;

http://git-wip-us.apache.org/repos/asf/lucy/blob/8369f5f2/core/Lucy/Util/BBSortEx.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Util/BBSortEx.c b/core/Lucy/Util/BBSortEx.c
index 92d80a5..a0a0c7e 100644
--- a/core/Lucy/Util/BBSortEx.c
+++ b/core/Lucy/Util/BBSortEx.c
@@ -33,7 +33,7 @@ BBSortEx_new(uint32_t mem_threshold, VArray *external) {
 
 BBSortEx*
 BBSortEx_init(BBSortEx *self, uint32_t mem_threshold, VArray *external) {
-    SortEx_init((SortExternal*)self, sizeof(Obj*));
+    SortEx_init((SortExternal*)self);
     BBSortExIVARS *const ivars = BBSortEx_IVARS(self);
     ivars->external_tick = 0;
     ivars->external = (VArray*)INCREF(external);
@@ -133,7 +133,8 @@ BBSortEx_Refill_IMP(BBSortEx *self) {
 
         if (ivars->cache_max == ivars->cache_cap) {
             BBSortEx_Grow_Cache(self,
-                                Memory_oversize(ivars->cache_max + 1, ivars->width));
+                                Memory_oversize(ivars->cache_max + 1,
+                                                sizeof(Obj*)));
         }
         Obj **cache = (Obj**)ivars->cache;
         cache[ivars->cache_max++] = INCREF(elem);

http://git-wip-us.apache.org/repos/asf/lucy/blob/8369f5f2/core/Lucy/Util/SortExternal.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Util/SortExternal.c b/core/Lucy/Util/SortExternal.c
index fc86556..b948131 100644
--- a/core/Lucy/Util/SortExternal.c
+++ b/core/Lucy/Util/SortExternal.c
@@ -41,12 +41,9 @@ S_find_slice_size(SortExternal *self, SortExternalIVARS *ivars,
                   uint8_t *endpost);
 
 SortExternal*
-SortEx_init(SortExternal *self, size_t width) {
+SortEx_init(SortExternal *self) {
     SortExternalIVARS *const ivars = SortEx_IVARS(self);
-    // Assign.
-    ivars->width        = width;
 
-    // Init.
     ivars->mem_thresh   = UINT32_MAX;
     ivars->cache        = NULL;
     ivars->cache_cap    = 0;
@@ -88,13 +85,12 @@ SortEx_Clear_Cache_IMP(SortExternal *self) {
 void
 SortEx_Feed_IMP(SortExternal *self, void *data) {
     SortExternalIVARS *const ivars = SortEx_IVARS(self);
-    const size_t width = ivars->width;
     if (ivars->cache_max == ivars->cache_cap) {
-        size_t amount = Memory_oversize(ivars->cache_max + 1, width);
+        size_t amount = Memory_oversize(ivars->cache_max + 1, sizeof(Obj*));
         SortEx_Grow_Cache(self, amount);
     }
-    uint8_t *target = ivars->cache + ivars->cache_max * width;
-    memcpy(target, data, width);
+    uint8_t *target = ivars->cache + ivars->cache_max * sizeof(Obj*);
+    memcpy(target, data, sizeof(Obj*));
     ivars->cache_max++;
 }
 
@@ -105,7 +101,7 @@ SI_peek(SortExternal *self, SortExternalIVARS *ivars) {
     }
 
     if (ivars->cache_max > 0) {
-        return ivars->cache + ivars->cache_tick * ivars->width;
+        return ivars->cache + ivars->cache_tick * sizeof(Obj*);
     }
     else {
         return NULL;
@@ -140,10 +136,10 @@ SortEx_Sort_Cache_IMP(SortExternal *self) {
             ivars->scratch_cap = ivars->cache_cap;
             ivars->scratch
                 = (uint8_t*)REALLOCATE(ivars->scratch,
-                                       ivars->scratch_cap * ivars->width);
+                                       ivars->scratch_cap * sizeof(Obj*));
         }
         Sort_mergesort(ivars->cache, ivars->scratch, ivars->cache_max,
-                       ivars->width, compare, self);
+                       sizeof(Obj*), compare, self);
     }
 }
 
@@ -193,7 +189,6 @@ S_refill_cache(SortExternal *self, SortExternalIVARS *ivars) {
 static uint8_t*
 S_find_endpost(SortExternal *self, SortExternalIVARS *ivars) {
     uint8_t *endpost = NULL;
-    const size_t width = ivars->width;
 
     for (uint32_t i = 0, max = VA_Get_Size(ivars->runs); i < max; i++) {
         // Get a run and retrieve the last item in its cache.
@@ -207,7 +202,7 @@ S_find_endpost(SortExternal *self, SortExternalIVARS *ivars) {
         else {
             // Cache item with the highest sort value currently held in memory
             // by the run.
-            uint8_t *candidate = run_ivars->cache + tick * width;
+            uint8_t *candidate = run_ivars->cache + tick * sizeof(Obj*);
 
             // If it's the first run, item is automatically the new endpost.
             if (i == 0) {
@@ -226,7 +221,6 @@ S_find_endpost(SortExternal *self, SortExternalIVARS *ivars) {
 static void
 S_absorb_slices(SortExternal *self, SortExternalIVARS *ivars,
                 uint8_t *endpost) {
-    size_t      width        = ivars->width;
     uint32_t    num_runs     = VA_Get_Size(ivars->runs);
     uint8_t   **slice_starts = ivars->slice_starts;
     uint32_t   *slice_sizes  = ivars->slice_sizes;
@@ -246,12 +240,12 @@ S_absorb_slices(SortExternal *self, SortExternalIVARS *ivars,
             // Move slice content from run cache to main cache.
             if (ivars->cache_max + slice_size > ivars->cache_cap) {
                 size_t cap = Memory_oversize(ivars->cache_max + slice_size,
-                                             width);
+                                             sizeof(Obj*));
                 SortEx_Grow_Cache(self, cap);
             }
-            memcpy(ivars->cache + ivars->cache_max * width,
-                   run_ivars->cache + run_ivars->cache_tick * width,
-                   slice_size * width);
+            memcpy(ivars->cache + ivars->cache_max * sizeof(Obj*),
+                   run_ivars->cache + run_ivars->cache_tick * sizeof(Obj*),
+                   slice_size * sizeof(Obj*));
             run_ivars->cache_tick += slice_size;
             ivars->cache_max += slice_size;
 
@@ -263,7 +257,7 @@ S_absorb_slices(SortExternal *self, SortExternalIVARS *ivars,
     // Transform slice starts from ticks to pointers.
     uint32_t total = 0;
     for (uint32_t i = 0; i < ivars->num_slices; i++) {
-        slice_starts[i] = ivars->cache + total * width;
+        slice_starts[i] = ivars->cache + total * sizeof(Obj*);
         total += slice_sizes[i];
     }
 
@@ -272,7 +266,7 @@ S_absorb_slices(SortExternal *self, SortExternalIVARS *ivars,
     if (ivars->scratch_cap < ivars->cache_cap) {
         ivars->scratch_cap = ivars->cache_cap;
         ivars->scratch = (uint8_t*)REALLOCATE(
-                            ivars->scratch, ivars->scratch_cap * width);
+                            ivars->scratch, ivars->scratch_cap * sizeof(Obj*));
     }
 
     // Exploit previous sorting, rather than sort cache naively.
@@ -287,10 +281,10 @@ S_absorb_slices(SortExternal *self, SortExternalIVARS *ivars,
                 const uint32_t merged_size = slice_sizes[i] + slice_sizes[i + 1];
                 Sort_merge(slice_starts[i], slice_sizes[i],
                            slice_starts[i + 1], slice_sizes[i + 1], ivars->scratch,
-                           ivars->width, compare, self);
+                           sizeof(Obj*), compare, self);
                 slice_sizes[j]  = merged_size;
                 slice_starts[j] = slice_starts[i];
-                memcpy(slice_starts[j], ivars->scratch, merged_size * width);
+                memcpy(slice_starts[j], ivars->scratch, merged_size * sizeof(Obj*));
                 i += 2;
                 j += 1;
             }
@@ -312,7 +306,7 @@ void
 SortEx_Grow_Cache_IMP(SortExternal *self, uint32_t size) {
     SortExternalIVARS *const ivars = SortEx_IVARS(self);
     if (size > ivars->cache_cap) {
-        ivars->cache = (uint8_t*)REALLOCATE(ivars->cache, size * ivars->width);
+        ivars->cache = (uint8_t*)REALLOCATE(ivars->cache, size * sizeof(Obj*));
         ivars->cache_cap = size;
     }
 }
@@ -323,14 +317,13 @@ S_find_slice_size(SortExternal *self, SortExternalIVARS *ivars,
     int32_t          lo      = ivars->cache_tick - 1;
     int32_t          hi      = ivars->cache_max;
     uint8_t *const   cache   = ivars->cache;
-    const size_t     width   = ivars->width;
     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 * width, endpost);
+        const int32_t delta = compare(self, cache + mid * sizeof(Obj*), endpost);
         if (delta > 0) { hi = mid; }
         else           { lo = mid; }
     }

http://git-wip-us.apache.org/repos/asf/lucy/blob/8369f5f2/core/Lucy/Util/SortExternal.cfh
----------------------------------------------------------------------
diff --git a/core/Lucy/Util/SortExternal.cfh b/core/Lucy/Util/SortExternal.cfh
index c414140..8362c4f 100644
--- a/core/Lucy/Util/SortExternal.cfh
+++ b/core/Lucy/Util/SortExternal.cfh
@@ -60,11 +60,10 @@ abstract class Lucy::Util::SortExternal nickname SortEx
     uint8_t      **slice_starts;
     uint32_t      *slice_sizes;
     uint32_t       mem_thresh;
-    size_t         width;
     bool           flipped;
 
     inert SortExternal*
-    init(SortExternal *self, size_t width);
+    init(SortExternal *self);
 
     /** Compare two sortable elements.
      */


[lucy-commits] [07/16] git commit: refs/heads/master - Change type of SortEx members.

Posted by ma...@apache.org.
Change type of SortEx members.

Change slice_starts and scratch to limit element types to Obj.


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

Branch: refs/heads/master
Commit: 90cfcac84a776fdd0555711f40f7e280eb739be3
Parents: 9ed7692
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Tue Jan 8 14:24:14 2013 -0800
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Sat Apr 26 12:01:25 2014 -0700

----------------------------------------------------------------------
 core/Lucy/Util/SortExternal.c   | 14 +++++++-------
 core/Lucy/Util/SortExternal.cfh |  4 ++--
 2 files changed, 9 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/90cfcac8/core/Lucy/Util/SortExternal.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Util/SortExternal.c b/core/Lucy/Util/SortExternal.c
index 9f0c30e..4d68664 100644
--- a/core/Lucy/Util/SortExternal.c
+++ b/core/Lucy/Util/SortExternal.c
@@ -136,8 +136,8 @@ SortEx_Sort_Cache_IMP(SortExternal *self) {
         if (ivars->scratch_cap < ivars->cache_cap) {
             ivars->scratch_cap = ivars->cache_cap;
             ivars->scratch
-                = (uint8_t*)REALLOCATE(ivars->scratch,
-                                       ivars->scratch_cap * sizeof(Obj*));
+                = (Obj**)REALLOCATE(ivars->scratch,
+                                    ivars->scratch_cap * sizeof(Obj*));
         }
         Sort_mergesort(ivars->cache, ivars->scratch, ivars->cache_max,
                        sizeof(Obj*), compare, self);
@@ -159,8 +159,8 @@ SortEx_Add_Run_IMP(SortExternal *self, SortExternal *run) {
         = (uint32_t*)REALLOCATE(ivars->slice_sizes,
                                 num_runs * sizeof(uint32_t));
     ivars->slice_starts
-        = (uint8_t**)REALLOCATE(ivars->slice_starts,
-                                num_runs * sizeof(uint8_t*));
+        = (Obj**)REALLOCATE(ivars->slice_starts,
+                                num_runs * sizeof(Obj*));
 }
 
 static void
@@ -223,7 +223,7 @@ static void
 S_absorb_slices(SortExternal *self, SortExternalIVARS *ivars,
                 uint8_t *endpost) {
     uint32_t    num_runs     = VA_Get_Size(ivars->runs);
-    uint8_t   **slice_starts = ivars->slice_starts;
+    Obj       **slice_starts = ivars->slice_starts;
     uint32_t   *slice_sizes  = ivars->slice_sizes;
     VTable     *vtable       = SortEx_Get_VTable(self);
     CFISH_Sort_Compare_t compare
@@ -258,7 +258,7 @@ S_absorb_slices(SortExternal *self, SortExternalIVARS *ivars,
     // Transform slice starts from ticks to pointers.
     uint32_t total = 0;
     for (uint32_t i = 0; i < ivars->num_slices; i++) {
-        slice_starts[i] = ivars->cache + total * sizeof(Obj*);
+        slice_starts[i] = (Obj*)(ivars->cache + total * sizeof(Obj*));
         total += slice_sizes[i];
     }
 
@@ -266,7 +266,7 @@ S_absorb_slices(SortExternal *self, SortExternalIVARS *ivars,
     // but exploit the fact that each slice is already sorted.
     if (ivars->scratch_cap < ivars->cache_cap) {
         ivars->scratch_cap = ivars->cache_cap;
-        ivars->scratch = (uint8_t*)REALLOCATE(
+        ivars->scratch = (Obj**)REALLOCATE(
                             ivars->scratch, ivars->scratch_cap * sizeof(Obj*));
     }
 

http://git-wip-us.apache.org/repos/asf/lucy/blob/90cfcac8/core/Lucy/Util/SortExternal.cfh
----------------------------------------------------------------------
diff --git a/core/Lucy/Util/SortExternal.cfh b/core/Lucy/Util/SortExternal.cfh
index a27f2c2..b1af4ad 100644
--- a/core/Lucy/Util/SortExternal.cfh
+++ b/core/Lucy/Util/SortExternal.cfh
@@ -53,11 +53,11 @@ abstract class Lucy::Util::SortExternal nickname SortEx
     uint32_t       cache_cap;
     uint32_t       cache_max;
     uint32_t       cache_tick;
-    uint8_t       *scratch;
+    Obj          **scratch;
     uint32_t       scratch_cap;
     VArray        *runs;
     uint32_t       num_slices;
-    uint8_t      **slice_starts;
+    Obj          **slice_starts;
     uint32_t      *slice_sizes;
     uint32_t       mem_thresh;
     bool           flipped;


[lucy-commits] [02/16] git commit: refs/heads/master - Change SortFieldWriter to use pointer-sized elems.

Posted by ma...@apache.org.
Change SortFieldWriter to use pointer-sized elems.

SortFieldWriter is the only subclass of SortExternal where the elements
have been anything other than pointers.  By changing it to use pointers,
we enable subsequent commits simplifying SortExternal by limiting it to
sorting pointers only.


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

Branch: refs/heads/master
Commit: 0bf76df7e7bf07c4df35a3d68d7dc6da009bf7b5
Parents: e6d1963
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Thu Jan 3 17:57:22 2013 -0800
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Sat Apr 26 09:52:20 2014 -0700

----------------------------------------------------------------------
 core/Lucy/Index/SortFieldWriter.c | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/0bf76df7/core/Lucy/Index/SortFieldWriter.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/SortFieldWriter.c b/core/Lucy/Index/SortFieldWriter.c
index e7d35cf..249e6ea 100644
--- a/core/Lucy/Index/SortFieldWriter.c
+++ b/core/Lucy/Index/SortFieldWriter.c
@@ -76,7 +76,7 @@ SortFieldWriter_init(SortFieldWriter *self, Schema *schema,
                      OutStream *temp_ord_out, OutStream *temp_ix_out,
                      OutStream *temp_dat_out) {
     // Init.
-    SortEx_init((SortExternal*)self, sizeof(SFWriterElem));
+    SortEx_init((SortExternal*)self, sizeof(SFWriterElem*));
     SortFieldWriterIVARS *const ivars = SortFieldWriter_IVARS(self);
     ivars->null_ord        = -1;
     ivars->count           = 0;
@@ -139,6 +139,11 @@ SortFieldWriter_Clear_Cache_IMP(SortFieldWriter *self) {
     SortFieldWriter_Clear_Cache_t super_clear_cache
         = SUPER_METHOD_PTR(SORTFIELDWRITER, LUCY_SortFieldWriter_Clear_Cache);
     super_clear_cache(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
+    // parent SortWriter to release the memory pool once **all** of its child
+    // SortFieldWriters have cleared their caches.
 }
 
 void
@@ -191,9 +196,10 @@ SortFieldWriter_Add_IMP(SortFieldWriter *self, int32_t doc_id, Obj *value) {
     SortFieldWriterIVARS *const ivars = SortFieldWriter_IVARS(self);
 
     // Uniq-ify the value, and record it for this document.
-    SFWriterElem elem;
-    elem.value = S_find_unique_value(ivars->uniq_vals, value);
-    elem.doc_id = doc_id;
+    SFWriterElem *elem
+        = (SFWriterElem*)MemPool_Grab(ivars->mem_pool, sizeof(SFWriterElem));
+    elem->value = S_find_unique_value(ivars->uniq_vals, value);
+    elem->doc_id = doc_id;
     SortFieldWriter_Feed(self, &elem);
     ivars->count++;
 }
@@ -336,8 +342,8 @@ S_write_val(Obj *val, int8_t prim_id, OutStream *ix_out, OutStream *dat_out,
 int
 SortFieldWriter_Compare_IMP(SortFieldWriter *self, void *va, void *vb) {
     SortFieldWriterIVARS *const ivars = SortFieldWriter_IVARS(self);
-    SFWriterElem *a = (SFWriterElem*)va;
-    SFWriterElem *b = (SFWriterElem*)vb;
+    SFWriterElem *a = *(SFWriterElem**)va;
+    SFWriterElem *b = *(SFWriterElem**)vb;
     int32_t comparison
         = FType_null_back_compare_values(ivars->type, a->value, b->value);
     if (comparison == 0) { comparison = b->doc_id - a->doc_id; }
@@ -553,7 +559,8 @@ S_write_files(SortFieldWriter *self, OutStream *ord_out, OutStream *ix_out,
 
     // Grab the first item and record its ord.  Add a dummy ord for invalid
     // doc id 0.
-    SFWriterElem *elem = (SFWriterElem*)SortFieldWriter_Fetch(self);
+    SFWriterElem **elem_ptr = (SFWriterElem**)SortFieldWriter_Fetch(self);
+    SFWriterElem *elem = *elem_ptr;
     ords[elem->doc_id] = ord;
     ords[0] = 0;
 
@@ -561,7 +568,8 @@ S_write_files(SortFieldWriter *self, OutStream *ord_out, OutStream *ix_out,
     ivars->last_val = INCREF(elem->value);
     Obj *last_val_address = elem->value;
     S_write_val(elem->value, prim_id, ix_out, dat_out, dat_start);
-    while (NULL != (elem = (SFWriterElem*)SortFieldWriter_Fetch(self))) {
+    while (NULL != (elem_ptr = (SFWriterElem**)SortFieldWriter_Fetch(self))) {
+        elem = *elem_ptr;
         if (elem->value != last_val_address) {
             int32_t comparison
                 = FType_Compare_Values(ivars->type, elem->value, ivars->last_val);


[lucy-commits] [14/16] git commit: refs/heads/master - Rename some methods in SortExternal.

Posted by ma...@apache.org.
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/3b0c585b
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/3b0c585b
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/3b0c585b

Branch: refs/heads/master
Commit: 3b0c585b559bfc9cc8f84820c248c61223a8521a
Parents: 4cff84b
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Fri Jan 11 15:06:45 2013 -0800
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Sat Apr 26 16:01:52 2014 -0700

----------------------------------------------------------------------
 core/Lucy/Index/PostingPool.c       | 16 ++++++++--------
 core/Lucy/Index/SortFieldWriter.c   | 24 ++++++++++++------------
 core/Lucy/Index/SortFieldWriter.cfh |  2 +-
 core/Lucy/Util/BBSortEx.c           | 18 +++++++++---------
 core/Lucy/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, 59 insertions(+), 59 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/3b0c585b/core/Lucy/Index/PostingPool.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/PostingPool.c b/core/Lucy/Index/PostingPool.c
index 9c538ed..3088f34 100644
--- a/core/Lucy/Index/PostingPool.c
+++ b/core/Lucy/Index/PostingPool.c
@@ -190,16 +190,16 @@ PostPool_Flip_IMP(PostingPool *self) {
         DECREF(post_temp_path);
     }
 
-    PostPool_Sort_Cache(self);
+    PostPool_Sort_Buffer(self);
     if (num_runs && (ivars->buf_max - ivars->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(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);
+        PostPool_Grow_Buffer(run, num_items);
         PostingPoolIVARS *const run_ivars = PostPool_IVARS(run);
 
         memcpy(run_ivars->buffer, (ivars->buffer) + ivars->buf_tick,
@@ -264,7 +264,7 @@ PostPool_Flush_IMP(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; }
+    if (PostPool_Buffer_Count(self) == 0) { return; }
 
     PostingPool *run
         = PostPool_new(ivars->schema, ivars->snapshot, ivars->segment,
@@ -288,7 +288,7 @@ PostPool_Flush_IMP(PostingPool *self) {
                               ivars->lex_temp_out);
     run_ivars->lex_start  = OutStream_Tell(ivars->lex_temp_out);
     run_ivars->post_start = OutStream_Tell(ivars->post_temp_out);
-    PostPool_Sort_Cache(self);
+    PostPool_Sort_Buffer(self);
     S_write_terms_and_postings(run, post_writer, NULL);
 
     run_ivars->lex_end  = OutStream_Tell(ivars->lex_temp_out);
@@ -300,7 +300,7 @@ PostPool_Flush_IMP(PostingPool *self) {
     run_ivars->buf_tick = 0;
     run_ivars->buf_max  = 0;
     run_ivars->buf_cap  = 0;
-    PostPool_Clear_Cache(self);
+    PostPool_Clear_Buffer(self);
 
     // Add the run to the array.
     PostPool_Add_Run(self, (SortExternal*)run);
@@ -517,7 +517,7 @@ PostPool_Refill_IMP(PostingPool *self) {
         // Add to the run's cache.
         if (num_elems >= ivars->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);
         }
         ivars->buffer[num_elems] = (Obj*)rawpost;
         num_elems++;
@@ -547,7 +547,7 @@ S_fresh_flip(PostingPool *self, InStream *lex_temp_in,
     ivars->flipped = true;
 
     // Sort RawPostings in cache, if any.
-    PostPool_Sort_Cache(self);
+    PostPool_Sort_Buffer(self);
 
     // Bail if never flushed.
     if (ivars->lex_end == 0) { return; }

http://git-wip-us.apache.org/repos/asf/lucy/blob/3b0c585b/core/Lucy/Index/SortFieldWriter.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/SortFieldWriter.c b/core/Lucy/Index/SortFieldWriter.c
index 1a0d5ff..9cdf47a 100644
--- a/core/Lucy/Index/SortFieldWriter.c
+++ b/core/Lucy/Index/SortFieldWriter.c
@@ -127,7 +127,7 @@ SortFieldWriter_init(SortFieldWriter *self, Schema *schema,
 }
 
 void
-SortFieldWriter_Clear_Cache_IMP(SortFieldWriter *self) {
+SortFieldWriter_Clear_Buffer_IMP(SortFieldWriter *self) {
     SortFieldWriterIVARS *const ivars = SortFieldWriter_IVARS(self);
     if (ivars->uniq_vals) {
         if (ivars->last_val) {
@@ -137,9 +137,9 @@ SortFieldWriter_Clear_Cache_IMP(SortFieldWriter *self) {
         }
         Hash_Clear(ivars->uniq_vals);
     }
-    SortFieldWriter_Clear_Cache_t super_clear_cache
-        = SUPER_METHOD_PTR(SORTFIELDWRITER, LUCY_SortFieldWriter_Clear_Cache);
-    super_clear_cache(self);
+    SortFieldWriter_Clear_Buffer_t super_clear_buffer
+        = SUPER_METHOD_PTR(SORTFIELDWRITER, 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
@@ -378,13 +378,13 @@ SortFieldWriter_Flush_IMP(SortFieldWriter *self) {
     SortFieldWriterIVARS *const ivars = SortFieldWriter_IVARS(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 = ivars->temp_ord_out;
     OutStream *const temp_ix_out  = ivars->temp_ix_out;
     OutStream *const temp_dat_out = ivars->temp_dat_out;
 
-    SortFieldWriter_Sort_Cache(self);
+    SortFieldWriter_Sort_Buffer(self);
     SortFieldWriter *run
         = SortFieldWriter_new(ivars->schema, ivars->snapshot, ivars->segment,
                               ivars->polyreader, ivars->field, ivars->mem_pool,
@@ -415,7 +415,7 @@ SortFieldWriter_Flush_IMP(SortFieldWriter *self) {
     run_ivars->buf_tick  = 0;
     run_ivars->buf_cap   = 0;
     ivars->buf_tick = ivars->buf_max;
-    SortFieldWriter_Clear_Cache(self);
+    SortFieldWriter_Clear_Buffer(self);
 
     // Record stream ends.
     run_ivars->ord_end = OutStream_Tell(temp_ord_out);
@@ -434,12 +434,12 @@ SortFieldWriter_Refill_IMP(SortFieldWriter *self) {
     if (!ivars->sort_cache) { return 0; }
 
     // Sanity check, then reset the cache and prepare to start loading items.
-    uint32_t buf_count = SortFieldWriter_Cache_Count(self);
+    uint32_t buf_count = SortFieldWriter_Buffer_Count(self);
     if (buf_count) {
         THROW(ERR, "Refill called but cache contains %u32 items",
               buf_count);
     }
-    SortFieldWriter_Clear_Cache(self);
+    SortFieldWriter_Clear_Buffer(self);
     MemPool_Release_All(ivars->mem_pool);
     S_lazy_init_sorted_ids(self);
 
@@ -480,7 +480,7 @@ SortFieldWriter_Refill_IMP(SortFieldWriter *self) {
         ivars->run_tick++;
     }
     ivars->run_ord++;
-    SortFieldWriter_Sort_Cache(self);
+    SortFieldWriter_Sort_Buffer(self);
 
     if (ivars->run_ord >= ivars->run_cardinality) {
         DECREF(ivars->sort_cache);
@@ -493,7 +493,7 @@ SortFieldWriter_Refill_IMP(SortFieldWriter *self) {
 void
 SortFieldWriter_Flip_IMP(SortFieldWriter *self) {
     SortFieldWriterIVARS *const ivars = SortFieldWriter_IVARS(self);
-    uint32_t num_items = SortFieldWriter_Cache_Count(self);
+    uint32_t num_items = SortFieldWriter_Buffer_Count(self);
     uint32_t num_runs = VA_Get_Size(ivars->runs);
 
     if (ivars->flipped) { THROW(ERR, "Can't call Flip() twice"); }
@@ -506,7 +506,7 @@ SortFieldWriter_Flip_IMP(SortFieldWriter *self) {
     }
 
     if (num_items) {
-        SortFieldWriter_Sort_Cache(self);
+        SortFieldWriter_Sort_Buffer(self);
     }
     else if (num_runs) {
         Folder  *folder = PolyReader_Get_Folder(ivars->polyreader);

http://git-wip-us.apache.org/repos/asf/lucy/blob/3b0c585b/core/Lucy/Index/SortFieldWriter.cfh
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/SortFieldWriter.cfh b/core/Lucy/Index/SortFieldWriter.cfh
index 00e85c1..8f749cc 100644
--- a/core/Lucy/Index/SortFieldWriter.cfh
+++ b/core/Lucy/Index/SortFieldWriter.cfh
@@ -88,7 +88,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/3b0c585b/core/Lucy/Util/BBSortEx.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Util/BBSortEx.c b/core/Lucy/Util/BBSortEx.c
index 156ab02..662a570 100644
--- a/core/Lucy/Util/BBSortEx.c
+++ b/core/Lucy/Util/BBSortEx.c
@@ -50,12 +50,12 @@ BBSortEx_Destroy_IMP(BBSortEx *self) {
 }
 
 void
-BBSortEx_Clear_Cache_IMP(BBSortEx *self) {
+BBSortEx_Clear_Buffer_IMP(BBSortEx *self) {
     BBSortExIVARS *const ivars = BBSortEx_IVARS(self);
     ivars->mem_consumed = 0;
-    BBSortEx_Clear_Cache_t super_clear_cache
-        = SUPER_METHOD_PTR(BBSORTEX, LUCY_BBSortEx_Clear_Cache);
-    super_clear_cache(self);
+    BBSortEx_Clear_Buffer_t super_clear_buffer
+        = SUPER_METHOD_PTR(BBSORTEX, LUCY_BBSortEx_Clear_Buffer);
+    super_clear_buffer(self);
 }
 
 void
@@ -84,7 +84,7 @@ BBSortEx_Flush_IMP(BBSortEx *self) {
     else            { elems = VA_new(buf_count); }
 
     // Sort, then create a new run.
-    BBSortEx_Sort_Cache(self);
+    BBSortEx_Sort_Buffer(self);
     for (uint32_t i = ivars->buf_tick; i < ivars->buf_max; i++) {
         VA_Push(elems, buffer[i]);
     }
@@ -94,7 +94,7 @@ BBSortEx_Flush_IMP(BBSortEx *self) {
 
     // Blank the cache vars.
     ivars->buf_tick += buf_count;
-    BBSortEx_Clear_Cache(self);
+    BBSortEx_Clear_Buffer(self);
 }
 
 uint32_t
@@ -128,9 +128,9 @@ BBSortEx_Refill_IMP(BBSortEx *self) {
         }
 
         if (ivars->buf_max == ivars->buf_cap) {
-            BBSortEx_Grow_Cache(self,
-                                Memory_oversize(ivars->buf_max + 1,
-                                                sizeof(Obj*)));
+            BBSortEx_Grow_Buffer(self,
+                                 Memory_oversize(ivars->buf_max + 1,
+                                                 sizeof(Obj*)));
         }
         ivars->buffer[ivars->buf_max++] = INCREF(elem);
     }

http://git-wip-us.apache.org/repos/asf/lucy/blob/3b0c585b/core/Lucy/Util/BBSortEx.cfh
----------------------------------------------------------------------
diff --git a/core/Lucy/Util/BBSortEx.cfh b/core/Lucy/Util/BBSortEx.cfh
index 3ba7531..8ef64c8 100644
--- a/core/Lucy/Util/BBSortEx.cfh
+++ b/core/Lucy/Util/BBSortEx.cfh
@@ -43,7 +43,7 @@ class Lucy::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/3b0c585b/core/Lucy/Util/SortExternal.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Util/SortExternal.c b/core/Lucy/Util/SortExternal.c
index ce42550..c7dff90 100644
--- a/core/Lucy/Util/SortExternal.c
+++ b/core/Lucy/Util/SortExternal.c
@@ -21,7 +21,7 @@
 
 // Refill the main cache, drawing from the caches of all runs.
 static void
-S_refill_cache(SortExternal *self, SortExternalIVARS *ivars);
+S_refill_buffer(SortExternal *self, SortExternalIVARS *ivars);
 
 // Absorb all the items which are "in-range" from all the Runs into the main
 // cache.
@@ -68,7 +68,7 @@ SortEx_Destroy_IMP(SortExternal *self) {
     FREEMEM(ivars->slice_sizes);
     FREEMEM(ivars->slice_starts);
     if (ivars->buffer) {
-        SortEx_Clear_Cache(self);
+        SortEx_Clear_Buffer(self);
         FREEMEM(ivars->buffer);
     }
     DECREF(ivars->runs);
@@ -76,7 +76,7 @@ SortEx_Destroy_IMP(SortExternal *self) {
 }
 
 void
-SortEx_Clear_Cache_IMP(SortExternal *self) {
+SortEx_Clear_Buffer_IMP(SortExternal *self) {
     SortExternalIVARS *const ivars = SortEx_IVARS(self);
     Obj **const buffer = ivars->buffer;
     const uint32_t max = ivars->buf_max;
@@ -92,7 +92,7 @@ SortEx_Feed_IMP(SortExternal *self, Obj *item) {
     SortExternalIVARS *const ivars = SortEx_IVARS(self);
     if (ivars->buf_max == ivars->buf_cap) {
         size_t amount = Memory_oversize(ivars->buf_max + 1, sizeof(Obj*));
-        SortEx_Grow_Cache(self, amount);
+        SortEx_Grow_Buffer(self, amount);
     }
     ivars->buffer[ivars->buf_max] = item;
     ivars->buf_max++;
@@ -101,7 +101,7 @@ SortEx_Feed_IMP(SortExternal *self, Obj *item) {
 static CFISH_INLINE Obj*
 SI_peek(SortExternal *self, SortExternalIVARS *ivars) {
     if (ivars->buf_tick >= ivars->buf_max) {
-        S_refill_cache(self, ivars);
+        S_refill_buffer(self, ivars);
     }
 
     if (ivars->buf_max > 0) {
@@ -127,10 +127,10 @@ SortEx_Peek_IMP(SortExternal *self) {
 }
 
 void
-SortEx_Sort_Cache_IMP(SortExternal *self) {
+SortEx_Sort_Buffer_IMP(SortExternal *self) {
     SortExternalIVARS *const ivars = SortEx_IVARS(self);
     if (ivars->buf_tick != 0) {
-        THROW(ERR, "Cant Sort_Cache() after fetching %u32 items", ivars->buf_tick);
+        THROW(ERR, "Cant Sort_Buffer() after fetching %u32 items", ivars->buf_tick);
     }
     if (ivars->buf_max != 0) {
         VTable *vtable = SortEx_Get_VTable(self);
@@ -169,7 +169,7 @@ void
 SortEx_Shrink_IMP(SortExternal *self) {
     SortExternalIVARS *const ivars = SortEx_IVARS(self);
     if (ivars->buf_max - ivars->buf_tick > 0) {
-        size_t buf_count = SortEx_Cache_Count(self);
+        size_t buf_count = SortEx_Buffer_Count(self);
         size_t size        = buf_count * sizeof(Obj*);
         if (ivars->buf_tick > 0) {
             Obj **start = ivars->buffer + ivars->buf_tick;
@@ -198,15 +198,15 @@ SortEx_Shrink_IMP(SortExternal *self) {
 }
 
 static void
-S_refill_cache(SortExternal *self, SortExternalIVARS *ivars) {
+S_refill_buffer(SortExternal *self, SortExternalIVARS *ivars) {
     // 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(ivars->runs)) {
         SortExternal *const run = (SortExternal*)VA_Fetch(ivars->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 {
@@ -276,7 +276,7 @@ S_absorb_slices(SortExternal *self, SortExternalIVARS *ivars,
             if (ivars->buf_max + slice_size > ivars->buf_cap) {
                 size_t cap = Memory_oversize(ivars->buf_max + slice_size,
                                              sizeof(Obj*));
-                SortEx_Grow_Cache(self, cap);
+                SortEx_Grow_Buffer(self, cap);
             }
             memcpy(ivars->buffer + ivars->buf_max,
                    run_ivars->buffer + run_ivars->buf_tick,
@@ -338,7 +338,7 @@ S_absorb_slices(SortExternal *self, SortExternalIVARS *ivars,
 }
 
 void
-SortEx_Grow_Cache_IMP(SortExternal *self, uint32_t cap) {
+SortEx_Grow_Buffer_IMP(SortExternal *self, uint32_t cap) {
     SortExternalIVARS *const ivars = SortEx_IVARS(self);
     if (cap > ivars->buf_cap) {
         ivars->buffer = (Obj**)REALLOCATE(ivars->buffer, cap * sizeof(Obj*));
@@ -375,7 +375,7 @@ SortEx_Set_Mem_Thresh_IMP(SortExternal *self, uint32_t mem_thresh) {
 }
 
 uint32_t
-SortEx_Cache_Count_IMP(SortExternal *self) {
+SortEx_Buffer_Count_IMP(SortExternal *self) {
     SortExternalIVARS *const ivars = SortEx_IVARS(self);
     return ivars->buf_max - ivars->buf_tick;
 }

http://git-wip-us.apache.org/repos/asf/lucy/blob/3b0c585b/core/Lucy/Util/SortExternal.cfh
----------------------------------------------------------------------
diff --git a/core/Lucy/Util/SortExternal.cfh b/core/Lucy/Util/SortExternal.cfh
index 9674f92..917f5df 100644
--- a/core/Lucy/Util/SortExternal.cfh
+++ b/core/Lucy/Util/SortExternal.cfh
@@ -109,7 +109,7 @@ abstract class Lucy::Util::SortExternal nickname 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 nickname 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 cap);
+    Grow_Buffer(SortExternal *self, uint32_t cap);
 
     void
     Set_Mem_Thresh(SortExternal *self, uint32_t mem_thresh);

http://git-wip-us.apache.org/repos/asf/lucy/blob/3b0c585b/perl/t/015-sort_external.t
----------------------------------------------------------------------
diff --git a/perl/t/015-sort_external.t b/perl/t/015-sort_external.t
index 134e7c7..b656abf 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::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::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 = ();
 


[lucy-commits] [10/16] git commit: refs/heads/master - Handle refcounting when clearing SortEx buffer.

Posted by ma...@apache.org.
Handle refcounting when clearing SortEx buffer.

Now that SortExternal only handles objects rather than addresses, it
makes sense to decref objects when emptying out the buffer.

This change is safe for all subclasses and incurs no performance penalty
under normal conditions -- unless something goes wrong all buffered
items will have already been consumed by the time the buffer-clearing
operation is invoked.


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

Branch: refs/heads/master
Commit: 88271ce1059c6191bc6b946deb51c1aba48ca474
Parents: c09c1dc
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Tue Jan 8 17:22:23 2013 -0800
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Sat Apr 26 14:10:55 2014 -0700

----------------------------------------------------------------------
 core/Lucy/Util/BBSortEx.c     | 4 ----
 core/Lucy/Util/SortExternal.c | 5 +++++
 2 files changed, 5 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/88271ce1/core/Lucy/Util/BBSortEx.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Util/BBSortEx.c b/core/Lucy/Util/BBSortEx.c
index 40238cf..c5c4c13 100644
--- a/core/Lucy/Util/BBSortEx.c
+++ b/core/Lucy/Util/BBSortEx.c
@@ -52,10 +52,6 @@ BBSortEx_Destroy_IMP(BBSortEx *self) {
 void
 BBSortEx_Clear_Cache_IMP(BBSortEx *self) {
     BBSortExIVARS *const ivars = BBSortEx_IVARS(self);
-    Obj **const cache = ivars->cache;
-    for (uint32_t i = ivars->cache_tick, max = ivars->cache_max; i < max; i++) {
-        DECREF(cache[i]);
-    }
     ivars->mem_consumed = 0;
     BBSortEx_Clear_Cache_t super_clear_cache
         = SUPER_METHOD_PTR(BBSORTEX, LUCY_BBSortEx_Clear_Cache);

http://git-wip-us.apache.org/repos/asf/lucy/blob/88271ce1/core/Lucy/Util/SortExternal.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Util/SortExternal.c b/core/Lucy/Util/SortExternal.c
index 434c34d..c4d936e 100644
--- a/core/Lucy/Util/SortExternal.c
+++ b/core/Lucy/Util/SortExternal.c
@@ -78,6 +78,11 @@ SortEx_Destroy_IMP(SortExternal *self) {
 void
 SortEx_Clear_Cache_IMP(SortExternal *self) {
     SortExternalIVARS *const ivars = SortEx_IVARS(self);
+    Obj **const cache = ivars->cache;
+    const uint32_t max = ivars->cache_max;
+    for (uint32_t i = ivars->cache_tick; i < max; i++) {
+        DECREF(cache[i]);
+    }
     ivars->cache_max    = 0;
     ivars->cache_tick   = 0;
 }


[lucy-commits] [09/16] git commit: refs/heads/master - Change type for SortEx buffer.

Posted by ma...@apache.org.
Change type for SortEx buffer.

Change buffer for SortExternal to an array of objects instead of
addresses.


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

Branch: refs/heads/master
Commit: c09c1dcab745ed5ecdaa66e1e1c1a276263e418f
Parents: 7392ca1
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Tue Jan 8 17:11:59 2013 -0800
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Sat Apr 26 13:48:18 2014 -0700

----------------------------------------------------------------------
 core/Lucy/Index/PostingPool.c   |  9 ++++-----
 core/Lucy/Util/BBSortEx.c       |  7 +++----
 core/Lucy/Util/SortExternal.c   | 23 ++++++++++-------------
 core/Lucy/Util/SortExternal.cfh |  4 ++--
 4 files changed, 19 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/c09c1dca/core/Lucy/Index/PostingPool.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/PostingPool.c b/core/Lucy/Index/PostingPool.c
index 6628fc3..55eecc9 100644
--- a/core/Lucy/Index/PostingPool.c
+++ b/core/Lucy/Index/PostingPool.c
@@ -202,7 +202,7 @@ PostPool_Flip_IMP(PostingPool *self) {
         PostPool_Grow_Cache(run, num_items);
         PostingPoolIVARS *const run_ivars = PostPool_IVARS(run);
 
-        memcpy(run_ivars->cache, ((Obj**)ivars->cache) + ivars->cache_tick,
+        memcpy(run_ivars->cache, (ivars->cache) + ivars->cache_tick,
                num_items * sizeof(Obj*));
         run_ivars->cache_max = num_items;
         PostPool_Add_Run(self, (SortExternal*)run);
@@ -266,10 +266,10 @@ PostPool_Shrink_IMP(PostingPool *self) {
         size_t cache_count = PostPool_Cache_Count(self);
         size_t size        = cache_count * sizeof(Obj*);
         if (ivars->cache_tick > 0) {
-            Obj **start = ((Obj**)ivars->cache) + ivars->cache_tick;
+            Obj **start = ivars->cache + ivars->cache_tick;
             memmove(ivars->cache, start, size);
         }
-        ivars->cache      = (uint8_t*)REALLOCATE(ivars->cache, size);
+        ivars->cache      = (Obj**)REALLOCATE(ivars->cache, size);
         ivars->cache_tick = 0;
         ivars->cache_max  = cache_count;
         ivars->cache_cap  = cache_count;
@@ -549,8 +549,7 @@ PostPool_Refill_IMP(PostingPool *self) {
             size_t new_cap = Memory_oversize(num_elems + 1, sizeof(Obj*));
             PostPool_Grow_Cache(self, new_cap);
         }
-        Obj **cache = (Obj**)ivars->cache;
-        cache[num_elems] = (Obj*)rawpost;
+        ivars->cache[num_elems] = (Obj*)rawpost;
         num_elems++;
     }
 

http://git-wip-us.apache.org/repos/asf/lucy/blob/c09c1dca/core/Lucy/Util/BBSortEx.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Util/BBSortEx.c b/core/Lucy/Util/BBSortEx.c
index fb50522..40238cf 100644
--- a/core/Lucy/Util/BBSortEx.c
+++ b/core/Lucy/Util/BBSortEx.c
@@ -52,7 +52,7 @@ BBSortEx_Destroy_IMP(BBSortEx *self) {
 void
 BBSortEx_Clear_Cache_IMP(BBSortEx *self) {
     BBSortExIVARS *const ivars = BBSortEx_IVARS(self);
-    Obj **const cache = (Obj**)ivars->cache;
+    Obj **const cache = ivars->cache;
     for (uint32_t i = ivars->cache_tick, max = ivars->cache_max; i < max; i++) {
         DECREF(cache[i]);
     }
@@ -81,7 +81,7 @@ void
 BBSortEx_Flush_IMP(BBSortEx *self) {
     BBSortExIVARS *const ivars = BBSortEx_IVARS(self);
     uint32_t     cache_count = ivars->cache_max - ivars->cache_tick;
-    Obj        **cache = (Obj**)ivars->cache;
+    Obj        **cache = ivars->cache;
     VArray      *elems;
 
     if (!cache_count) { return; }
@@ -136,8 +136,7 @@ BBSortEx_Refill_IMP(BBSortEx *self) {
                                 Memory_oversize(ivars->cache_max + 1,
                                                 sizeof(Obj*)));
         }
-        Obj **cache = (Obj**)ivars->cache;
-        cache[ivars->cache_max++] = INCREF(elem);
+        ivars->cache[ivars->cache_max++] = INCREF(elem);
     }
 
     return ivars->cache_max;

http://git-wip-us.apache.org/repos/asf/lucy/blob/c09c1dca/core/Lucy/Util/SortExternal.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Util/SortExternal.c b/core/Lucy/Util/SortExternal.c
index 3aa3334..434c34d 100644
--- a/core/Lucy/Util/SortExternal.c
+++ b/core/Lucy/Util/SortExternal.c
@@ -89,8 +89,7 @@ SortEx_Feed_IMP(SortExternal *self, Obj *item) {
         size_t amount = Memory_oversize(ivars->cache_max + 1, sizeof(Obj*));
         SortEx_Grow_Cache(self, amount);
     }
-    Obj **elems = (Obj**)ivars->cache;
-    elems[ivars->cache_max] = item;
+    ivars->cache[ivars->cache_max] = item;
     ivars->cache_max++;
 }
 
@@ -101,8 +100,7 @@ SI_peek(SortExternal *self, SortExternalIVARS *ivars) {
     }
 
     if (ivars->cache_max > 0) {
-        Obj **elems = (Obj**)ivars->cache;
-        return elems[ivars->cache_tick];
+        return ivars->cache[ivars->cache_tick];
     }
     else {
         return NULL;
@@ -159,8 +157,7 @@ SortEx_Add_Run_IMP(SortExternal *self, SortExternal *run) {
         = (uint32_t*)REALLOCATE(ivars->slice_sizes,
                                 num_runs * sizeof(uint32_t));
     ivars->slice_starts
-        = (Obj**)REALLOCATE(ivars->slice_starts,
-                                num_runs * sizeof(Obj*));
+        = (Obj***)REALLOCATE(ivars->slice_starts, num_runs * sizeof(Obj**));
 }
 
 static void
@@ -203,7 +200,7 @@ S_find_endpost(SortExternal *self, SortExternalIVARS *ivars) {
         else {
             // Cache item with the highest sort value currently held in memory
             // by the run.
-            Obj **candidate = (Obj**)run_ivars->cache + tick;
+            Obj **candidate = run_ivars->cache + tick;
 
             // If it's the first run, item is automatically the new endpost.
             if (i == 0) {
@@ -223,7 +220,7 @@ static void
 S_absorb_slices(SortExternal *self, SortExternalIVARS *ivars,
                 Obj **endpost) {
     uint32_t    num_runs     = VA_Get_Size(ivars->runs);
-    Obj       **slice_starts = ivars->slice_starts;
+    Obj      ***slice_starts = ivars->slice_starts;
     uint32_t   *slice_sizes  = ivars->slice_sizes;
     VTable     *vtable       = SortEx_Get_VTable(self);
     CFISH_Sort_Compare_t compare
@@ -244,8 +241,8 @@ S_absorb_slices(SortExternal *self, SortExternalIVARS *ivars,
                                              sizeof(Obj*));
                 SortEx_Grow_Cache(self, cap);
             }
-            memcpy(ivars->cache + ivars->cache_max * sizeof(Obj*),
-                   run_ivars->cache + run_ivars->cache_tick * sizeof(Obj*),
+            memcpy(ivars->cache + ivars->cache_max,
+                   run_ivars->cache + run_ivars->cache_tick,
                    slice_size * sizeof(Obj*));
             run_ivars->cache_tick += slice_size;
             ivars->cache_max += slice_size;
@@ -258,7 +255,7 @@ S_absorb_slices(SortExternal *self, SortExternalIVARS *ivars,
     // Transform slice starts from ticks to pointers.
     uint32_t total = 0;
     for (uint32_t i = 0; i < ivars->num_slices; i++) {
-        slice_starts[i] = (Obj*)(ivars->cache + total * sizeof(Obj*));
+        slice_starts[i] = ivars->cache + total;
         total += slice_sizes[i];
     }
 
@@ -307,7 +304,7 @@ void
 SortEx_Grow_Cache_IMP(SortExternal *self, uint32_t size) {
     SortExternalIVARS *const ivars = SortEx_IVARS(self);
     if (size > ivars->cache_cap) {
-        ivars->cache = (uint8_t*)REALLOCATE(ivars->cache, size * sizeof(Obj*));
+        ivars->cache = (Obj**)REALLOCATE(ivars->cache, size * sizeof(Obj*));
         ivars->cache_cap = size;
     }
 }
@@ -317,7 +314,7 @@ S_find_slice_size(SortExternal *self, SortExternalIVARS *ivars,
                   Obj **endpost) {
     int32_t          lo      = ivars->cache_tick - 1;
     int32_t          hi      = ivars->cache_max;
-    Obj            **cache   = (Obj**)ivars->cache;
+    Obj            **cache   = ivars->cache;
     SortEx_Compare_t compare
         = METHOD_PTR(SortEx_Get_VTable(self), LUCY_SortEx_Compare);
 

http://git-wip-us.apache.org/repos/asf/lucy/blob/c09c1dca/core/Lucy/Util/SortExternal.cfh
----------------------------------------------------------------------
diff --git a/core/Lucy/Util/SortExternal.cfh b/core/Lucy/Util/SortExternal.cfh
index b1af4ad..13d3009 100644
--- a/core/Lucy/Util/SortExternal.cfh
+++ b/core/Lucy/Util/SortExternal.cfh
@@ -49,7 +49,7 @@ __END_C__
 abstract class Lucy::Util::SortExternal nickname SortEx
     inherits Clownfish::Obj {
 
-    uint8_t       *cache;
+    Obj          **cache;
     uint32_t       cache_cap;
     uint32_t       cache_max;
     uint32_t       cache_tick;
@@ -57,7 +57,7 @@ abstract class Lucy::Util::SortExternal nickname SortEx
     uint32_t       scratch_cap;
     VArray        *runs;
     uint32_t       num_slices;
-    Obj          **slice_starts;
+    Obj         ***slice_starts;
     uint32_t      *slice_sizes;
     uint32_t       mem_thresh;
     bool           flipped;


[lucy-commits] [08/16] git commit: refs/heads/master - Change type for some SortEx private functions.

Posted by ma...@apache.org.
Change type for some SortEx private functions.

Modify some private subroutines in SortExternal to use Obj pointers
rather than byte addresses.


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

Branch: refs/heads/master
Commit: 7392ca1c8e700df22be4a7ea1bdeecdd9139fb21
Parents: 90cfcac
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Tue Jan 8 16:45:18 2013 -0800
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Sat Apr 26 12:05:49 2014 -0700

----------------------------------------------------------------------
 core/Lucy/Util/SortExternal.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/7392ca1c/core/Lucy/Util/SortExternal.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Util/SortExternal.c b/core/Lucy/Util/SortExternal.c
index 4d68664..3aa3334 100644
--- a/core/Lucy/Util/SortExternal.c
+++ b/core/Lucy/Util/SortExternal.c
@@ -27,18 +27,18 @@ S_refill_cache(SortExternal *self, SortExternalIVARS *ivars);
 // cache.
 static void
 S_absorb_slices(SortExternal *self, SortExternalIVARS *ivars,
-                uint8_t *endpost);
+                Obj **endpost);
 
 // Return the address for the item in one of the runs' caches which is the
 // highest in sort order, but which we can guarantee is lower in sort order
 // than any item which has yet to enter a run cache.
-static uint8_t*
+static Obj**
 S_find_endpost(SortExternal *self, SortExternalIVARS *ivars);
 
-// Determine how many cache items are less than or equal to [endpost].
+// Determine how many buffered items are less than or equal to `endpost`.
 static uint32_t
 S_find_slice_size(SortExternal *self, SortExternalIVARS *ivars,
-                  uint8_t *endpost);
+                  Obj **endpost);
 
 SortExternal*
 SortEx_init(SortExternal *self) {
@@ -182,14 +182,14 @@ S_refill_cache(SortExternal *self, SortExternalIVARS *ivars) {
 
     // Absorb as many elems as possible from all runs into main cache.
     if (VA_Get_Size(ivars->runs)) {
-        uint8_t *endpost = S_find_endpost(self, ivars);
+        Obj **endpost = S_find_endpost(self, ivars);
         S_absorb_slices(self, ivars, endpost);
     }
 }
 
-static uint8_t*
+static Obj**
 S_find_endpost(SortExternal *self, SortExternalIVARS *ivars) {
-    uint8_t *endpost = NULL;
+    Obj **endpost = NULL;
 
     for (uint32_t i = 0, max = VA_Get_Size(ivars->runs); i < max; i++) {
         // Get a run and retrieve the last item in its cache.
@@ -203,7 +203,7 @@ S_find_endpost(SortExternal *self, SortExternalIVARS *ivars) {
         else {
             // Cache item with the highest sort value currently held in memory
             // by the run.
-            uint8_t *candidate = run_ivars->cache + tick * sizeof(Obj*);
+            Obj **candidate = (Obj**)run_ivars->cache + tick;
 
             // If it's the first run, item is automatically the new endpost.
             if (i == 0) {
@@ -221,7 +221,7 @@ S_find_endpost(SortExternal *self, SortExternalIVARS *ivars) {
 
 static void
 S_absorb_slices(SortExternal *self, SortExternalIVARS *ivars,
-                uint8_t *endpost) {
+                Obj **endpost) {
     uint32_t    num_runs     = VA_Get_Size(ivars->runs);
     Obj       **slice_starts = ivars->slice_starts;
     uint32_t   *slice_sizes  = ivars->slice_sizes;
@@ -314,17 +314,17 @@ SortEx_Grow_Cache_IMP(SortExternal *self, uint32_t size) {
 
 static uint32_t
 S_find_slice_size(SortExternal *self, SortExternalIVARS *ivars,
-                  uint8_t *endpost) {
+                  Obj **endpost) {
     int32_t          lo      = ivars->cache_tick - 1;
     int32_t          hi      = ivars->cache_max;
-    uint8_t *const   cache   = ivars->cache;
+    Obj            **cache   = (Obj**)ivars->cache;
     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 * sizeof(Obj*), endpost);
+        const int32_t delta = compare(self, cache + mid, endpost);
         if (delta > 0) { hi = mid; }
         else           { lo = mid; }
     }


[lucy-commits] [06/16] git commit: refs/heads/master - Change return type for Peek() and Fetch().

Posted by ma...@apache.org.
Change return type for Peek() and Fetch().

Modify SortExternal and subclasses so that Peek() and Fetch return Obj*
rather than a void* which was actually Obj**.


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

Branch: refs/heads/master
Commit: 9ed7692cf8be7707ec892911b5a8949b4063d064
Parents: d477115
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Fri Jan 4 16:16:14 2013 -0800
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Sat Apr 26 11:52:22 2014 -0700

----------------------------------------------------------------------
 core/Lucy/Index/PostingPool.c            | 10 ++-----
 core/Lucy/Index/SortFieldWriter.c        |  6 ++--
 core/Lucy/Util/SortExternal.c            | 13 +++++----
 core/Lucy/Util/SortExternal.cfh          |  4 +--
 perl/buildlib/Lucy/Build/Binding/Util.pm | 42 ---------------------------
 5 files changed, 14 insertions(+), 61 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/9ed7692c/core/Lucy/Index/PostingPool.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/PostingPool.c b/core/Lucy/Index/PostingPool.c
index 57067f2..6628fc3 100644
--- a/core/Lucy/Index/PostingPool.c
+++ b/core/Lucy/Index/PostingPool.c
@@ -374,9 +374,8 @@ S_write_terms_and_postings(PostingPool *self, PostingWriter *post_writer,
         = Arch_Skip_Interval(Schema_Get_Architecture(ivars->schema));
 
     // Prime heldover variables.
-    RawPosting *posting = (RawPosting*)CERTIFY(
-                              (*(RawPosting**)PostPool_Fetch(self)),
-                              RAWPOSTING);
+    RawPosting *posting
+        = (RawPosting*)CERTIFY(PostPool_Fetch(self), RAWPOSTING);
     RawPostingIVARS *post_ivars = RawPost_IVARS(posting);
     CharBuf *last_term_text
         = CB_new_from_trusted_utf8(post_ivars->blob, post_ivars->content_len);
@@ -465,10 +464,7 @@ S_write_terms_and_postings(PostingPool *self, PostingWriter *post_writer,
         // Retrieve the next posting from the sort pool.
         // DECREF(posting);  // No!!  DON'T destroy!!!
 
-        void *address = PostPool_Fetch(self);
-        posting = address
-                  ? *(RawPosting**)address
-                  : NULL;
+        posting = (RawPosting*)PostPool_Fetch(self);
         post_ivars = RawPost_IVARS(posting);
     }
 

http://git-wip-us.apache.org/repos/asf/lucy/blob/9ed7692c/core/Lucy/Index/SortFieldWriter.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/SortFieldWriter.c b/core/Lucy/Index/SortFieldWriter.c
index 34aa84d..2e55a39 100644
--- a/core/Lucy/Index/SortFieldWriter.c
+++ b/core/Lucy/Index/SortFieldWriter.c
@@ -558,8 +558,7 @@ S_write_files(SortFieldWriter *self, OutStream *ord_out, OutStream *ix_out,
 
     // Grab the first item and record its ord.  Add a dummy ord for invalid
     // doc id 0.
-    SFWriterElem **elem_ptr = (SFWriterElem**)SortFieldWriter_Fetch(self);
-    SFWriterElem *elem = *elem_ptr;
+    SFWriterElem *elem = (SFWriterElem*)SortFieldWriter_Fetch(self);
     SFWriterElemIVARS *elem_ivars = SFWriterElem_IVARS(elem);
     ords[elem_ivars->doc_id] = ord;
     ords[0] = 0;
@@ -568,8 +567,7 @@ S_write_files(SortFieldWriter *self, OutStream *ord_out, OutStream *ix_out,
     ivars->last_val = INCREF(elem_ivars->value);
     Obj *last_val_address = elem_ivars->value;
     S_write_val(elem_ivars->value, prim_id, ix_out, dat_out, dat_start);
-    while (NULL != (elem_ptr = (SFWriterElem**)SortFieldWriter_Fetch(self))) {
-        elem = *elem_ptr;
+    while (NULL != (elem = (SFWriterElem*)SortFieldWriter_Fetch(self))) {
         elem_ivars = SFWriterElem_IVARS(elem);
         if (elem_ivars->value != last_val_address) {
             int32_t comparison

http://git-wip-us.apache.org/repos/asf/lucy/blob/9ed7692c/core/Lucy/Util/SortExternal.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Util/SortExternal.c b/core/Lucy/Util/SortExternal.c
index 98158b9..9f0c30e 100644
--- a/core/Lucy/Util/SortExternal.c
+++ b/core/Lucy/Util/SortExternal.c
@@ -94,29 +94,30 @@ SortEx_Feed_IMP(SortExternal *self, Obj *item) {
     ivars->cache_max++;
 }
 
-static CFISH_INLINE void*
+static CFISH_INLINE Obj*
 SI_peek(SortExternal *self, SortExternalIVARS *ivars) {
     if (ivars->cache_tick >= ivars->cache_max) {
         S_refill_cache(self, ivars);
     }
 
     if (ivars->cache_max > 0) {
-        return ivars->cache + ivars->cache_tick * sizeof(Obj*);
+        Obj **elems = (Obj**)ivars->cache;
+        return elems[ivars->cache_tick];
     }
     else {
         return NULL;
     }
 }
 
-void*
+Obj*
 SortEx_Fetch_IMP(SortExternal *self) {
     SortExternalIVARS *const ivars = SortEx_IVARS(self);
-    void *address = SI_peek(self, ivars);
+    Obj *item = SI_peek(self, ivars);
     ivars->cache_tick++;
-    return address;
+    return item;
 }
 
-void*
+Obj*
 SortEx_Peek_IMP(SortExternal *self) {
     SortExternalIVARS *const ivars = SortEx_IVARS(self);
     return SI_peek(self, ivars);

http://git-wip-us.apache.org/repos/asf/lucy/blob/9ed7692c/core/Lucy/Util/SortExternal.cfh
----------------------------------------------------------------------
diff --git a/core/Lucy/Util/SortExternal.cfh b/core/Lucy/Util/SortExternal.cfh
index a6a7313..a27f2c2 100644
--- a/core/Lucy/Util/SortExternal.cfh
+++ b/core/Lucy/Util/SortExternal.cfh
@@ -92,13 +92,13 @@ abstract class Lucy::Util::SortExternal nickname SortEx
     /** Fetch the next sorted item from the sort pool.  Invalid prior to
      * calling Flip(). Returns NULL when all elements have been exhausted.
      */
-    nullable void*
+    incremented nullable Obj*
     Fetch(SortExternal *self);
 
     /** Preview the next item that Fetch will return, but don't pop it.
      * Invalid prior to calling Flip().
      */
-    nullable void*
+    nullable Obj*
     Peek(SortExternal *self);
 
     /** Add a run to the sortex's collection.

http://git-wip-us.apache.org/repos/asf/lucy/blob/9ed7692c/perl/buildlib/Lucy/Build/Binding/Util.pm
----------------------------------------------------------------------
diff --git a/perl/buildlib/Lucy/Build/Binding/Util.pm b/perl/buildlib/Lucy/Build/Binding/Util.pm
index a0de3ed..5bd6ed9 100644
--- a/perl/buildlib/Lucy/Build/Binding/Util.pm
+++ b/perl/buildlib/Lucy/Build/Binding/Util.pm
@@ -29,52 +29,10 @@ sub bind_all {
 }
 
 sub bind_bbsortex {
-    my @hand_rolled = qw(
-        Fetch
-        Peek
-    );
-    my $xs_code = <<'END_XS_CODE';
-MODULE = Lucy    PACKAGE = Lucy::Util::BBSortEx
-
-SV*
-fetch(self)
-    lucy_BBSortEx *self;
-CODE:
-{
-    void *address = LUCY_BBSortEx_Fetch(self);
-    if (address) {
-        RETVAL = XSBind_cfish_to_perl(*(cfish_Obj**)address);
-        CFISH_DECREF(*(cfish_Obj**)address);
-    }
-    else {
-        RETVAL = newSV(0);
-    }
-}
-OUTPUT: RETVAL
-
-SV*
-peek(self)
-    lucy_BBSortEx *self;
-CODE:
-{
-    void *address = LUCY_BBSortEx_Peek(self);
-    if (address) {
-        RETVAL = XSBind_cfish_to_perl(*(cfish_Obj**)address);
-    }
-    else {
-        RETVAL = newSV(0);
-    }
-}
-OUTPUT: RETVAL
-
-END_XS_CODE
-
     my $binding = Clownfish::CFC::Binding::Perl::Class->new(
         parcel     => "Lucy",
         class_name => "Lucy::Util::BBSortEx",
     );
-    $binding->append_xs($xs_code);
-
     Clownfish::CFC::Binding::Perl::Class->register($binding);
 }
 


[lucy-commits] [11/16] git commit: refs/heads/master - Move Shrink() up from PostingPool to SortExternal.

Posted by ma...@apache.org.
Move Shrink() up from PostingPool to SortExternal.

Move the Shrink method up into the parent class and generalize it by
calling Shrink() on runs.


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

Branch: refs/heads/master
Commit: 7677ad4df614d0523571811dc4a9bf1f41e1df60
Parents: 88271ce
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Tue Jan 8 17:59:56 2013 -0800
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Sat Apr 26 14:16:05 2014 -0700

----------------------------------------------------------------------
 core/Lucy/Index/PostingPool.c   | 30 ------------------------------
 core/Lucy/Index/PostingPool.cfh |  5 -----
 core/Lucy/Util/SortExternal.c   | 32 ++++++++++++++++++++++++++++++++
 core/Lucy/Util/SortExternal.cfh |  5 +++++
 4 files changed, 37 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/7677ad4d/core/Lucy/Index/PostingPool.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/PostingPool.c b/core/Lucy/Index/PostingPool.c
index 55eecc9..cc56c34 100644
--- a/core/Lucy/Index/PostingPool.c
+++ b/core/Lucy/Index/PostingPool.c
@@ -260,36 +260,6 @@ PostPool_Add_Segment_IMP(PostingPool *self, SegReader *reader,
 }
 
 void
-PostPool_Shrink_IMP(PostingPool *self) {
-    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 (ivars->cache_tick > 0) {
-            Obj **start = ivars->cache + ivars->cache_tick;
-            memmove(ivars->cache, start, size);
-        }
-        ivars->cache      = (Obj**)REALLOCATE(ivars->cache, size);
-        ivars->cache_tick = 0;
-        ivars->cache_max  = cache_count;
-        ivars->cache_cap  = cache_count;
-    }
-    else {
-        FREEMEM(ivars->cache);
-        ivars->cache      = NULL;
-        ivars->cache_tick = 0;
-        ivars->cache_max  = 0;
-        ivars->cache_cap  = 0;
-    }
-    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.
-}
-
-void
 PostPool_Flush_IMP(PostingPool *self) {
     PostingPoolIVARS *const ivars = PostPool_IVARS(self);
 

http://git-wip-us.apache.org/repos/asf/lucy/blob/7677ad4d/core/Lucy/Index/PostingPool.cfh
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/PostingPool.cfh b/core/Lucy/Index/PostingPool.cfh
index be1d26a..587955b 100644
--- a/core/Lucy/Index/PostingPool.cfh
+++ b/core/Lucy/Index/PostingPool.cfh
@@ -69,11 +69,6 @@ class Lucy::Index::PostingPool nickname PostPool
     Add_Inversion(PostingPool *self, Inversion *inversion, int32_t doc_id,
                   float doc_boost, float length_norm);
 
-    /** Reduce RAM footprint as much as possible.
-     */
-    void
-    Shrink(PostingPool *self);
-
     MemoryPool*
     Get_Mem_Pool(PostingPool *self);
 

http://git-wip-us.apache.org/repos/asf/lucy/blob/7677ad4d/core/Lucy/Util/SortExternal.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Util/SortExternal.c b/core/Lucy/Util/SortExternal.c
index c4d936e..f8a2690 100644
--- a/core/Lucy/Util/SortExternal.c
+++ b/core/Lucy/Util/SortExternal.c
@@ -165,6 +165,38 @@ SortEx_Add_Run_IMP(SortExternal *self, SortExternal *run) {
         = (Obj***)REALLOCATE(ivars->slice_starts, num_runs * sizeof(Obj**));
 }
 
+void
+SortEx_Shrink_IMP(SortExternal *self) {
+    SortExternalIVARS *const ivars = SortEx_IVARS(self);
+    if (ivars->cache_max - ivars->cache_tick > 0) {
+        size_t cache_count = SortEx_Cache_Count(self);
+        size_t size        = cache_count * sizeof(Obj*);
+        if (ivars->cache_tick > 0) {
+            Obj **start = ivars->cache + ivars->cache_tick;
+            memmove(ivars->cache, start, size);
+        }
+        ivars->cache      = (Obj**)REALLOCATE(ivars->cache, size);
+        ivars->cache_tick = 0;
+        ivars->cache_max  = cache_count;
+        ivars->cache_cap  = cache_count;
+    }
+    else {
+        FREEMEM(ivars->cache);
+        ivars->cache      = NULL;
+        ivars->cache_tick = 0;
+        ivars->cache_max  = 0;
+        ivars->cache_cap  = 0;
+    }
+    ivars->scratch_cap = 0;
+    FREEMEM(ivars->scratch);
+    ivars->scratch = NULL;
+
+    for (uint32_t i = 0, max = VA_Get_Size(ivars->runs); i < max; i++) {
+        SortExternal *run = (SortExternal*)VA_Fetch(ivars->runs, i);
+        SortEx_Shrink(run);
+    }
+}
+
 static void
 S_refill_cache(SortExternal *self, SortExternalIVARS *ivars) {
     // Reset cache vars.

http://git-wip-us.apache.org/repos/asf/lucy/blob/7677ad4d/core/Lucy/Util/SortExternal.cfh
----------------------------------------------------------------------
diff --git a/core/Lucy/Util/SortExternal.cfh b/core/Lucy/Util/SortExternal.cfh
index 13d3009..cfc0591 100644
--- a/core/Lucy/Util/SortExternal.cfh
+++ b/core/Lucy/Util/SortExternal.cfh
@@ -106,6 +106,11 @@ abstract class Lucy::Util::SortExternal nickname SortEx
     void
     Add_Run(SortExternal *self, decremented SortExternal *run);
 
+    /** Compact buffer sizes and minimize memory consumption.
+     */
+    void
+    Shrink(SortExternal *self);
+
     /** Refill the cache of a run.  Will only be called on child objects, not
      * the main object.
      */


[lucy-commits] [05/16] git commit: refs/heads/master - Modify SortEx_Feed() argument type.

Posted by ma...@apache.org.
Modify SortEx_Feed() argument type.

Have Feed() take an Obj* rather than void*.


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

Branch: refs/heads/master
Commit: d477115848375c74b9266f49144bfc2a817895e0
Parents: bb2a97d
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Fri Jan 4 15:17:17 2013 -0800
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Sat Apr 26 11:36:01 2014 -0700

----------------------------------------------------------------------
 core/Lucy/Index/Posting/MatchPosting.c   | 2 +-
 core/Lucy/Index/Posting/RichPosting.c    | 2 +-
 core/Lucy/Index/Posting/ScorePosting.c   | 2 +-
 core/Lucy/Index/SortFieldWriter.c        | 2 +-
 core/Lucy/Util/BBSortEx.c                | 6 +++---
 core/Lucy/Util/BBSortEx.cfh              | 2 +-
 core/Lucy/Util/SortExternal.c            | 6 +++---
 core/Lucy/Util/SortExternal.cfh          | 7 ++-----
 perl/buildlib/Lucy/Build/Binding/Util.pm | 9 ---------
 9 files changed, 13 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/d4771158/core/Lucy/Index/Posting/MatchPosting.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/Posting/MatchPosting.c b/core/Lucy/Index/Posting/MatchPosting.c
index 55c9734..800d684 100644
--- a/core/Lucy/Index/Posting/MatchPosting.c
+++ b/core/Lucy/Index/Posting/MatchPosting.c
@@ -138,7 +138,7 @@ MatchPost_Add_Inversion_To_Pool_IMP(MatchPosting *self,
         RawPosting *raw_posting
             = RawPost_new(MemPool_Grab(mem_pool, raw_post_bytes), doc_id,
                           freq, token_ivars->text, token_ivars->len);
-        PostPool_Feed(post_pool, &raw_posting);
+        PostPool_Feed(post_pool, (Obj*)raw_posting);
     }
 }
 

http://git-wip-us.apache.org/repos/asf/lucy/blob/d4771158/core/Lucy/Index/Posting/RichPosting.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/Posting/RichPosting.c b/core/Lucy/Index/Posting/RichPosting.c
index f5af4ce..8bcc423 100644
--- a/core/Lucy/Index/Posting/RichPosting.c
+++ b/core/Lucy/Index/Posting/RichPosting.c
@@ -147,7 +147,7 @@ RichPost_Add_Inversion_To_Pool_IMP(RichPosting *self, PostingPool *post_pool,
         raw_post_ivars->aux_len = dest - start;
         raw_post_bytes = dest - (char*)raw_posting;
         MemPool_Resize(mem_pool, raw_posting, raw_post_bytes);
-        PostPool_Feed(post_pool, &raw_posting);
+        PostPool_Feed(post_pool, (Obj*)raw_posting);
     }
 }
 

http://git-wip-us.apache.org/repos/asf/lucy/blob/d4771158/core/Lucy/Index/Posting/ScorePosting.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/Posting/ScorePosting.c b/core/Lucy/Index/Posting/ScorePosting.c
index b2d3265..f5aa961 100644
--- a/core/Lucy/Index/Posting/ScorePosting.c
+++ b/core/Lucy/Index/Posting/ScorePosting.c
@@ -117,7 +117,7 @@ ScorePost_Add_Inversion_To_Pool_IMP(ScorePosting *self,
         raw_post_ivars->aux_len = dest - start;
         raw_post_bytes = dest - (char*)raw_posting;
         MemPool_Resize(mem_pool, raw_posting, raw_post_bytes);
-        PostPool_Feed(post_pool, &raw_posting);
+        PostPool_Feed(post_pool, (Obj*)raw_posting);
     }
 }
 

http://git-wip-us.apache.org/repos/asf/lucy/blob/d4771158/core/Lucy/Index/SortFieldWriter.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/SortFieldWriter.c b/core/Lucy/Index/SortFieldWriter.c
index 7c0e770..34aa84d 100644
--- a/core/Lucy/Index/SortFieldWriter.c
+++ b/core/Lucy/Index/SortFieldWriter.c
@@ -199,7 +199,7 @@ SortFieldWriter_Add_IMP(SortFieldWriter *self, int32_t doc_id, Obj *value) {
     // Uniq-ify the value, and record it for this document.
     Obj *copy = S_find_unique_value(ivars->uniq_vals, value);
     SFWriterElem *elem = S_SFWriterElem_create(ivars->mem_pool, copy, doc_id);
-    SortFieldWriter_Feed(self, &elem);
+    SortFieldWriter_Feed(self, (Obj*)elem);
     ivars->count++;
 }
 

http://git-wip-us.apache.org/repos/asf/lucy/blob/d4771158/core/Lucy/Util/BBSortEx.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Util/BBSortEx.c b/core/Lucy/Util/BBSortEx.c
index a0a0c7e..fb50522 100644
--- a/core/Lucy/Util/BBSortEx.c
+++ b/core/Lucy/Util/BBSortEx.c
@@ -63,14 +63,14 @@ BBSortEx_Clear_Cache_IMP(BBSortEx *self) {
 }
 
 void
-BBSortEx_Feed_IMP(BBSortEx *self, void *data) {
+BBSortEx_Feed_IMP(BBSortEx *self, Obj *item) {
     BBSortExIVARS *const ivars = BBSortEx_IVARS(self);
     BBSortEx_Feed_t super_feed
         = SUPER_METHOD_PTR(BBSORTEX, LUCY_BBSortEx_Feed);
-    super_feed(self, data);
+    super_feed(self, item);
 
     // Flush() if necessary.
-    ByteBuf *bytebuf = (ByteBuf*)CERTIFY(*(ByteBuf**)data, BYTEBUF);
+    ByteBuf *bytebuf = (ByteBuf*)CERTIFY(item, BYTEBUF);
     ivars->mem_consumed += BB_Get_Size(bytebuf);
     if (ivars->mem_consumed >= ivars->mem_thresh) {
         BBSortEx_Flush(self);

http://git-wip-us.apache.org/repos/asf/lucy/blob/d4771158/core/Lucy/Util/BBSortEx.cfh
----------------------------------------------------------------------
diff --git a/core/Lucy/Util/BBSortEx.cfh b/core/Lucy/Util/BBSortEx.cfh
index 41f72ea..3ba7531 100644
--- a/core/Lucy/Util/BBSortEx.cfh
+++ b/core/Lucy/Util/BBSortEx.cfh
@@ -34,7 +34,7 @@ class Lucy::Util::BBSortEx
         VArray *external = NULL);
 
     void
-    Feed(BBSortEx *self, void *data);
+    Feed(BBSortEx *self, decremented Obj *item);
 
     void
     Flush(BBSortEx *self);

http://git-wip-us.apache.org/repos/asf/lucy/blob/d4771158/core/Lucy/Util/SortExternal.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Util/SortExternal.c b/core/Lucy/Util/SortExternal.c
index b948131..98158b9 100644
--- a/core/Lucy/Util/SortExternal.c
+++ b/core/Lucy/Util/SortExternal.c
@@ -83,14 +83,14 @@ SortEx_Clear_Cache_IMP(SortExternal *self) {
 }
 
 void
-SortEx_Feed_IMP(SortExternal *self, void *data) {
+SortEx_Feed_IMP(SortExternal *self, Obj *item) {
     SortExternalIVARS *const ivars = SortEx_IVARS(self);
     if (ivars->cache_max == ivars->cache_cap) {
         size_t amount = Memory_oversize(ivars->cache_max + 1, sizeof(Obj*));
         SortEx_Grow_Cache(self, amount);
     }
-    uint8_t *target = ivars->cache + ivars->cache_max * sizeof(Obj*);
-    memcpy(target, data, sizeof(Obj*));
+    Obj **elems = (Obj**)ivars->cache;
+    elems[ivars->cache_max] = item;
     ivars->cache_max++;
 }
 

http://git-wip-us.apache.org/repos/asf/lucy/blob/d4771158/core/Lucy/Util/SortExternal.cfh
----------------------------------------------------------------------
diff --git a/core/Lucy/Util/SortExternal.cfh b/core/Lucy/Util/SortExternal.cfh
index 8362c4f..a6a7313 100644
--- a/core/Lucy/Util/SortExternal.cfh
+++ b/core/Lucy/Util/SortExternal.cfh
@@ -79,13 +79,10 @@ abstract class Lucy::Util::SortExternal nickname SortEx
     abstract void
     Flush(SortExternal *self);
 
-    /** Add data to the sort pool.
-     *
-     * @param data Pointer to the data being added, which must be exactly
-     * <code>width</code> bytes in size.
+    /** Add an item to the sort pool.
      */
     void
-    Feed(SortExternal *self, void *data);
+    Feed(SortExternal *self, decremented Obj *item);
 
     /** Flip the sortex from write mode to read mode.
      */

http://git-wip-us.apache.org/repos/asf/lucy/blob/d4771158/perl/buildlib/Lucy/Build/Binding/Util.pm
----------------------------------------------------------------------
diff --git a/perl/buildlib/Lucy/Build/Binding/Util.pm b/perl/buildlib/Lucy/Build/Binding/Util.pm
index 1561b48..a0de3ed 100644
--- a/perl/buildlib/Lucy/Build/Binding/Util.pm
+++ b/perl/buildlib/Lucy/Build/Binding/Util.pm
@@ -32,7 +32,6 @@ sub bind_bbsortex {
     my @hand_rolled = qw(
         Fetch
         Peek
-        Feed
     );
     my $xs_code = <<'END_XS_CODE';
 MODULE = Lucy    PACKAGE = Lucy::Util::BBSortEx
@@ -68,14 +67,6 @@ CODE:
 }
 OUTPUT: RETVAL
 
-void
-feed(self, bb)
-    lucy_BBSortEx *self;
-    cfish_ByteBuf *bb;
-CODE:
-    CFISH_INCREF(bb);
-    LUCY_BBSortEx_Feed(self, &bb);
-
 END_XS_CODE
 
     my $binding = Clownfish::CFC::Binding::Perl::Class->new(


[lucy-commits] [16/16] git commit: refs/heads/master - Update SortExternal docs.

Posted by ma...@apache.org.
Update SortExternal docs.

Modify summary to reflect the fact that SortExternal now only sorts
objects rather than arbitrary data.


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

Branch: refs/heads/master
Commit: c15909359dcb1cce9ea1f5b2ba0f0e10f0114784
Parents: 00181bd
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Tue Jan 22 14:06:43 2013 -0800
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Sat Apr 26 16:06:30 2014 -0700

----------------------------------------------------------------------
 core/Lucy/Util/SortExternal.cfh | 32 ++++++++++++++++----------------
 1 file changed, 16 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/c1590935/core/Lucy/Util/SortExternal.cfh
----------------------------------------------------------------------
diff --git a/core/Lucy/Util/SortExternal.cfh b/core/Lucy/Util/SortExternal.cfh
index 5ffb44c..7e8439b 100644
--- a/core/Lucy/Util/SortExternal.cfh
+++ b/core/Lucy/Util/SortExternal.cfh
@@ -18,22 +18,22 @@ parcel Lucy;
 
 /** Abstract external sorter.
  *
- * SortExternal objects are sort pools which allow you to sort large amounts
- * of data.  To achieve this, you Feed() all values into the SortExternal
- * object, Flip() the object from write mode to read mode, then Fetch() the
- * values one at a time in sorted order.
+ * SortExternal objects are sort pools which allow you to sort huge
+ * collections of elements.  To achieve this, you Feed() all items into the
+ * SortExternal object, Flip() it from write mode to read mode, then Fetch()
+ * the elements one at a time in sorted order.
  *
- * It's expected that the total memory footprint of the sortable objects will
- * eventually exceed a specified threshold; at that point, the SortExternal
- * object will call the abstract method Flush().  It's expected that Flush()
- * implementations will empty out the current sort buffer, write a sorted "run"
- * to external storage, and add a new child SortExternal object to the top
- * level object's "runs" array to represent the flushed content.
+ * It's expected that the total memory footprint of the buffered sortable
+ * items will eventually exceed a specified threshold; at that point, the
+ * SortExternal object will call the abstract method Flush().  It's expected
+ * that Flush() implementations will empty out the current buffer, write a
+ * sorted "run" to external storage, and add a new child SortExternal object
+ * to the top level object's "runs" array to represent the flushed content.
  *
- * During the read phase, the child objects retrieve values from external
- * storage by calling the abstract method Refill().  The top-level
+ * During the read phase, the child sortex objects retrieve elements from
+ * external storage by calling the abstract method Refill().  The top-level
  * SortExternal object then interleaves multiple sorted streams to produce a
- * single unified stream of sorted values.
+ * single unified stream of sorted items.
  */
 abstract class Lucy::Util::SortExternal nickname SortEx
     inherits Clownfish::Obj {
@@ -63,7 +63,7 @@ abstract class Lucy::Util::SortExternal nickname SortEx
      *
      * Presumably this entails sorting everything, writing the sorted elements
      * to disk, spawning a child object to represent those elements, and
-     * adding that child to the top level object via Add_Run().
+     * adding that child to the top-level object via Add_Run().
      */
     abstract void
     Flush(SortExternal *self);
@@ -100,8 +100,8 @@ abstract class Lucy::Util::SortExternal nickname SortEx
     void
     Shrink(SortExternal *self);
 
-    /** Refill the buffer of a run.  Will only be called on child objects, not
-     * the main object.
+    /** Refill the buffer of a run.  Will only be called on child sortex
+     * objects, not the main object.
      */
     abstract uint32_t
     Refill(SortExternal *self);


[lucy-commits] [15/16] git commit: refs/heads/master - Update SortExternal docs with new terminology.

Posted by ma...@apache.org.
Update SortExternal docs with new terminology.

Modify comments and docs to use "buffer" instead of "cache".


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

Branch: refs/heads/master
Commit: 00181bd4e0eb18c3d79f09ddbb8f8e63c08101e5
Parents: 3b0c585
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Fri Jan 11 16:13:45 2013 -0800
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Sat Apr 26 16:01:56 2014 -0700

----------------------------------------------------------------------
 core/Lucy/Index/PostingPool.c     | 16 ++++++++--------
 core/Lucy/Index/SortFieldWriter.c |  6 +++---
 core/Lucy/Util/BBSortEx.c         |  6 +++---
 core/Lucy/Util/SortExternal.c     | 26 +++++++++++++-------------
 core/Lucy/Util/SortExternal.cfh   | 16 ++++++++--------
 5 files changed, 35 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/00181bd4/core/Lucy/Index/PostingPool.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/PostingPool.c b/core/Lucy/Index/PostingPool.c
index 3088f34..fc71473 100644
--- a/core/Lucy/Index/PostingPool.c
+++ b/core/Lucy/Index/PostingPool.c
@@ -277,7 +277,7 @@ PostPool_Flush_IMP(PostingPool *self) {
                                             ivars->segment, ivars->polyreader,
                                             ivars->post_temp_out);
 
-    // Borrow the cache.
+    // Borrow the buffer.
     run_ivars->buffer   = ivars->buffer;
     run_ivars->buf_tick = ivars->buf_tick;
     run_ivars->buf_max  = ivars->buf_max;
@@ -295,7 +295,7 @@ PostPool_Flush_IMP(PostingPool *self) {
     run_ivars->post_end = OutStream_Tell(ivars->post_temp_out);
     LexWriter_Leave_Temp_Mode(ivars->lex_writer);
 
-    // Return the cache and empty it.
+    // Return the buffer and empty it.
     run_ivars->buffer   = NULL;
     run_ivars->buf_tick = 0;
     run_ivars->buf_max  = 0;
@@ -458,9 +458,9 @@ PostPool_Refill_IMP(PostingPool *self) {
     if (ivars->lexicon == NULL) { return 0; }
     else { term_text = (String*)Lex_Get_Term(lexicon); }
 
-    // Make sure cache is empty.
+    // Make sure buffer is empty.
     if (ivars->buf_max - ivars->buf_tick > 0) {
-        THROW(ERR, "Refill called but cache contains %u32 items",
+        THROW(ERR, "Refill called but buffer contains %u32 items",
               ivars->buf_max - ivars->buf_tick);
     }
     ivars->buf_max  = 0;
@@ -492,7 +492,7 @@ PostPool_Refill_IMP(PostingPool *self) {
             }
         }
 
-        // Bail if we've hit the ceiling for this run's cache.
+        // Bail if we've hit the ceiling for this run's buffer.
         if (mem_pool_ivars->consumed >= mem_thresh && num_elems > 0) {
             break;
         }
@@ -514,7 +514,7 @@ PostPool_Refill_IMP(PostingPool *self) {
             rawpost_ivars->doc_id = remapped;
         }
 
-        // Add to the run's cache.
+        // Add to the run's buffer.
         if (num_elems >= ivars->buf_cap) {
             size_t new_cap = Memory_oversize(num_elems + 1, sizeof(Obj*));
             PostPool_Grow_Buffer(self, new_cap);
@@ -523,7 +523,7 @@ PostPool_Refill_IMP(PostingPool *self) {
         num_elems++;
     }
 
-    // Reset the cache array position and length; remember file pos.
+    // Reset the buffer array position and length; remember file pos.
     ivars->buf_max   = num_elems;
     ivars->buf_tick  = 0;
 
@@ -546,7 +546,7 @@ S_fresh_flip(PostingPool *self, InStream *lex_temp_in,
     if (ivars->flipped) { THROW(ERR, "Can't Flip twice"); }
     ivars->flipped = true;
 
-    // Sort RawPostings in cache, if any.
+    // Sort RawPostings in buffer, if any.
     PostPool_Sort_Buffer(self);
 
     // Bail if never flushed.

http://git-wip-us.apache.org/repos/asf/lucy/blob/00181bd4/core/Lucy/Index/SortFieldWriter.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/SortFieldWriter.c b/core/Lucy/Index/SortFieldWriter.c
index 9cdf47a..381f9ad 100644
--- a/core/Lucy/Index/SortFieldWriter.c
+++ b/core/Lucy/Index/SortFieldWriter.c
@@ -144,7 +144,7 @@ SortFieldWriter_Clear_Buffer_IMP(SortFieldWriter *self) {
     // This is because the pool is shared amongst multiple SortFieldWriters
     // which belong to a parent SortWriter; it is the responsibility of the
     // parent SortWriter to release the memory pool once **all** of its child
-    // SortFieldWriters have cleared their caches.
+    // SortFieldWriters have cleared their buffers.
 }
 
 void
@@ -433,10 +433,10 @@ SortFieldWriter_Refill_IMP(SortFieldWriter *self) {
     SortFieldWriterIVARS *const ivars = SortFieldWriter_IVARS(self);
     if (!ivars->sort_cache) { return 0; }
 
-    // Sanity check, then reset the cache and prepare to start loading items.
+    // Sanity check, then reset the buffer and prepare to start loading items.
     uint32_t buf_count = SortFieldWriter_Buffer_Count(self);
     if (buf_count) {
-        THROW(ERR, "Refill called but cache contains %u32 items",
+        THROW(ERR, "Refill called but buffer contains %u32 items",
               buf_count);
     }
     SortFieldWriter_Clear_Buffer(self);

http://git-wip-us.apache.org/repos/asf/lucy/blob/00181bd4/core/Lucy/Util/BBSortEx.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Util/BBSortEx.c b/core/Lucy/Util/BBSortEx.c
index 662a570..ff96c73 100644
--- a/core/Lucy/Util/BBSortEx.c
+++ b/core/Lucy/Util/BBSortEx.c
@@ -92,7 +92,7 @@ BBSortEx_Flush_IMP(BBSortEx *self) {
     DECREF(elems);
     BBSortEx_Add_Run(self, (SortExternal*)run);
 
-    // Blank the cache vars.
+    // Blank the buffer vars.
     ivars->buf_tick += buf_count;
     BBSortEx_Clear_Buffer(self);
 }
@@ -101,9 +101,9 @@ uint32_t
 BBSortEx_Refill_IMP(BBSortEx *self) {
     BBSortExIVARS *const ivars = BBSortEx_IVARS(self);
 
-    // Make sure cache is empty, then set cache tick vars.
+    // Make sure buffer is empty, then set buffer tick vars.
     if (ivars->buf_max - ivars->buf_tick > 0) {
-        THROW(ERR, "Refill called but cache contains %u32 items",
+        THROW(ERR, "Refill called but buffer contains %u32 items",
               ivars->buf_max - ivars->buf_tick);
     }
     ivars->buf_tick = 0;

http://git-wip-us.apache.org/repos/asf/lucy/blob/00181bd4/core/Lucy/Util/SortExternal.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Util/SortExternal.c b/core/Lucy/Util/SortExternal.c
index c7dff90..c8b6963 100644
--- a/core/Lucy/Util/SortExternal.c
+++ b/core/Lucy/Util/SortExternal.c
@@ -19,19 +19,19 @@
 
 #include "Lucy/Util/SortExternal.h"
 
-// Refill the main cache, drawing from the caches of all runs.
+// Refill the main buffer, drawing from the buffers of all runs.
 static void
 S_refill_buffer(SortExternal *self, SortExternalIVARS *ivars);
 
 // Absorb all the items which are "in-range" from all the Runs into the main
-// cache.
+// buffer.
 static void
 S_absorb_slices(SortExternal *self, SortExternalIVARS *ivars,
                 Obj **endpost);
 
-// Return the address for the item in one of the runs' caches which is the
+// Return the address for the item in one of the runs' buffers which is the
 // highest in sort order, but which we can guarantee is lower in sort order
-// than any item which has yet to enter a run cache.
+// than any item which has yet to enter a run buffer.
 static Obj**
 S_find_endpost(SortExternal *self, SortExternalIVARS *ivars);
 
@@ -199,10 +199,10 @@ SortEx_Shrink_IMP(SortExternal *self) {
 
 static void
 S_refill_buffer(SortExternal *self, SortExternalIVARS *ivars) {
-    // Reset cache vars.
+    // Reset buffer vars.
     SortEx_Clear_Buffer(self);
 
-    // Make sure all runs have at least one item in the cache.
+    // Make sure all runs have at least one item in the buffer.
     uint32_t i = 0;
     while (i < VA_Get_Size(ivars->runs)) {
         SortExternal *const run = (SortExternal*)VA_Fetch(ivars->runs, i);
@@ -214,7 +214,7 @@ S_refill_buffer(SortExternal *self, SortExternalIVARS *ivars) {
         }
     }
 
-    // Absorb as many elems as possible from all runs into main cache.
+    // Absorb as many elems as possible from all runs into main buffer.
     if (VA_Get_Size(ivars->runs)) {
         Obj **endpost = S_find_endpost(self, ivars);
         S_absorb_slices(self, ivars, endpost);
@@ -226,12 +226,12 @@ S_find_endpost(SortExternal *self, SortExternalIVARS *ivars) {
     Obj **endpost = NULL;
 
     for (uint32_t i = 0, max = VA_Get_Size(ivars->runs); i < max; i++) {
-        // Get a run and retrieve the last item in its cache.
+        // Get a run and retrieve the last item in its buffer.
         SortExternal *const run = (SortExternal*)VA_Fetch(ivars->runs, i);
         SortExternalIVARS *const run_ivars = SortEx_IVARS(run);
         const uint32_t tick = run_ivars->buf_max - 1;
         if (tick >= run_ivars->buf_cap || run_ivars->buf_max < 1) {
-            THROW(ERR, "Invalid SortExternal cache access: %u32 %u32 %u32", tick,
+            THROW(ERR, "Invalid SortExternal buffer access: %u32 %u32 %u32", tick,
                   run_ivars->buf_max, run_ivars->buf_cap);
         }
         else {
@@ -265,14 +265,14 @@ S_absorb_slices(SortExternal *self, SortExternalIVARS *ivars,
 
     if (ivars->buf_max != 0) { THROW(ERR, "Can't refill unless empty"); }
 
-    // Move all the elements in range into the main cache as slices.
+    // Move all the elements in range into the main buffer as slices.
     for (uint32_t i = 0; i < num_runs; i++) {
         SortExternal *const run = (SortExternal*)VA_Fetch(ivars->runs, i);
         SortExternalIVARS *const run_ivars = SortEx_IVARS(run);
         uint32_t slice_size = S_find_slice_size(run, run_ivars, endpost);
 
         if (slice_size) {
-            // Move slice content from run cache to main cache.
+            // Move slice content from run buffer to main buffer.
             if (ivars->buf_max + slice_size > ivars->buf_cap) {
                 size_t cap = Memory_oversize(ivars->buf_max + slice_size,
                                              sizeof(Obj*));
@@ -296,7 +296,7 @@ S_absorb_slices(SortExternal *self, SortExternalIVARS *ivars,
         total += slice_sizes[i];
     }
 
-    // The main cache now consists of several slices.  Sort the main cache,
+    // The main buffer now consists of several slices.  Sort the main buffer,
     // but exploit the fact that each slice is already sorted.
     if (ivars->scratch_cap < ivars->buf_cap) {
         ivars->scratch_cap = ivars->buf_cap;
@@ -304,7 +304,7 @@ S_absorb_slices(SortExternal *self, SortExternalIVARS *ivars,
                             ivars->scratch, ivars->scratch_cap * sizeof(Obj*));
     }
 
-    // Exploit previous sorting, rather than sort cache naively.
+    // Exploit previous sorting, rather than sort buffer naively.
     // Leave the first slice intact if the number of slices is odd. */
     while (ivars->num_slices > 1) {
         uint32_t i = 0;

http://git-wip-us.apache.org/repos/asf/lucy/blob/00181bd4/core/Lucy/Util/SortExternal.cfh
----------------------------------------------------------------------
diff --git a/core/Lucy/Util/SortExternal.cfh b/core/Lucy/Util/SortExternal.cfh
index 917f5df..5ffb44c 100644
--- a/core/Lucy/Util/SortExternal.cfh
+++ b/core/Lucy/Util/SortExternal.cfh
@@ -26,7 +26,7 @@ parcel Lucy;
  * It's expected that the total memory footprint of the sortable objects will
  * eventually exceed a specified threshold; at that point, the SortExternal
  * object will call the abstract method Flush().  It's expected that Flush()
- * implementations will empty out the current sort cache, write a sorted "run"
+ * implementations will empty out the current sort buffer, write a sorted "run"
  * to external storage, and add a new child SortExternal object to the top
  * level object's "runs" array to represent the flushed content.
  *
@@ -59,7 +59,7 @@ abstract class Lucy::Util::SortExternal nickname SortEx
     abstract int
     Compare(SortExternal *self, void *va, void *vb);
 
-    /** Flush all elements currently in the cache.
+    /** Flush all elements currently in the buffer.
      *
      * Presumably this entails sorting everything, writing the sorted elements
      * to disk, spawning a child object to represent those elements, and
@@ -100,31 +100,31 @@ abstract class Lucy::Util::SortExternal nickname SortEx
     void
     Shrink(SortExternal *self);
 
-    /** Refill the cache of a run.  Will only be called on child objects, not
+    /** Refill the buffer of a run.  Will only be called on child objects, not
      * the main object.
      */
     abstract uint32_t
     Refill(SortExternal *self);
 
-    /** Sort all items currently in the main cache.
+    /** Sort all items currently in the main buffer.
      */
     void
     Sort_Buffer(SortExternal *self);
 
-    /** Reset cache variables so that cache gives the appearance of having
+    /** Reset buffer variables so that buffer gives the appearance of having
      * been initialized.
      *
-     * Subclasses may take steps to release items held in cache, if any.
+     * Subclasses may take steps to release items held in buffer, if any.
      */
     void
     Clear_Buffer(SortExternal *self);
 
-    /** Return the number of items presently in the cache.
+    /** Return the number of items presently in the buffer.
      */
     uint32_t
     Buffer_Count(SortExternal *self);
 
-    /** Allocate more memory to the cache.
+    /** Allocate more memory to the buffer.
      */
     void
     Grow_Buffer(SortExternal *self, uint32_t cap);


[lucy-commits] [12/16] git commit: refs/heads/master - Purge some obsolete code from SortExternal.

Posted by ma...@apache.org.
Purge some obsolete code from SortExternal.


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

Branch: refs/heads/master
Commit: 79f4ca56a4509cece13bdd241685cc8bd2ef425d
Parents: 7677ad4
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Tue Jan 8 18:12:09 2013 -0800
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Sat Apr 26 14:17:18 2014 -0700

----------------------------------------------------------------------
 core/Lucy/Util/SortExternal.cfh          | 11 -----------
 perl/buildlib/Lucy/Build/Binding/Util.pm | 12 ------------
 2 files changed, 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/79f4ca56/core/Lucy/Util/SortExternal.cfh
----------------------------------------------------------------------
diff --git a/core/Lucy/Util/SortExternal.cfh b/core/Lucy/Util/SortExternal.cfh
index cfc0591..a813459 100644
--- a/core/Lucy/Util/SortExternal.cfh
+++ b/core/Lucy/Util/SortExternal.cfh
@@ -16,17 +16,6 @@
 
 parcel Lucy;
 
-__C__
-#include <stddef.h>
-#include "Clownfish/Obj.h"
-#include "Clownfish/Util/SortUtils.h"
-
-#define LUCY_SORTEX_DEFAULT_MEM_THRESHOLD 0x1000000
-#ifdef LUCY_USE_SHORT_NAMES
-  #define SORTEX_DEFAULT_MEM_THRESHOLD LUCY_SORTEX_DEFAULT_MEM_THRESHOLD
-#endif
-__END_C__
-
 /** Abstract external sorter.
  *
  * SortExternal objects are sort pools which allow you to sort large amounts

http://git-wip-us.apache.org/repos/asf/lucy/blob/79f4ca56/perl/buildlib/Lucy/Build/Binding/Util.pm
----------------------------------------------------------------------
diff --git a/perl/buildlib/Lucy/Build/Binding/Util.pm b/perl/buildlib/Lucy/Build/Binding/Util.pm
index 5bd6ed9..4ef7dbe 100644
--- a/perl/buildlib/Lucy/Build/Binding/Util.pm
+++ b/perl/buildlib/Lucy/Build/Binding/Util.pm
@@ -179,22 +179,10 @@ END_XS_CODE
 }
 
 sub bind_sortexternal {
-    my $xs_code = <<'END_XS_CODE';
-MODULE = Lucy    PACKAGE = Lucy::Util::SortExternal
-
-IV
-_DEFAULT_MEM_THRESHOLD()
-CODE:
-    RETVAL = LUCY_SORTEX_DEFAULT_MEM_THRESHOLD;
-OUTPUT: RETVAL
-END_XS_CODE
-
     my $binding = Clownfish::CFC::Binding::Perl::Class->new(
         parcel     => "Lucy",
         class_name => "Lucy::Util::SortExternal",
     );
-    $binding->append_xs($xs_code);
-
     Clownfish::CFC::Binding::Perl::Class->register($binding);
 }
 


[lucy-commits] [04/16] git commit: refs/heads/master - Use object-based elements within SortFieldWriter.

Posted by ma...@apache.org.
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/bb2a97d7
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/bb2a97d7
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/bb2a97d7

Branch: refs/heads/master
Commit: bb2a97d7bac3fc7fb43009c06594a0bd3d06b350
Parents: 8369f5f
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Fri Jan 4 14:19:27 2013 -0800
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Sat Apr 26 11:26:56 2014 -0700

----------------------------------------------------------------------
 core/Lucy/Index/SortFieldWriter.c   | 80 +++++++++++++++++++++++---------
 core/Lucy/Index/SortFieldWriter.cfh | 19 ++++++++
 2 files changed, 78 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/bb2a97d7/core/Lucy/Index/SortFieldWriter.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/SortFieldWriter.c b/core/Lucy/Index/SortFieldWriter.c
index 123e7f6..7c0e770 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,
@@ -196,10 +197,8 @@ SortFieldWriter_Add_IMP(SortFieldWriter *self, int32_t doc_id, Obj *value) {
     SortFieldWriterIVARS *const ivars = SortFieldWriter_IVARS(self);
 
     // Uniq-ify the value, and record it for this document.
-    SFWriterElem *elem
-        = (SFWriterElem*)MemPool_Grab(ivars->mem_pool, sizeof(SFWriterElem));
-    elem->value = S_find_unique_value(ivars->uniq_vals, value);
-    elem->doc_id = doc_id;
+    Obj *copy = S_find_unique_value(ivars->uniq_vals, value);
+    SFWriterElem *elem = S_SFWriterElem_create(ivars->mem_pool, copy, doc_id);
     SortFieldWriter_Feed(self, &elem);
     ivars->count++;
 }
@@ -342,8 +341,8 @@ S_write_val(Obj *val, int8_t prim_id, OutStream *ix_out, OutStream *dat_out,
 int
 SortFieldWriter_Compare_IMP(SortFieldWriter *self, void *va, void *vb) {
     SortFieldWriterIVARS *const ivars = SortFieldWriter_IVARS(self);
-    SFWriterElem *a = *(SFWriterElem**)va;
-    SFWriterElem *b = *(SFWriterElem**)vb;
+    SFWriterElemIVARS *a = SFWriterElem_IVARS(*(SFWriterElem**)va);
+    SFWriterElemIVARS *b = SFWriterElem_IVARS(*(SFWriterElem**)vb);
     int32_t comparison
         = FType_null_back_compare_values(ivars->type, a->value, b->value);
     if (comparison == 0) { comparison = b->doc_id - a->doc_id; }
@@ -561,27 +560,31 @@ S_write_files(SortFieldWriter *self, OutStream *ord_out, OutStream *ix_out,
     // doc id 0.
     SFWriterElem **elem_ptr = (SFWriterElem**)SortFieldWriter_Fetch(self);
     SFWriterElem *elem = *elem_ptr;
-    ords[elem->doc_id] = ord;
+    SFWriterElemIVARS *elem_ivars = SFWriterElem_IVARS(elem);
+    ords[elem_ivars->doc_id] = ord;
     ords[0] = 0;
 
     // Build array of ords, write non-NULL sorted values.
-    ivars->last_val = INCREF(elem->value);
-    Obj *last_val_address = elem->value;
-    S_write_val(elem->value, prim_id, ix_out, dat_out, dat_start);
+    ivars->last_val = INCREF(elem_ivars->value);
+    Obj *last_val_address = elem_ivars->value;
+    S_write_val(elem_ivars->value, prim_id, ix_out, dat_out, dat_start);
     while (NULL != (elem_ptr = (SFWriterElem**)SortFieldWriter_Fetch(self))) {
         elem = *elem_ptr;
-        if (elem->value != last_val_address) {
+        elem_ivars = SFWriterElem_IVARS(elem);
+        if (elem_ivars->value != last_val_address) {
             int32_t comparison
-                = FType_Compare_Values(ivars->type, elem->value, ivars->last_val);
+                = FType_Compare_Values(ivars->type, elem_ivars->value,
+                                       ivars->last_val);
             if (comparison != 0) {
                 ord++;
-                S_write_val(elem->value, prim_id, ix_out, dat_out, dat_start);
+                S_write_val(elem_ivars->value, prim_id, ix_out, dat_out,
+                            dat_start);
                 DECREF(ivars->last_val);
-                ivars->last_val = INCREF(elem->value);
+                ivars->last_val = INCREF(elem_ivars->value);
             }
-            last_val_address = elem->value;
+            last_val_address = elem_ivars->value;
         }
-        ords[elem->doc_id] = ord;
+        ords[elem_ivars->doc_id] = ord;
     }
     DECREF(ivars->last_val);
     ivars->last_val = NULL;
@@ -750,4 +753,39 @@ 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);
+    SFWriterElemIVARS *ivars = SFWriterElem_IVARS(self);
+    ivars->value  = value;
+    ivars->doc_id = doc_id;
+    return self;
+}
+
+void
+SFWriterElem_Destroy_IMP(SFWriterElem *self) {
+    UNUSED_VAR(self);
+    THROW(ERR, "Illegal attempt to destroy SFWriterElem object");
+}
+
+uint32_t
+SFWriterElem_Get_RefCount_IMP(SFWriterElem* self) {
+    UNUSED_VAR(self);
+    return 1;
+}
+
+SFWriterElem*
+SFWriterElem_Inc_RefCount_IMP(SFWriterElem* self) {
+    return self;
+}
+
+uint32_t
+SFWriterElem_Dec_RefCount_IMP(SFWriterElem* self) {
+    UNUSED_VAR(self);
+    return 1;
+}
 

http://git-wip-us.apache.org/repos/asf/lucy/blob/bb2a97d7/core/Lucy/Index/SortFieldWriter.cfh
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/SortFieldWriter.cfh b/core/Lucy/Index/SortFieldWriter.cfh
index ac25515..00e85c1 100644
--- a/core/Lucy/Index/SortFieldWriter.cfh
+++ b/core/Lucy/Index/SortFieldWriter.cfh
@@ -100,4 +100,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);
+}
+
 


[lucy-commits] [13/16] git commit: refs/heads/master - Rename some vars in SortExternal.

Posted by ma...@apache.org.
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/4cff84bc
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/4cff84bc
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/4cff84bc

Branch: refs/heads/master
Commit: 4cff84bc0451fe784c074bc6866e6d8229be2903
Parents: 79f4ca5
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Wed Jan 9 13:14:00 2013 -0800
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Sat Apr 26 16:00:52 2014 -0700

----------------------------------------------------------------------
 core/Lucy/Index/PostingPool.c     |  42 +++++------
 core/Lucy/Index/SortFieldWriter.c |  24 +++---
 core/Lucy/Util/BBSortEx.c         |  30 ++++----
 core/Lucy/Util/SortExternal.c     | 130 ++++++++++++++++-----------------
 core/Lucy/Util/SortExternal.cfh   |  10 +--
 5 files changed, 118 insertions(+), 118 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/4cff84bc/core/Lucy/Index/PostingPool.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/PostingPool.c b/core/Lucy/Index/PostingPool.c
index cc56c34..9c538ed 100644
--- a/core/Lucy/Index/PostingPool.c
+++ b/core/Lucy/Index/PostingPool.c
@@ -191,7 +191,7 @@ PostPool_Flip_IMP(PostingPool *self) {
     }
 
     PostPool_Sort_Cache(self);
-    if (num_runs && (ivars->cache_max - ivars->cache_tick) > 0) {
+    if (num_runs && (ivars->buf_max - ivars->buf_tick) > 0) {
         uint32_t num_items = PostPool_Cache_Count(self);
         // Cheap imitation of flush. FIXME.
         PostingPool *run
@@ -202,12 +202,12 @@ PostPool_Flip_IMP(PostingPool *self) {
         PostPool_Grow_Cache(run, num_items);
         PostingPoolIVARS *const run_ivars = PostPool_IVARS(run);
 
-        memcpy(run_ivars->cache, (ivars->cache) + ivars->cache_tick,
+        memcpy(run_ivars->buffer, (ivars->buffer) + ivars->buf_tick,
                num_items * sizeof(Obj*));
-        run_ivars->cache_max = num_items;
+        run_ivars->buf_max = num_items;
         PostPool_Add_Run(self, (SortExternal*)run);
-        ivars->cache_tick = 0;
-        ivars->cache_max = 0;
+        ivars->buf_tick = 0;
+        ivars->buf_max = 0;
     }
 
     // Assign.
@@ -278,10 +278,10 @@ PostPool_Flush_IMP(PostingPool *self) {
                                             ivars->post_temp_out);
 
     // Borrow the cache.
-    run_ivars->cache      = ivars->cache;
-    run_ivars->cache_tick = ivars->cache_tick;
-    run_ivars->cache_max  = ivars->cache_max;
-    run_ivars->cache_cap  = ivars->cache_cap;
+    run_ivars->buffer   = ivars->buffer;
+    run_ivars->buf_tick = ivars->buf_tick;
+    run_ivars->buf_max  = ivars->buf_max;
+    run_ivars->buf_cap  = ivars->buf_cap;
 
     // Write to temp files.
     LexWriter_Enter_Temp_Mode(ivars->lex_writer, ivars->field,
@@ -296,10 +296,10 @@ PostPool_Flush_IMP(PostingPool *self) {
     LexWriter_Leave_Temp_Mode(ivars->lex_writer);
 
     // Return the cache and empty it.
-    run_ivars->cache      = NULL;
-    run_ivars->cache_tick = 0;
-    run_ivars->cache_max  = 0;
-    run_ivars->cache_cap  = 0;
+    run_ivars->buffer   = NULL;
+    run_ivars->buf_tick = 0;
+    run_ivars->buf_max  = 0;
+    run_ivars->buf_cap  = 0;
     PostPool_Clear_Cache(self);
 
     // Add the run to the array.
@@ -459,12 +459,12 @@ PostPool_Refill_IMP(PostingPool *self) {
     else { term_text = (String*)Lex_Get_Term(lexicon); }
 
     // Make sure cache is empty.
-    if (ivars->cache_max - ivars->cache_tick > 0) {
+    if (ivars->buf_max - ivars->buf_tick > 0) {
         THROW(ERR, "Refill called but cache contains %u32 items",
-              ivars->cache_max - ivars->cache_tick);
+              ivars->buf_max - ivars->buf_tick);
     }
-    ivars->cache_max  = 0;
-    ivars->cache_tick = 0;
+    ivars->buf_max  = 0;
+    ivars->buf_tick = 0;
 
     // Ditch old MemoryPool and get another.
     DECREF(ivars->mem_pool);
@@ -515,17 +515,17 @@ PostPool_Refill_IMP(PostingPool *self) {
         }
 
         // Add to the run's cache.
-        if (num_elems >= ivars->cache_cap) {
+        if (num_elems >= ivars->buf_cap) {
             size_t new_cap = Memory_oversize(num_elems + 1, sizeof(Obj*));
             PostPool_Grow_Cache(self, new_cap);
         }
-        ivars->cache[num_elems] = (Obj*)rawpost;
+        ivars->buffer[num_elems] = (Obj*)rawpost;
         num_elems++;
     }
 
     // Reset the cache array position and length; remember file pos.
-    ivars->cache_max   = num_elems;
-    ivars->cache_tick  = 0;
+    ivars->buf_max   = num_elems;
+    ivars->buf_tick  = 0;
 
     return num_elems;
 }

http://git-wip-us.apache.org/repos/asf/lucy/blob/4cff84bc/core/Lucy/Index/SortFieldWriter.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/SortFieldWriter.c b/core/Lucy/Index/SortFieldWriter.c
index 2e55a39..1a0d5ff 100644
--- a/core/Lucy/Index/SortFieldWriter.c
+++ b/core/Lucy/Index/SortFieldWriter.c
@@ -399,10 +399,10 @@ SortFieldWriter_Flush_IMP(SortFieldWriter *self) {
     run_ivars->dat_start = OutStream_Align(temp_dat_out, sizeof(int64_t));
 
     // Have the run borrow the array of elems.
-    run_ivars->cache      = ivars->cache;
-    run_ivars->cache_max  = ivars->cache_max;
-    run_ivars->cache_tick = ivars->cache_tick;
-    run_ivars->cache_cap  = ivars->cache_cap;
+    run_ivars->buffer   = ivars->buffer;
+    run_ivars->buf_max  = ivars->buf_max;
+    run_ivars->buf_tick = ivars->buf_tick;
+    run_ivars->buf_cap  = ivars->buf_cap;
 
     // Write files, record stats.
     run_ivars->run_max = (int32_t)Seg_Get_Count(ivars->segment);
@@ -410,11 +410,11 @@ SortFieldWriter_Flush_IMP(SortFieldWriter *self) {
                                                temp_dat_out);
 
     // Reclaim the buffer from the run and empty it.
-    run_ivars->cache       = NULL;
-    run_ivars->cache_max   = 0;
-    run_ivars->cache_tick  = 0;
-    run_ivars->cache_cap   = 0;
-    ivars->cache_tick = ivars->cache_max;
+    run_ivars->buffer    = NULL;
+    run_ivars->buf_max   = 0;
+    run_ivars->buf_tick  = 0;
+    run_ivars->buf_cap   = 0;
+    ivars->buf_tick = ivars->buf_max;
     SortFieldWriter_Clear_Cache(self);
 
     // Record stream ends.
@@ -434,10 +434,10 @@ SortFieldWriter_Refill_IMP(SortFieldWriter *self) {
     if (!ivars->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_Cache_Count(self);
+    if (buf_count) {
         THROW(ERR, "Refill called but cache contains %u32 items",
-              cache_count);
+              buf_count);
     }
     SortFieldWriter_Clear_Cache(self);
     MemPool_Release_All(ivars->mem_pool);

http://git-wip-us.apache.org/repos/asf/lucy/blob/4cff84bc/core/Lucy/Util/BBSortEx.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Util/BBSortEx.c b/core/Lucy/Util/BBSortEx.c
index c5c4c13..156ab02 100644
--- a/core/Lucy/Util/BBSortEx.c
+++ b/core/Lucy/Util/BBSortEx.c
@@ -76,24 +76,24 @@ BBSortEx_Feed_IMP(BBSortEx *self, Obj *item) {
 void
 BBSortEx_Flush_IMP(BBSortEx *self) {
     BBSortExIVARS *const ivars = BBSortEx_IVARS(self);
-    uint32_t     cache_count = ivars->cache_max - ivars->cache_tick;
-    Obj        **cache = ivars->cache;
+    uint32_t     buf_count = ivars->buf_max - ivars->buf_tick;
+    Obj        **buffer = ivars->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);
-    for (uint32_t i = ivars->cache_tick; i < ivars->cache_max; i++) {
-        VA_Push(elems, cache[i]);
+    for (uint32_t i = ivars->buf_tick; i < ivars->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.
-    ivars->cache_tick += cache_count;
+    ivars->buf_tick += buf_count;
     BBSortEx_Clear_Cache(self);
 }
 
@@ -102,12 +102,12 @@ BBSortEx_Refill_IMP(BBSortEx *self) {
     BBSortExIVARS *const ivars = BBSortEx_IVARS(self);
 
     // Make sure cache is empty, then set cache tick vars.
-    if (ivars->cache_max - ivars->cache_tick > 0) {
+    if (ivars->buf_max - ivars->buf_tick > 0) {
         THROW(ERR, "Refill called but cache contains %u32 items",
-              ivars->cache_max - ivars->cache_tick);
+              ivars->buf_max - ivars->buf_tick);
     }
-    ivars->cache_tick = 0;
-    ivars->cache_max  = 0;
+    ivars->buf_tick = 0;
+    ivars->buf_max  = 0;
 
     // Read in elements.
     while (1) {
@@ -127,15 +127,15 @@ BBSortEx_Refill_IMP(BBSortEx *self) {
             ivars->mem_consumed += BB_Get_Size(elem);
         }
 
-        if (ivars->cache_max == ivars->cache_cap) {
+        if (ivars->buf_max == ivars->buf_cap) {
             BBSortEx_Grow_Cache(self,
-                                Memory_oversize(ivars->cache_max + 1,
+                                Memory_oversize(ivars->buf_max + 1,
                                                 sizeof(Obj*)));
         }
-        ivars->cache[ivars->cache_max++] = INCREF(elem);
+        ivars->buffer[ivars->buf_max++] = INCREF(elem);
     }
 
-    return ivars->cache_max;
+    return ivars->buf_max;
 }
 
 void

http://git-wip-us.apache.org/repos/asf/lucy/blob/4cff84bc/core/Lucy/Util/SortExternal.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Util/SortExternal.c b/core/Lucy/Util/SortExternal.c
index f8a2690..ce42550 100644
--- a/core/Lucy/Util/SortExternal.c
+++ b/core/Lucy/Util/SortExternal.c
@@ -45,10 +45,10 @@ SortEx_init(SortExternal *self) {
     SortExternalIVARS *const ivars = SortEx_IVARS(self);
 
     ivars->mem_thresh   = UINT32_MAX;
-    ivars->cache        = NULL;
-    ivars->cache_cap    = 0;
-    ivars->cache_max    = 0;
-    ivars->cache_tick   = 0;
+    ivars->buffer       = NULL;
+    ivars->buf_cap      = 0;
+    ivars->buf_max      = 0;
+    ivars->buf_tick     = 0;
     ivars->scratch      = NULL;
     ivars->scratch_cap  = 0;
     ivars->runs         = VA_new(0);
@@ -67,9 +67,9 @@ SortEx_Destroy_IMP(SortExternal *self) {
     FREEMEM(ivars->scratch);
     FREEMEM(ivars->slice_sizes);
     FREEMEM(ivars->slice_starts);
-    if (ivars->cache) {
+    if (ivars->buffer) {
         SortEx_Clear_Cache(self);
-        FREEMEM(ivars->cache);
+        FREEMEM(ivars->buffer);
     }
     DECREF(ivars->runs);
     SUPER_DESTROY(self, SORTEXTERNAL);
@@ -78,34 +78,34 @@ SortEx_Destroy_IMP(SortExternal *self) {
 void
 SortEx_Clear_Cache_IMP(SortExternal *self) {
     SortExternalIVARS *const ivars = SortEx_IVARS(self);
-    Obj **const cache = ivars->cache;
-    const uint32_t max = ivars->cache_max;
-    for (uint32_t i = ivars->cache_tick; i < max; i++) {
-        DECREF(cache[i]);
+    Obj **const buffer = ivars->buffer;
+    const uint32_t max = ivars->buf_max;
+    for (uint32_t i = ivars->buf_tick; i < max; i++) {
+        DECREF(buffer[i]);
     }
-    ivars->cache_max    = 0;
-    ivars->cache_tick   = 0;
+    ivars->buf_max    = 0;
+    ivars->buf_tick   = 0;
 }
 
 void
 SortEx_Feed_IMP(SortExternal *self, Obj *item) {
     SortExternalIVARS *const ivars = SortEx_IVARS(self);
-    if (ivars->cache_max == ivars->cache_cap) {
-        size_t amount = Memory_oversize(ivars->cache_max + 1, sizeof(Obj*));
+    if (ivars->buf_max == ivars->buf_cap) {
+        size_t amount = Memory_oversize(ivars->buf_max + 1, sizeof(Obj*));
         SortEx_Grow_Cache(self, amount);
     }
-    ivars->cache[ivars->cache_max] = item;
-    ivars->cache_max++;
+    ivars->buffer[ivars->buf_max] = item;
+    ivars->buf_max++;
 }
 
 static CFISH_INLINE Obj*
 SI_peek(SortExternal *self, SortExternalIVARS *ivars) {
-    if (ivars->cache_tick >= ivars->cache_max) {
+    if (ivars->buf_tick >= ivars->buf_max) {
         S_refill_cache(self, ivars);
     }
 
-    if (ivars->cache_max > 0) {
-        return ivars->cache[ivars->cache_tick];
+    if (ivars->buf_max > 0) {
+        return ivars->buffer[ivars->buf_tick];
     }
     else {
         return NULL;
@@ -116,7 +116,7 @@ Obj*
 SortEx_Fetch_IMP(SortExternal *self) {
     SortExternalIVARS *const ivars = SortEx_IVARS(self);
     Obj *item = SI_peek(self, ivars);
-    ivars->cache_tick++;
+    ivars->buf_tick++;
     return item;
 }
 
@@ -129,20 +129,20 @@ SortEx_Peek_IMP(SortExternal *self) {
 void
 SortEx_Sort_Cache_IMP(SortExternal *self) {
     SortExternalIVARS *const ivars = SortEx_IVARS(self);
-    if (ivars->cache_tick != 0) {
-        THROW(ERR, "Cant Sort_Cache() after fetching %u32 items", ivars->cache_tick);
+    if (ivars->buf_tick != 0) {
+        THROW(ERR, "Cant Sort_Cache() after fetching %u32 items", ivars->buf_tick);
     }
-    if (ivars->cache_max != 0) {
+    if (ivars->buf_max != 0) {
         VTable *vtable = SortEx_Get_VTable(self);
         CFISH_Sort_Compare_t compare
             = (CFISH_Sort_Compare_t)METHOD_PTR(vtable, LUCY_SortEx_Compare);
-        if (ivars->scratch_cap < ivars->cache_cap) {
-            ivars->scratch_cap = ivars->cache_cap;
+        if (ivars->scratch_cap < ivars->buf_cap) {
+            ivars->scratch_cap = ivars->buf_cap;
             ivars->scratch
                 = (Obj**)REALLOCATE(ivars->scratch,
                                     ivars->scratch_cap * sizeof(Obj*));
         }
-        Sort_mergesort(ivars->cache, ivars->scratch, ivars->cache_max,
+        Sort_mergesort(ivars->buffer, ivars->scratch, ivars->buf_max,
                        sizeof(Obj*), compare, self);
     }
 }
@@ -168,24 +168,24 @@ SortEx_Add_Run_IMP(SortExternal *self, SortExternal *run) {
 void
 SortEx_Shrink_IMP(SortExternal *self) {
     SortExternalIVARS *const ivars = SortEx_IVARS(self);
-    if (ivars->cache_max - ivars->cache_tick > 0) {
-        size_t cache_count = SortEx_Cache_Count(self);
-        size_t size        = cache_count * sizeof(Obj*);
-        if (ivars->cache_tick > 0) {
-            Obj **start = ivars->cache + ivars->cache_tick;
-            memmove(ivars->cache, start, size);
+    if (ivars->buf_max - ivars->buf_tick > 0) {
+        size_t buf_count = SortEx_Cache_Count(self);
+        size_t size        = buf_count * sizeof(Obj*);
+        if (ivars->buf_tick > 0) {
+            Obj **start = ivars->buffer + ivars->buf_tick;
+            memmove(ivars->buffer, start, size);
         }
-        ivars->cache      = (Obj**)REALLOCATE(ivars->cache, size);
-        ivars->cache_tick = 0;
-        ivars->cache_max  = cache_count;
-        ivars->cache_cap  = cache_count;
+        ivars->buffer   = (Obj**)REALLOCATE(ivars->buffer, size);
+        ivars->buf_tick = 0;
+        ivars->buf_max  = buf_count;
+        ivars->buf_cap  = buf_count;
     }
     else {
-        FREEMEM(ivars->cache);
-        ivars->cache      = NULL;
-        ivars->cache_tick = 0;
-        ivars->cache_max  = 0;
-        ivars->cache_cap  = 0;
+        FREEMEM(ivars->buffer);
+        ivars->buffer   = NULL;
+        ivars->buf_tick = 0;
+        ivars->buf_max  = 0;
+        ivars->buf_cap  = 0;
     }
     ivars->scratch_cap = 0;
     FREEMEM(ivars->scratch);
@@ -229,15 +229,15 @@ S_find_endpost(SortExternal *self, SortExternalIVARS *ivars) {
         // Get a run and retrieve the last item in its cache.
         SortExternal *const run = (SortExternal*)VA_Fetch(ivars->runs, i);
         SortExternalIVARS *const run_ivars = SortEx_IVARS(run);
-        const uint32_t tick = run_ivars->cache_max - 1;
-        if (tick >= run_ivars->cache_cap || run_ivars->cache_max < 1) {
+        const uint32_t tick = run_ivars->buf_max - 1;
+        if (tick >= run_ivars->buf_cap || run_ivars->buf_max < 1) {
             THROW(ERR, "Invalid SortExternal cache access: %u32 %u32 %u32", tick,
-                  run_ivars->cache_max, run_ivars->cache_cap);
+                  run_ivars->buf_max, run_ivars->buf_cap);
         }
         else {
             // Cache item with the highest sort value currently held in memory
             // by the run.
-            Obj **candidate = run_ivars->cache + tick;
+            Obj **candidate = run_ivars->buffer + tick;
 
             // If it's the first run, item is automatically the new endpost.
             if (i == 0) {
@@ -263,7 +263,7 @@ S_absorb_slices(SortExternal *self, SortExternalIVARS *ivars,
     CFISH_Sort_Compare_t compare
         = (CFISH_Sort_Compare_t)METHOD_PTR(vtable, LUCY_SortEx_Compare);
 
-    if (ivars->cache_max != 0) { THROW(ERR, "Can't refill unless empty"); }
+    if (ivars->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++) {
@@ -273,16 +273,16 @@ S_absorb_slices(SortExternal *self, SortExternalIVARS *ivars,
 
         if (slice_size) {
             // Move slice content from run cache to main cache.
-            if (ivars->cache_max + slice_size > ivars->cache_cap) {
-                size_t cap = Memory_oversize(ivars->cache_max + slice_size,
+            if (ivars->buf_max + slice_size > ivars->buf_cap) {
+                size_t cap = Memory_oversize(ivars->buf_max + slice_size,
                                              sizeof(Obj*));
                 SortEx_Grow_Cache(self, cap);
             }
-            memcpy(ivars->cache + ivars->cache_max,
-                   run_ivars->cache + run_ivars->cache_tick,
+            memcpy(ivars->buffer + ivars->buf_max,
+                   run_ivars->buffer + run_ivars->buf_tick,
                    slice_size * sizeof(Obj*));
-            run_ivars->cache_tick += slice_size;
-            ivars->cache_max += slice_size;
+            run_ivars->buf_tick += slice_size;
+            ivars->buf_max += slice_size;
 
             // Track number of slices and slice sizes.
             slice_sizes[ivars->num_slices++] = slice_size;
@@ -292,14 +292,14 @@ S_absorb_slices(SortExternal *self, SortExternalIVARS *ivars,
     // Transform slice starts from ticks to pointers.
     uint32_t total = 0;
     for (uint32_t i = 0; i < ivars->num_slices; i++) {
-        slice_starts[i] = ivars->cache + total;
+        slice_starts[i] = ivars->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 (ivars->scratch_cap < ivars->cache_cap) {
-        ivars->scratch_cap = ivars->cache_cap;
+    if (ivars->scratch_cap < ivars->buf_cap) {
+        ivars->scratch_cap = ivars->buf_cap;
         ivars->scratch = (Obj**)REALLOCATE(
                             ivars->scratch, ivars->scratch_cap * sizeof(Obj*));
     }
@@ -338,27 +338,27 @@ S_absorb_slices(SortExternal *self, SortExternalIVARS *ivars,
 }
 
 void
-SortEx_Grow_Cache_IMP(SortExternal *self, uint32_t size) {
+SortEx_Grow_Cache_IMP(SortExternal *self, uint32_t cap) {
     SortExternalIVARS *const ivars = SortEx_IVARS(self);
-    if (size > ivars->cache_cap) {
-        ivars->cache = (Obj**)REALLOCATE(ivars->cache, size * sizeof(Obj*));
-        ivars->cache_cap = size;
+    if (cap > ivars->buf_cap) {
+        ivars->buffer = (Obj**)REALLOCATE(ivars->buffer, cap * sizeof(Obj*));
+        ivars->buf_cap = cap;
     }
 }
 
 static uint32_t
 S_find_slice_size(SortExternal *self, SortExternalIVARS *ivars,
                   Obj **endpost) {
-    int32_t          lo      = ivars->cache_tick - 1;
-    int32_t          hi      = ivars->cache_max;
-    Obj            **cache   = ivars->cache;
+    int32_t          lo      = ivars->buf_tick - 1;
+    int32_t          hi      = ivars->buf_max;
+    Obj            **buffer  = ivars->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; }
     }
@@ -366,7 +366,7 @@ S_find_slice_size(SortExternal *self, SortExternalIVARS *ivars,
     // If lo is still -1, we didn't find anything.
     return lo == -1
            ? 0
-           : (lo - ivars->cache_tick) + 1;
+           : (lo - ivars->buf_tick) + 1;
 }
 
 void
@@ -377,7 +377,7 @@ SortEx_Set_Mem_Thresh_IMP(SortExternal *self, uint32_t mem_thresh) {
 uint32_t
 SortEx_Cache_Count_IMP(SortExternal *self) {
     SortExternalIVARS *const ivars = SortEx_IVARS(self);
-    return ivars->cache_max - ivars->cache_tick;
+    return ivars->buf_max - ivars->buf_tick;
 }
 
 

http://git-wip-us.apache.org/repos/asf/lucy/blob/4cff84bc/core/Lucy/Util/SortExternal.cfh
----------------------------------------------------------------------
diff --git a/core/Lucy/Util/SortExternal.cfh b/core/Lucy/Util/SortExternal.cfh
index a813459..9674f92 100644
--- a/core/Lucy/Util/SortExternal.cfh
+++ b/core/Lucy/Util/SortExternal.cfh
@@ -38,10 +38,10 @@ parcel Lucy;
 abstract class Lucy::Util::SortExternal nickname 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;
@@ -127,7 +127,7 @@ abstract class Lucy::Util::SortExternal nickname SortEx
     /** Allocate more memory to the cache.
      */
     void
-    Grow_Cache(SortExternal *self, uint32_t new_cache_cap);
+    Grow_Cache(SortExternal *self, uint32_t cap);
 
     void
     Set_Mem_Thresh(SortExternal *self, uint32_t mem_thresh);