]> mj.ucw.cz Git - libucw.git/blobdiff - lib/sorter/sort-test.c
Merge with git+ssh://git.ucw.cz/projects/sherlock/GIT/sherlock.git
[libucw.git] / lib / sorter / sort-test.c
index 5fcbbaf74e65c71de9a9d48cdd75e5c0de04fffe..e7d5873020d2bb527e2ac0efb312bbe5ff0b8e4f 100644 (file)
 #include <fcntl.h>
 #include <unistd.h>
 
 #include <fcntl.h>
 #include <unistd.h>
 
+/*** A hack for overriding radix-sorter configuration ***/
+
+#ifdef FORCE_RADIX_BITS
+#undef CONFIG_UCW_RADIX_SORTER_BITS
+#define CONFIG_UCW_RADIX_SORTER_BITS FORCE_RADIX_BITS
+#endif
+
 /*** Time measurement ***/
 
 static timestamp_t timer;
 /*** Time measurement ***/
 
 static timestamp_t timer;
@@ -153,9 +160,10 @@ struct key3 {
 
 static inline int s3_compare(struct key3 *x, struct key3 *y)
 {
 
 static inline int s3_compare(struct key3 *x, struct key3 *y)
 {
-  /* FIXME: Maybe unroll manually? */
-  for (uns i=0; i<4; i++)
-    COMPARE(x->hash[i], y->hash[i]);
+  COMPARE(x->hash[0], y->hash[0]);
+  COMPARE(x->hash[1], y->hash[1]);
+  COMPARE(x->hash[2], y->hash[2]);
+  COMPARE(x->hash[3], y->hash[3]);
   return 0;
 }
 
   return 0;
 }
 
@@ -389,7 +397,7 @@ static int s5_gen(struct s5_pair *p)
 {
   if (s5_j >= s5_N)
     {
 {
   if (s5_j >= s5_N)
     {
-      if (s5_i >= s5_N-1)
+      if (!s5_N || s5_i >= s5_N-1)
        return 0;
       s5_j = 0;
       s5_i++;
        return 0;
       s5_j = 0;
       s5_i++;
@@ -418,7 +426,7 @@ static void s5_write_merged(struct fastbuf *f, struct key5 **keys, void **data,
   s5m_sort(m, a);
   keys[0]->cnt = m;
   bwrite(f, keys[0], sizeof(struct key5));
   s5m_sort(m, a);
   keys[0]->cnt = m;
   bwrite(f, keys[0], sizeof(struct key5));
-  bwrite(f, a, 4*m);                   /* FIXME: Might overflow here */
+  bwrite(f, a, 4*m);
 }
 
 static void s5_copy_merged(struct key5 **keys, struct fastbuf **data, uns n, struct fastbuf *dest)
 }
 
 static void s5_copy_merged(struct key5 **keys, struct fastbuf **data, uns n, struct fastbuf *dest)
@@ -453,13 +461,10 @@ static inline int s5p_lt(struct s5_pair x, struct s5_pair y)
   return 0;
 }
 
   return 0;
 }
 
-/* FIXME: Use smarter internal sorter when it's available */
 #define ASORT_PREFIX(x) s5p_##x
 #define ASORT_KEY_TYPE struct s5_pair
 #define ASORT_PREFIX(x) s5p_##x
 #define ASORT_KEY_TYPE struct s5_pair
-#define ASORT_ELT(i) ary[i]
 #define ASORT_LT(x,y) s5p_lt(x,y)
 #define ASORT_LT(x,y) s5p_lt(x,y)
-#define ASORT_EXTRA_ARGS , struct s5_pair *ary
-#include "lib/arraysort.h"
+#include "lib/sorter/array.h"
 
 static int s5_presort(struct fastbuf *dest, void *buf, size_t bufsize)
 {
 
 static int s5_presort(struct fastbuf *dest, void *buf, size_t bufsize)
 {
@@ -470,7 +475,7 @@ static int s5_presort(struct fastbuf *dest, void *buf, size_t bufsize)
     n++;
   if (!n)
     return 0;
     n++;
   if (!n)
     return 0;
-  s5p_sort(n, a);
+  s5p_sort(a, n);
   uns i = 0;
   while (i < n)
     {
   uns i = 0;
   while (i < n)
     {
@@ -515,6 +520,8 @@ 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);
+  if (!size)
+    N = 0;
   msg(L_INFO, ">>> Graph%s (N=%u)", (mode ? "" : " with custom presorting"), N);
   s5_N = N;
   s5_K = N/4*3;
   msg(L_INFO, ">>> Graph%s (N=%u)", (mode ? "" : " with custom presorting"), N);
   s5_N = N;
   s5_K = N/4*3;
@@ -665,9 +672,20 @@ main(int argc, char **argv)
          goto usage;
        break;
       case 't':
          goto usage;
        break;
       case 't':
-       t = atol(optarg);
-       if (t >= TMAX)
-         goto usage;
+         {
+           char *w[32];
+           int f = sepsplit(optarg, ',', w, ARRAY_SIZE(w));
+           if (f < 0)
+             goto usage;
+           t = 0;
+           for (int i=0; i<f; i++)
+             {
+               int j = atol(w[i]);
+               if (j >= TMAX)
+                 goto usage;
+               t |= 1 << j;
+             }
+         }
        break;
       case 'v':
        sorter_trace++;
        break;
       case 'v':
        sorter_trace++;
@@ -680,10 +698,8 @@ main(int argc, char **argv)
   if (optind != argc)
     goto usage;
 
   if (optind != argc)
     goto usage;
 
-  if (t != ~0U)
-    run_test(t, size);
-  else
-    for (uns i=0; i<TMAX; i++)
+  for (uns i=0; i<TMAX; i++)
+    if (t & (1 << i))
       run_test(i, size);
 
   return 0;
       run_test(i, size);
 
   return 0;