From a663947513f62589995c90639b17ea3c45e728f6 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Fri, 12 Sep 2003 09:52:25 +0000 Subject: [PATCH] Fix the reduction logic. --- main.c | 23 ++++------------------- report.c | 8 ++++++++ shred.h | 2 ++ 3 files changed, 14 insertions(+), 19 deletions(-) diff --git a/main.c b/main.c index a6063ce..227a289 100644 --- a/main.c +++ b/main.c @@ -304,23 +304,18 @@ static void init_scf(char *file, struct scf_t *scf, const int readfile) } } -static void dump_array(struct sorthash_t *obarray, - int hashcount, - linenum_t (*fn)(linenum_t)) +void dump_array(const char *legend, + struct sorthash_t *obarray, int hashcount) /* dump the contents of a sort_hash array */ { struct sorthash_t *np; + fputs(legend, stderr); for (np = obarray; np < obarray + hashcount; np++) { struct hash_t scratch; scratch = np->hash; - if (fn) - { - scratch.start = fn(np->hash.start); - scratch.end = fn(np->hash.end); - } printf("%d: %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x %s:%d:%d\n", np-obarray, scratch.hash[0], @@ -561,10 +556,7 @@ main(int argc, char *argv[]) if (!compile_only) { if (debug) - { - printf("Consolidated hash list:\n"); - dump_array(sort_buffer, sort_count, NULL); - } + dump_array("Consolidated hash list:\n", sort_buffer, sort_count); /* now we're ready to emit the report */ puts("#SCF-B 1.1"); @@ -580,13 +572,6 @@ main(int argc, char *argv[]) report_time("Hash merge done, %d shreds", sort_count); sort_hashes(sort_buffer, sort_count); report_time("Sort done"); - - if (debug) - { - puts("Chunk list before reduction."); - dump_array(sort_buffer, sort_count, NULL); - } - emit_report(sort_buffer, sort_count); } diff --git a/report.c b/report.c index 1d3a21d..b4307a2 100644 --- a/report.c +++ b/report.c @@ -169,6 +169,9 @@ struct match_t *reduce_matches(struct sorthash_t *obarray, int *hashcountp) unsigned int nonuniques, nreduced, progress, hashcount = *hashcountp; struct sorthash_t *mp, *np; + if (debug) + dump_array("Chunk list before reduction.\n",obarray, hashcount); + /* * To reduce the size of the in-core working set, we do a a * pre-elimination of duplicates based on hash key alone, in @@ -204,6 +207,9 @@ struct match_t *reduce_matches(struct sorthash_t *obarray, int *hashcountp) obarray = (struct sorthash_t *)realloc(obarray, sizeof(struct sorthash_t)* hashcount); + if (debug) + dump_array("Chunk list after reduction.\n",obarray, hashcount); + /* build list of hashes with more than one range associated */ nonuniques = progress = 0; fprintf(stderr, "%% Extracting duplicates... "); @@ -286,6 +292,8 @@ void emit_report(struct sorthash_t *obarray, int hashcount) int mergecount; hitlist = reduce_matches(obarray, &hashcount); + if (debug) + dump_array("After removing uniques.\n", obarray, hashcount); report_time("%d range groups after removing unique hashes", hashcount); mergecount = collapse_ranges(hitlist, hashcount); report_time("%d range groups after merging", mergecount); diff --git a/shred.h b/shred.h index 0ab16b6..98da0ba 100644 --- a/shred.h +++ b/shred.h @@ -36,6 +36,8 @@ extern int shredsize; /* main.c functions */ extern void report_time(char *legend, ...); extern void corehook(struct hash_t hash, const char *file); +extern void dump_array(const char *legend, + struct sorthash_t *obarray, int hashcount); /* shredtree.c functions */ extern char **sorted_file_list(const char *, int *); -- 2.43.0