]> mj.ucw.cz Git - libucw.git/blobdiff - lib/sorter/sort-test.c
Unified top-level Makefile with main-line.
[libucw.git] / lib / sorter / sort-test.c
index 9a822d141847037182f8a40cf3553bd8a16d8904..3eb2147e65ba94791083b955acff2acf11b81cd8 100644 (file)
@@ -36,7 +36,7 @@ static void
 stop(void)
 {
   sync();
 stop(void)
 {
   sync();
-  log(L_INFO, "Test took %.3fs", get_timer(&timer) / 1000.);
+  msg(L_INFO, "Test took %.3fs", get_timer(&timer) / 1000.);
 }
 
 /*** Simple 4-byte integer keys ***/
 }
 
 /*** Simple 4-byte integer keys ***/
@@ -60,7 +60,7 @@ test_int(int mode, u64 size)
 {
   uns N = size ? nextprime(MIN(size/4, 0xffff0000)) : 0;
   uns K = N/4*3;
 {
   uns N = size ? nextprime(MIN(size/4, 0xffff0000)) : 0;
   uns K = N/4*3;
-  log(L_INFO, ">>> Integers (%s, N=%u)", ((char *[]) { "increasing", "decreasing", "random" })[mode], N);
+  msg(L_INFO, ">>> Integers (%s, N=%u)", ((char *[]) { "increasing", "decreasing", "random" })[mode], N);
 
   struct fastbuf *f = bopen_tmp(65536);
   for (uns i=0; i<N; i++)
 
   struct fastbuf *f = bopen_tmp(65536);
   for (uns i=0; i<N; i++)
@@ -113,7 +113,7 @@ test_counted(int mode, u64 size)
     mult++;
   uns N = items ? nextprime(items/(2*mult)) : 0;
   uns K = N/4*3;
     mult++;
   uns N = items ? nextprime(items/(2*mult)) : 0;
   uns K = N/4*3;
-  log(L_INFO, ">>> Counted integers (%s, N=%u, mult=%u)", ((char *[]) { "increasing", "decreasing", "random" })[mode], N, mult);
+  msg(L_INFO, ">>> Counted integers (%s, N=%u, mult=%u)", ((char *[]) { "increasing", "decreasing", "random" })[mode], N, mult);
 
   struct fastbuf *f = bopen_tmp(65536);
   for (uns m=0; m<mult; m++)
 
   struct fastbuf *f = bopen_tmp(65536);
   for (uns m=0; m<mult; m++)
@@ -137,7 +137,7 @@ test_counted(int mode, u64 size)
        die("Discrepancy: %u instead of %u", j, i);
       uns k = bgetl(f);
       if (k != 2*mult)
        die("Discrepancy: %u instead of %u", j, i);
       uns k = bgetl(f);
       if (k != 2*mult)
-       die("Discrepancy: %u has count %u instead of %u", j, k, mult);
+       die("Discrepancy: %u has count %u instead of %u", j, k, 2*mult);
     }
   bclose(f);
 }
     }
   bclose(f);
 }
@@ -205,7 +205,7 @@ static void
 test_hashes(int mode, u64 size)
 {
   uns N = MIN(size / sizeof(struct key3), 0xffffffff);
 test_hashes(int mode, u64 size)
 {
   uns N = MIN(size / sizeof(struct key3), 0xffffffff);
-  log(L_INFO, ">>> Hashes (%s, N=%u)", ((char *[]) { "increasing", "decreasing", "random" })[mode], N);
+  msg(L_INFO, ">>> Hashes (%s, N=%u)", ((char *[]) { "increasing", "decreasing", "random" })[mode], N);
   struct key3 k, lastk;
 
   struct fastbuf *f = bopen_tmp(65536);
   struct key3 k, lastk;
 
   struct fastbuf *f = bopen_tmp(65536);
@@ -323,7 +323,7 @@ test_strings(uns mode, u64 size)
 {
   uns avg_item_size = KEY4_MAX/2 + 4 + (mode ? 128 : 0);
   uns N = MIN(size / avg_item_size, 0xffffffff);
 {
   uns avg_item_size = KEY4_MAX/2 + 4 + (mode ? 128 : 0);
   uns N = MIN(size / avg_item_size, 0xffffffff);
-  log(L_INFO, ">>> Strings %s(N=%u)", (mode ? "with data " : ""), N);
+  msg(L_INFO, ">>> Strings %s(N=%u)", (mode ? "with data " : ""), N);
   srand(1);
 
   struct key4 k, lastk;
   srand(1);
 
   struct key4 k, lastk;
@@ -514,7 +514,7 @@ test_graph(uns mode, u64 size)
   uns N = 3;
   while ((u64)N*(N+2)*4 < size)
     N = nextprime(N);
   uns N = 3;
   while ((u64)N*(N+2)*4 < size)
     N = nextprime(N);
-  log(L_INFO, ">>> Graph%s (N=%u)", (mode ? "" : " with custom presorting"), N);
+  msg(L_INFO, ">>> Graph%s (N=%u)", (mode ? "" : " with custom presorting"), N);
   s5_N = N;
   s5_K = N/4*3;
   s5_L = N/3*2;
   s5_N = N;
   s5_K = N/4*3;
   s5_L = N/3*2;
@@ -560,6 +560,47 @@ test_graph(uns mode, u64 size)
   bclose(f);
 }
 
   bclose(f);
 }
 
+/*** Simple 8-byte integer keys ***/
+
+struct key6 {
+  u64 x;
+};
+
+#define SORT_KEY_REGULAR struct key6
+#define SORT_PREFIX(x) s6_##x
+#define SORT_INPUT_FB
+#define SORT_OUTPUT_FB
+#define SORT_UNIQUE
+#define SORT_INT64(k) (k).x
+
+#include "lib/sorter/sorter.h"
+
+static void
+test_int64(int mode, u64 size)
+{
+  u64 N = size ? nextprime(MIN(size/8, 0xffff0000)) : 0;
+  u64 K = N/4*3;
+  msg(L_INFO, ">>> 64-bit integers (%s, N=%llu)", ((char *[]) { "increasing", "decreasing", "random" })[mode], (long long)N);
+
+  struct fastbuf *f = bopen_tmp(65536);
+  for (u64 i=0; i<N; i++)
+    bputq(f, 777777*((mode==0) ? i : (mode==1) ? N-1-i : ((u64)i * K + 17) % N));
+  brewind(f);
+
+  start();
+  f = s6_sort(f, NULL, 777777*(N-1));
+  stop();
+
+  SORT_XTRACE(2, "Verifying");
+  for (u64 i=0; i<N; i++)
+    {
+      u64 j = bgetq(f);
+      if (777777*i != j)
+       die("Discrepancy: %llu instead of %llu", (long long)j, 777777*(long long)i);
+    }
+  bclose(f);
+}
+
 /*** Main ***/
 
 static void
 /*** Main ***/
 
 static void
@@ -593,7 +634,13 @@ run_test(uns i, u64 size)
       test_graph(0, size); break;
     case 12:
       test_graph(1, size); break;
       test_graph(0, size); break;
     case 12:
       test_graph(1, size); break;
-#define TMAX 13
+    case 13:
+      test_int64(0, size); break;
+    case 14:
+      test_int64(1, size); break;
+    case 15:
+      test_int64(2, size); break;
+#define TMAX 16
     }
 }
 
     }
 }