/* collapse together overlapping ranges in the hit list */
{
struct match_t *sp, *tp;
- int removed = 0;
+ int spancount, removed = 0;
/*
* For two matches to be eligible for merger, all their filenames must
#endif /* DEBUG */
/* time to merge overlapping shreds */
- for (sp = reduced; sp < reduced + nonuniques; sp++)
+ spancount = 0;
+ for (sp = reduced; sp < reduced + nonuniques; sp++, spancount--)
{
- for (tp = sp + 1; !compare_files(sp, tp) && tp < reduced + nonuniques; tp++)
- {
+ int remaining;
+
+ if (spancount <= 0)
+ {
+ spancount = 0;
+ for (tp = sp + 1;
+ !compare_files(sp, tp) && tp < reduced + nonuniques;
+ tp++)
+ spancount++;
+ }
+
+ for (tp = sp + 1, remaining = spancount; remaining--; tp++)
+ {
#ifdef DEBUG
- printf("Trying merge of %d into %d\n", tp-reduced, sp-reduced);
+ printf("Trying merge of %d into %d\n", tp-reduced, sp-reduced);
#endif /* DEBUG */
- /* neither must have been deleted */
- if (!sp->nmatches || !tp->nmatches)
- {
+ /* neither must have been deleted */
+ if (!sp->nmatches || !tp->nmatches)
+ {
#ifdef DEBUG
- printf("Null match pointer: %d=%p, %d=%p\n",
- sp-reduced, sp->matches, tp-reduced, tp->matches);
+ printf("Null match pointer: %d=%p, %d=%p\n",
+ sp-reduced, sp->matches, tp-reduced, tp->matches);
#endif /* DEBUG */
- continue;
- }
+ continue;
+ }
- /* attempt the merge */
- if (merge_ranges(tp->matches, sp->matches, sp->nmatches))
- {
+ /* attempt the merge */
+ if (merge_ranges(tp->matches, sp->matches, sp->nmatches))
+ {
#ifdef DEBUG
- struct sorthash_t *rp;
+ struct sorthash_t *rp;
- printf("*** Merged %d into %d\n", tp-reduced, sp-reduced);
- for (rp=sp->matches; rp < sp->matches+sp->nmatches; rp++)
- printf("%s:%d:%d\n",rp->file->name,rp->hash.start,rp->hash.end);
+ printf("*** Merged %d into %d\n", tp-reduced, sp-reduced);
+ for (rp=sp->matches; rp < sp->matches+sp->nmatches; rp++)
+ printf("%s:%d:%d\n",rp->file->name,rp->hash.start,rp->hash.end);
#endif /* DEBUG */
- removed++;
- sp->nmatches = 0;
- }
- }
- }
+ removed++;
+ sp->nmatches = 0;
+ }
+ }
+ }
#ifdef DEBUG
- for (sp = reduced; sp < reduced + nonuniques; sp++)
- {
- struct sorthash_t *rp;
+ for (sp = reduced; sp < reduced + nonuniques; sp++)
+ {
+ struct sorthash_t *rp;
- printf("Clique beginning at %d (%d):\n", sp - reduced, sp->nmatches);
- for (rp = sp->matches; rp < sp->matches + sp->nmatches; rp++)
- printf("%s:%d:%d\n", rp->file->name, rp->hash.start, rp->hash.end);
- }
+ printf("Clique beginning at %d (%d):\n", sp - reduced, sp->nmatches);
+ for (rp = sp->matches; rp < sp->matches + sp->nmatches; rp++)
+ printf("%s:%d:%d\n", rp->file->name, rp->hash.start, rp->hash.end);
+ }
#endif /* DEBUG */
- return(nonuniques - removed);
+ return(nonuniques - removed);
}
struct match_t *reduce_matches(struct sorthash_t *obarray, int *hashcountp)