+Sat Jan 8 23:58:34 2005 Ben Pfaff <blp@gnu.org>
+
+ * 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 <blp@gnu.org>
+
+ * 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 <john@darrington.wattle.id.au>
* Makefile.am chart.[ch] histogram.[ch] piechart.c (Modified);
casefile_mode_reader (cf);
casefile_to_disk (cf);
+ flush_buffer (cf);
if (cf->fd != -1)
{
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;
if (token != '.')
return lex_end_of_command ();
- for (pattern = 0; pattern < 5; pattern++)
+ for (pattern = 0; pattern < 6; pattern++)
{
const size_t *size;
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);
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;
}
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)
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--;
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];
}
}