]> thyrsus.com Git - comparator.git/commitdiff
Fix the reduction logic.
authorEric S. Raymond <esr@thyrsus.com>
Fri, 12 Sep 2003 09:52:25 +0000 (09:52 +0000)
committerEric S. Raymond <esr@thyrsus.com>
Fri, 12 Sep 2003 09:52:25 +0000 (09:52 +0000)
main.c
report.c
shred.h

diff --git a/main.c b/main.c
index a6063ce340b545ebd45e997fb050ccf10faca452..227a289fceb9fcd5e75eb75c72141e78f6c09dfb 100644 (file)
--- 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);
     }
 
index 1d3a21d2dbf2d4cbbeb4a280003e8026e5a71791..b4307a2747454e0e2f843d66593c3cadfe5c05b6 100644 (file)
--- 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 0ab16b6435d79fbf4d7f11f5adc470f8422ef734..98da0ba8fb1b9e5d0021655b509cd6aba8e80ece 100644 (file)
--- 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 *);