]> mj.ucw.cz Git - libucw.git/blobdiff - lib/sorter/s-twoway.h
Fix bucket estimator.
[libucw.git] / lib / sorter / s-twoway.h
index 16a6720b10d75526f272c5193d2a43402003b0d8..0e6d644260021d4171f86ca5a189f4269cb2e512 100644 (file)
@@ -20,11 +20,11 @@ static void P(twoway_merge)(struct sort_context *ctx UNUSED, struct sort_bucket
   int comp;
   uns run_count = 0;
 
-  fin1 = sbuck_open_read(ins[0]);
+  fin1 = sbuck_read(ins[0]);
   next1 = P(read_key)(fin1, kin1);
-  if (sbuck_can_read(ins[1]))
+  if (sbuck_have(ins[1]))
     {
-      fin2 = sbuck_open_read(ins[1]);
+      fin2 = sbuck_read(ins[1]);
       next2 = P(read_key)(fin2, kin2);
     }
   else
@@ -50,14 +50,17 @@ static void P(twoway_merge)(struct sort_context *ctx UNUSED, struct sort_bucket
          if (unlikely(!fout1))
            {
              if (!fout2)
-               fout1 = sbuck_open_write(outs[0]);
+               fout1 = sbuck_write(outs[0]);
              else if (outs[1])
-               fout1 = sbuck_open_write(outs[1]);
+               fout1 = sbuck_write(outs[1]);
              else
                fout1 = fout2;
            }
          run_count++;
        }
+#ifdef SORT_ASSERT_UNIQUE
+      ASSERT(comp != 0);
+#endif
       if (comp LESS 0)
        {
          P(copy_data)(kin1, fin1, fout1);
@@ -66,7 +69,7 @@ static void P(twoway_merge)(struct sort_context *ctx UNUSED, struct sort_bucket
          run1 = next1 && (P(compare)(kprev1, kin1) LESS 0);
          kout = kprev1;
        }
-#ifdef SORT_MERGE
+#ifdef SORT_UNIFY
       else if (comp == 0)
        {
          P(key) *mkeys[] = { kin1, kin2 };
@@ -80,10 +83,6 @@ static void P(twoway_merge)(struct sort_context *ctx UNUSED, struct sort_bucket
          run2 = next2 && (P(compare)(kprev2, kin2) LESS 0);
          kout = kprev2;
        }
-#endif
-#ifdef SORT_ASSERT_UNIQUE
-      else if (unlikely(comp == 0))
-       ASSERT(0);
 #endif
       else
        {
@@ -100,8 +99,6 @@ static void P(twoway_merge)(struct sort_context *ctx UNUSED, struct sort_bucket
        }
     }
 
-  sbuck_close_read(ins[0]);
-  sbuck_close_read(ins[1]);
   if (fout2 && fout2 != fout1)
     outs[1]->runs += run_count / 2;
   if (fout1)