lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject svn commit: r902830 - in /lucene/lucy/trunk/core/Lucy/Util: SortUtils.bp SortUtils.c
Date Mon, 25 Jan 2010 14:47:54 GMT
Author: marvin
Date: Mon Jan 25 14:47:54 2010
New Revision: 902830

URL: http://svn.apache.org/viewvc?rev=902830&view=rev
Log:
Consolidate Sort_merge4() and Sort_merge8() into a single function,
Sort_merge(), which takes a "width" argument.

Modified:
    lucene/lucy/trunk/core/Lucy/Util/SortUtils.bp
    lucene/lucy/trunk/core/Lucy/Util/SortUtils.c

Modified: lucene/lucy/trunk/core/Lucy/Util/SortUtils.bp
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Util/SortUtils.bp?rev=902830&r1=902829&r2=902830&view=diff
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Util/SortUtils.bp (original)
+++ lucene/lucy/trunk/core/Lucy/Util/SortUtils.bp Mon Jan 25 14:47:54 2010
@@ -45,19 +45,11 @@
      * Lucy's external sort takes advantage of this when it is reading
      * back pre-sorted runs from disk and merging the streams into a
      * consolidated buffer.
-     * 
-     * merge4 merges elements which are 4 bytes in size; merge8 merges 8-byte
-     * elements.
      */
     inert void
-    merge4(void *left_ptr,  u32_t left_num_elems,
-           void *right_ptr, u32_t right_num_elems,
-           void *dest, Sort_compare_t compare, void *context);
-    inert void
-    merge8(void *left_ptr,  u32_t left_num_elems,
-           void *right_ptr, u32_t right_num_elems,
-           void *dest, Sort_compare_t compare, void *context);
-
+    merge(void *left_ptr,  u32_t left_num_elems,
+          void *right_ptr, u32_t right_num_elems,
+          void *dest, size_t width, Sort_compare_t compare, void *context);
 
     /** Quicksort. 
      */

Modified: lucene/lucy/trunk/core/Lucy/Util/SortUtils.c
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Util/SortUtils.c?rev=902830&r1=902829&r2=902830&view=diff
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Util/SortUtils.c (original)
+++ lucene/lucy/trunk/core/Lucy/Util/SortUtils.c Mon Jan 25 14:47:54 2010
@@ -24,8 +24,6 @@
 S_msort8(EIGHT_BYTE_TYPE *elems, EIGHT_BYTE_TYPE *scratch,
          u32_t left, u32_t right, Sort_compare_t compare, void *context);
 
-/* Static inline versions of Sort_merge4 and Sort_merge8.
- */
 static INLINE void
 SI_merge4(FOUR_BYTE_TYPE *left_ptr,  u32_t left_size,
           FOUR_BYTE_TYPE *right_ptr, u32_t right_size,
@@ -63,23 +61,23 @@
 }
 
 void
-Sort_merge4(void *left_ptr,  u32_t left_size,
-            void *right_ptr, u32_t right_size,
-            void *dest, Sort_compare_t compare, void *context) 
-{
-    SI_merge4((FOUR_BYTE_TYPE*)left_ptr, left_size, 
-              (FOUR_BYTE_TYPE*)right_ptr, right_size, 
-              (FOUR_BYTE_TYPE*)dest, compare, context);
-}
-
-void
-Sort_merge8(void *left_ptr,  u32_t left_size,
-            void *right_ptr, u32_t right_size,
-            void *dest, Sort_compare_t compare, void *context) 
-{
-    SI_merge8((EIGHT_BYTE_TYPE*)left_ptr, left_size, 
-              (EIGHT_BYTE_TYPE*)right_ptr, right_size, 
-              (EIGHT_BYTE_TYPE*)dest, compare, context);
+Sort_merge(void *left_ptr,  u32_t left_size,
+           void *right_ptr, u32_t right_size,
+           void *dest, size_t width, Sort_compare_t compare, void *context)
+{
+    if (width == 4) {
+        SI_merge4((FOUR_BYTE_TYPE*)left_ptr, left_size, 
+                  (FOUR_BYTE_TYPE*)right_ptr, right_size, 
+                  (FOUR_BYTE_TYPE*)dest, compare, context);
+    }
+    else if (width == 8) {
+        SI_merge8((EIGHT_BYTE_TYPE*)left_ptr, left_size, 
+                  (EIGHT_BYTE_TYPE*)right_ptr, right_size, 
+                  (EIGHT_BYTE_TYPE*)dest, compare, context);
+    }
+    else {
+        THROW(ERR, "Invalid value for 'width': %u64", (uint64_t)width);
+    }
 }
 
 static void
@@ -90,7 +88,7 @@
         const u32_t mid = ( (right+left)/2 ) + 1;
         S_msort4(elems, scratch, left, mid - 1, compare, context);
         S_msort4(elems, scratch, mid,  right, compare, context);
-        Sort_merge4( (elems + left),  (mid - left), 
+        SI_merge4( (elems + left),  (mid - left), 
             (elems + mid), (right - mid + 1), scratch, compare, context);
         memcpy((elems + left), scratch,
             ((right - left + 1) * sizeof(FOUR_BYTE_TYPE)) );
@@ -105,7 +103,7 @@
         const u32_t mid = ( (right+left)/2 ) + 1;
         S_msort8(elems, scratch, left, mid - 1, compare, context);
         S_msort8(elems, scratch, mid,  right, compare, context);
-        Sort_merge8( (elems + left),  (mid - left), 
+        SI_merge8( (elems + left),  (mid - left), 
             (elems + mid), (right - mid + 1), scratch, compare, context);
         memcpy((elems + left), scratch,
             ((right - left + 1) * sizeof(EIGHT_BYTE_TYPE)) );



Mime
View raw message