X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=lib%2Fsorter%2Fs-twoway.h;h=ef23a2e9339806b51bc2622379e0b9c6417d24d2;hb=7bddf3297ee2592efb3ca02b822683371e64e340;hp=6bbdf28d1e9690dc06e6d4994fb7fee2377c3d65;hpb=5ff0a5b047624c8f215da9cd6c7182d609fcbd01;p=libucw.git diff --git a/lib/sorter/s-twoway.h b/lib/sorter/s-twoway.h index 6bbdf28d..ef23a2e9 100644 --- a/lib/sorter/s-twoway.h +++ b/lib/sorter/s-twoway.h @@ -7,10 +7,7 @@ * of the GNU Lesser General Public License. */ -/* FIXME: There is a plenty of room for further optimization */ -/* FIXME: Swap outputs if there already are some runs? */ - -static void P(twoway_merge)(struct sort_context *ctx, struct sort_bucket **ins, struct sort_bucket **outs) +static void P(twoway_merge)(struct sort_context *ctx UNUSED, struct sort_bucket **ins, struct sort_bucket **outs) { struct fastbuf *fin1, *fin2, *fout1, *fout2, *ftmp; P(key) kbuf1, kbuf2, kbuf3, kbuf4; @@ -20,11 +17,11 @@ static void P(twoway_merge)(struct sort_context *ctx, struct sort_bucket **ins, int comp; uns run_count = 0; - fin1 = sorter_open_read(ins[0]); + fin1 = sbuck_read(ins[0]); next1 = P(read_key)(fin1, kin1); - if (ins[1]) + if (sbuck_have(ins[1])) { - fin2 = sorter_open_read(ins[1]); + fin2 = sbuck_read(ins[1]); next2 = P(read_key)(fin2, kin2); } else @@ -50,14 +47,17 @@ static void P(twoway_merge)(struct sort_context *ctx, struct sort_bucket **ins, if (unlikely(!fout1)) { if (!fout2) - fout1 = sorter_open_write(outs[0]); + fout1 = sbuck_write(outs[0]); else if (outs[1]) - fout1 = sorter_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 +66,7 @@ static void P(twoway_merge)(struct sort_context *ctx, struct sort_bucket **ins, 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 +80,6 @@ static void P(twoway_merge)(struct sort_context *ctx, struct sort_bucket **ins, 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 +96,6 @@ static void P(twoway_merge)(struct sort_context *ctx, struct sort_bucket **ins, } } - sorter_close_read(ins[0]); - sorter_close_read(ins[1]); if (fout2 && fout2 != fout1) outs[1]->runs += run_count / 2; if (fout1)