lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nwelln...@apache.org
Subject [13/14] lucy git commit: Switch to system qsort
Date Wed, 29 Apr 2015 19:56:34 GMT
Switch to system qsort


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

Branch: refs/heads/master
Commit: 8b97664d36752780409d14712d1d910cddda529f
Parents: 0c238b1
Author: Nick Wellnhofer <wellnhofer@aevum.de>
Authored: Wed Apr 29 11:32:43 2015 +0200
Committer: Nick Wellnhofer <wellnhofer@aevum.de>
Committed: Wed Apr 29 11:32:43 2015 +0200

----------------------------------------------------------------------
 core/Lucy/Analysis/Inversion.c        | 6 +++---
 core/Lucy/Analysis/Token.c            | 3 +--
 core/Lucy/Analysis/Token.cfh          | 4 ++--
 core/Lucy/Highlight/HeatMap.c         | 9 ++++-----
 core/Lucy/Index/IndexManager.c        | 9 ++++-----
 core/Lucy/Test/Object/TestBitVector.c | 9 ++++-----
 6 files changed, 18 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/8b97664d/core/Lucy/Analysis/Inversion.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Analysis/Inversion.c b/core/Lucy/Analysis/Inversion.c
index 5c34f4c..18e5e23 100644
--- a/core/Lucy/Analysis/Inversion.c
+++ b/core/Lucy/Analysis/Inversion.c
@@ -20,7 +20,8 @@
 
 #include "Lucy/Analysis/Inversion.h"
 #include "Lucy/Analysis/Token.h"
-#include "Clownfish/Util/SortUtils.h"
+
+#include <stdlib.h>
 
 // After inversion, record how many like tokens occur in each group.
 static void
@@ -162,8 +163,7 @@ Inversion_Invert_IMP(Inversion *self) {
     }
 
     // Sort the tokens lexically, and hand off to cluster counting routine.
-    Sort_quicksort(ivars->tokens, ivars->size, sizeof(Token*), Token_compare,
-                   NULL);
+    qsort(ivars->tokens, ivars->size, sizeof(Token*), Token_compare);
     S_count_clusters(self, ivars);
 }
 

http://git-wip-us.apache.org/repos/asf/lucy/blob/8b97664d/core/Lucy/Analysis/Token.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Analysis/Token.c b/core/Lucy/Analysis/Token.c
index eba4714..e365d06 100644
--- a/core/Lucy/Analysis/Token.c
+++ b/core/Lucy/Analysis/Token.c
@@ -58,14 +58,13 @@ Token_Destroy_IMP(Token *self) {
 }
 
 int
-Token_compare(void *context, const void *va, const void *vb) {
+Token_compare(const void *va, const void *vb) {
     Token *const token_a = *((Token**)va);
     Token *const token_b = *((Token**)vb);
     TokenIVARS *const a = Token_IVARS(token_a);
     TokenIVARS *const b = Token_IVARS(token_b);
     size_t min_len = a->len < b->len ? a->len : b->len;
     int comparison = memcmp(a->text, b->text, min_len);
-    UNUSED_VAR(context);
 
     if (comparison == 0) {
         if (a->len != b->len) {

http://git-wip-us.apache.org/repos/asf/lucy/blob/8b97664d/core/Lucy/Analysis/Token.cfh
----------------------------------------------------------------------
diff --git a/core/Lucy/Analysis/Token.cfh b/core/Lucy/Analysis/Token.cfh
index 0c229dd..b57f185 100644
--- a/core/Lucy/Analysis/Token.cfh
+++ b/core/Lucy/Analysis/Token.cfh
@@ -68,10 +68,10 @@ class Lucy::Analysis::Token inherits Clownfish::Obj {
          uint32_t start_offset, uint32_t end_offset,
          float boost = 1.0, int32_t pos_inc = 1);
 
-    /** Sort_quicksort-compatible comparison routine.
+    /** qsort-compatible comparison routine.
      */
     inert int
-    compare(void *context, const void *va, const void *vb);
+    compare(const void *va, const void *vb);
 
     uint32_t
     Get_Start_Offset(Token *self);

http://git-wip-us.apache.org/repos/asf/lucy/blob/8b97664d/core/Lucy/Highlight/HeatMap.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Highlight/HeatMap.c b/core/Lucy/Highlight/HeatMap.c
index 62d1b87..621a18d 100644
--- a/core/Lucy/Highlight/HeatMap.c
+++ b/core/Lucy/Highlight/HeatMap.c
@@ -19,7 +19,8 @@
 
 #include "Lucy/Highlight/HeatMap.h"
 #include "Lucy/Search/Span.h"
-#include "Clownfish/Util/SortUtils.h"
+
+#include <stdlib.h>
 
 HeatMap*
 HeatMap_new(Vector *spans, uint32_t window) {
@@ -56,8 +57,7 @@ HeatMap_Destroy_IMP(HeatMap *self) {
 }
 
 static int
-S_compare_i32(void *context, const void *va, const void *vb) {
-    UNUSED_VAR(context);
+S_compare_i32(const void *va, const void *vb) {
     return *(int32_t*)va - *(int32_t*)vb;
 }
 
@@ -74,8 +74,7 @@ S_flattened_but_empty_spans(Vector *spans) {
         bounds[i]             = Span_Get_Offset(span);
         bounds[i + num_spans] = Span_Get_Offset(span) + Span_Get_Length(span);
     }
-    Sort_quicksort(bounds, num_spans * 2, sizeof(uint32_t),
-                   S_compare_i32, NULL);
+    qsort(bounds, num_spans * 2, sizeof(uint32_t), S_compare_i32);
     uint32_t num_bounds = 0;
     int32_t  last       = INT32_MAX;
     for (uint32_t i = 0; i < num_spans * 2; i++) {

http://git-wip-us.apache.org/repos/asf/lucy/blob/8b97664d/core/Lucy/Index/IndexManager.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Index/IndexManager.c b/core/Lucy/Index/IndexManager.c
index b780716..9ba2d5f 100644
--- a/core/Lucy/Index/IndexManager.c
+++ b/core/Lucy/Index/IndexManager.c
@@ -29,9 +29,10 @@
 #include "Lucy/Store/LockFactory.h"
 #include "Lucy/Util/IndexFileNames.h"
 #include "Lucy/Util/Json.h"
-#include "Clownfish/Util/SortUtils.h"
 #include "Clownfish/Util/StringHelper.h"
 
+#include <stdlib.h>
+
 IndexManager*
 IxManager_new(String *host, LockFactory *lock_factory) {
     IndexManager *self = (IndexManager*)Class_Make_Obj(INDEXMANAGER);
@@ -109,10 +110,9 @@ IxManager_Make_Snapshot_Filename_IMP(IndexManager *self) {
 }
 
 static int
-S_compare_doc_count(void *context, const void *va, const void *vb) {
+S_compare_doc_count(const void *va, const void *vb) {
     SegReader *a = *(SegReader**)va;
     SegReader *b = *(SegReader**)vb;
-    UNUSED_VAR(context);
     return SegReader_Doc_Count(a) - SegReader_Doc_Count(b);
 }
 
@@ -158,8 +158,7 @@ IxManager_Recycle_IMP(IndexManager *self, PolyReader *reader,
     }
 
     // Sort by ascending size in docs, choose sparsely populated segments.
-    Sort_quicksort(candidates, num_candidates, sizeof(SegReader*),
-                   S_compare_doc_count, NULL);
+    qsort(candidates, num_candidates, sizeof(SegReader*), S_compare_doc_count);
     int32_t *counts = (int32_t*)MALLOCATE(num_candidates * sizeof(int32_t));
     for (uint32_t i = 0; i < num_candidates; i++) {
         counts[i] = SegReader_Doc_Count(candidates[i]);

http://git-wip-us.apache.org/repos/asf/lucy/blob/8b97664d/core/Lucy/Test/Object/TestBitVector.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Test/Object/TestBitVector.c b/core/Lucy/Test/Object/TestBitVector.c
index 59877d6..1ad92fa 100644
--- a/core/Lucy/Test/Object/TestBitVector.c
+++ b/core/Lucy/Test/Object/TestBitVector.c
@@ -18,13 +18,14 @@
 #define TESTLUCY_USE_SHORT_NAMES
 #include "Lucy/Util/ToolSet.h"
 
-#include "Clownfish/Util/SortUtils.h"
 #include "Clownfish/TestHarness/TestBatchRunner.h"
 #include "Clownfish/TestHarness/TestUtils.h"
 #include "Lucy/Test.h"
 #include "Lucy/Test/TestUtils.h"
 #include "Lucy/Test/Object/TestBitVector.h"
 
+#include <stdlib.h>
+
 TestBitVector*
 TestBitVector_new() {
     return (TestBitVector*)Class_Make_Obj(TESTBITVECTOR);
@@ -386,10 +387,9 @@ test_Clone(TestBatchRunner *runner) {
 }
 
 static int
-S_compare_u64s(void *context, const void *va, const void *vb) {
+S_compare_u64s(const void *va, const void *vb) {
     uint64_t a = *(uint64_t*)va;
     uint64_t b = *(uint64_t*)vb;
-    UNUSED_VAR(context);
     return a == b ? 0 : a < b ? -1 : 1;
 }
 
@@ -402,8 +402,7 @@ test_To_Array(TestBatchRunner *runner) {
     long       i;
 
     // Unique the random ints.
-    Sort_quicksort(source_ints, 20, sizeof(uint64_t),
-                   S_compare_u64s, NULL);
+    qsort(source_ints, 20, sizeof(uint64_t), S_compare_u64s);
     for (i = 0; i < 19; i++) {
         if (source_ints[i] != source_ints[i + 1]) {
             source_ints[num_unique] = source_ints[i];


Mime
View raw message