From cb962ee9edc95f73507d35f0714ec8aa68c5295c Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Sun, 9 Jan 2005 07:59:48 +0000 Subject: [PATCH] Sat Jan 8 23:58:34 2005 Ben Pfaff * sort.c: (compare_initial_runs) Needed additional level of dereferencing. (merge_once) Fix plenty of stupid mistakes. Sat Jan 8 23:55:27 2005 Ben Pfaff * casefile.c: (casefile_sleep) Need to flush_buffer() after calling casefile_to_disk() or we will lose the last block in the file if the casefile started out as disk-based. (casefile_get_reader) Initialize reader->destructive to 0. (cmd_debug_casefile) Add new test pattern. (test_casefile) Define new test pattern to make sure casefile_sleep() works properly. --- src/ChangeLog | 16 ++++++++++++++++ src/casefile.c | 13 ++++++++++--- src/sort.c | 27 ++++++++++++++------------- 3 files changed, 40 insertions(+), 16 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index b3548aa2..8576e20f 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,19 @@ +Sat Jan 8 23:58:34 2005 Ben Pfaff + + * sort.c: (compare_initial_runs) Needed additional level of + dereferencing. + (merge_once) Fix plenty of stupid mistakes. + +Sat Jan 8 23:55:27 2005 Ben Pfaff + + * casefile.c: (casefile_sleep) Need to flush_buffer() after + calling casefile_to_disk() or we will lose the last block in the + file if the casefile started out as disk-based. + (casefile_get_reader) Initialize reader->destructive to 0. + (cmd_debug_casefile) Add new test pattern. + (test_casefile) Define new test pattern to make sure + casefile_sleep() works properly. + Fri Jan 7 08:00:05 WST 2005 John Darrington * Makefile.am chart.[ch] histogram.[ch] piechart.c (Modified); diff --git a/src/casefile.c b/src/casefile.c index 76de45dc..eca07f83 100644 --- a/src/casefile.c +++ b/src/casefile.c @@ -224,6 +224,7 @@ casefile_sleep (const struct casefile *cf_) casefile_mode_reader (cf); casefile_to_disk (cf); + flush_buffer (cf); if (cf->fd != -1) { @@ -444,13 +445,14 @@ casefile_get_reader (const struct casefile *cf_) cf->mode = READ; reader = xmalloc (sizeof *reader); - reader->cf = cf; reader->next = cf->readers; if (cf->readers != NULL) reader->next->prev = reader; - reader->prev = NULL; cf->readers = reader; + reader->prev = NULL; + reader->cf = cf; reader->case_idx = 0; + reader->destructive = 0; reader->fd = -1; reader->buffer = NULL; reader->buffer_pos = 0; @@ -783,7 +785,7 @@ cmd_debug_casefile (void) if (token != '.') return lex_end_of_command (); - for (pattern = 0; pattern < 5; pattern++) + for (pattern = 0; pattern < 6; pattern++) { const size_t *size; @@ -811,13 +813,18 @@ test_casefile (int pattern, size_t value_cnt, size_t case_cnt) rng = gsl_rng_alloc (gsl_rng_mt19937); cf = casefile_create (value_cnt); + if (pattern == 5) + casefile_to_disk (cf); for (i = 0; i < case_cnt; i++) write_random_case (cf, i); + if (pattern == 5) + casefile_sleep (cf); r1 = casefile_get_reader (cf); r2 = casefile_get_reader (cf); switch (pattern) { case 0: + case 5: for (i = 0; i < case_cnt; i++) { read_and_verify_random_case (cf, r1, i); diff --git a/src/sort.c b/src/sort.c index 2aa800e0..2449509b 100644 --- a/src/sort.c +++ b/src/sort.c @@ -334,10 +334,10 @@ compare_case_dblptrs (const void *a_, const void *b_, void *criteria_) static int compare_initial_runs (const void *a_, const void *b_, void *aux UNUSED) { - const struct casefile *a = a_; - const struct casefile *b = b_; - unsigned long a_case_cnt = casefile_get_case_cnt (a); - unsigned long b_case_cnt = casefile_get_case_cnt (b); + struct casefile *const *a = a_; + struct casefile *const *b = b_; + unsigned long a_case_cnt = casefile_get_case_cnt (*a); + unsigned long b_case_cnt = casefile_get_case_cnt (*b); return a_case_cnt > b_case_cnt ? -1 : a_case_cnt < b_case_cnt; } @@ -753,7 +753,7 @@ merge (struct external_sort *xsrt) compare_initial_runs, NULL); dummy_run_cnt = mod (1 - (int) xsrt->run_cnt, max_order - 1); - assert( max_order > 0 ); + assert (max_order > 0); assert (max_order <= 2 || (xsrt->run_cnt + dummy_run_cnt) % (max_order - 1) == 1); while (xsrt->run_cnt > 1) @@ -832,7 +832,7 @@ merge_once (struct merge_state *mrg, for (i = 0; i < run_cnt; i++) { - input_readers[i] = casefile_get_reader (input_runs[i]); + input_readers[i] = casefile_get_destructive_reader (input_runs[i]); if (!casereader_read_xfer (input_readers[i], &input_cases[i])) { run_cnt--; @@ -856,17 +856,18 @@ merge_once (struct merge_state *mrg, min_idx = i; /* Write minimum to output file. */ - casefile_append_xfer (output_casefile, &input_cases[i]); + casefile_append_xfer (output_casefile, &input_cases[min_idx]); - if (!casereader_read_xfer (input_readers[i], &input_cases[i])) + if (!casereader_read_xfer (input_readers[min_idx], + &input_cases[min_idx])) { - casereader_destroy (input_readers[i]); - casefile_destroy (input_runs[i]); + casereader_destroy (input_readers[min_idx]); + casefile_destroy (input_runs[min_idx]); run_cnt--; - input_runs[i] = input_runs[run_cnt--]; - input_readers[i] = input_readers[run_cnt--]; - input_cases[i] = input_cases[run_cnt--]; + input_runs[min_idx] = input_runs[run_cnt]; + input_readers[min_idx] = input_readers[run_cnt]; + input_cases[min_idx] = input_cases[run_cnt]; } } -- 2.30.2