Browse Source

* imdb_search() : update

master
Alex 'AdUser' Z 10 years ago
parent
commit
6871af5d0d
  1. 18
      src/database.c
  2. 4
      src/database.h
  3. 19
      src/util.c

18
src/database.c

@ -277,12 +277,10 @@ imdb_search(imdb_t * const db,
return -1;
}
if (!sample->data[0]) {
db->errstr = "Source sample not exists";
return -1;
}
if (search->limit == 0)
search->limit = -1; /* unsigned -> max */
if (search->tresh_ratio > 0.0)
if (search->maxdiff_ratio > 0.0)
ratio_s = ratio_from_rec_data(sample->data);
*matches = NULL;
@ -296,16 +294,16 @@ imdb_search(imdb_t * const db,
if (ratio_s > 0.0 && (ratio_t = ratio_from_rec_data(p)) > 0.0) {
diff = ratio_s - ratio_t;
diff *= (ratio_s > ratio_t) ? 1.0 : -1.0;
if (diff > search->tresh_ratio)
if (diff > search->maxdiff_ratio)
continue;
} else {
/* either ratio not set, can't compare, skipping test */
/* either source or target ratio not set, can't compare, skip test */
}
/* - compare bitmap - more expensive */
diff = (float) bitmap_compare(p + REC_OFF_BM, sample->data + REC_OFF_BM);
diff /= BITMAP_BITS;
if (diff > search->tresh_bitmap)
if (diff > search->maxdiff_bitmap)
continue;
/* allocate more memory, if needed */
@ -323,11 +321,11 @@ imdb_search(imdb_t * const db,
(*matches)[found].num = blk.start + i;
(*matches)[found].diff = diff;
found++;
if (search->limit && found >= search->limit)
if (found >= search->limit)
break;
}
FREE(blk.data);
if (search->limit && found >= search->limit)
if (found >= search->limit)
break;
blk.start += blk_size;
}

4
src/database.h

@ -65,8 +65,8 @@ typedef struct {
typedef struct {
uint64_t limit;
float tresh_bitmap;
float tresh_ratio;
float maxdiff_bitmap;
float maxdiff_ratio;
} imdb_search_t;
typedef struct {

19
src/util.c

@ -38,7 +38,7 @@ void usage(int exitcode) {
exit(exitcode);
}
int search_similar(imdb_t *db, uint64_t number, float tresh)
int search_similar(imdb_t *db, uint64_t number, float maxdiff)
{
int ret = 0, i = 0;
imdb_rec_t sample;
@ -47,23 +47,22 @@ int search_similar(imdb_t *db, uint64_t number, float tresh)
memset(&sample, 0x0, sizeof(imdb_rec_t));
memset(&search, 0x0, sizeof(imdb_search_t));
search.tresh_ratio = tresh;
search.tresh_bitmap = tresh;
search.maxdiff_ratio = 0.2; /* 20% */
search.maxdiff_bitmap = maxdiff;
sample.num = number;
ret = imdb_search(db, &sample, &search, &matches);
if (ret == -1) {
if ((ret = imdb_search(db, &sample, &search, &matches)) < 0) {
printf("%s\n", db->errstr);
exit(EXIT_FAILURE);
}
if (ret == 0)
return 0;
if (ret > 0) {
for (i = 0; i < ret; i++)
printf("%llu -- %.2f\n", matches[i].num, matches[i].diff * 100);
for (i = 0; i < ret; i++) {
printf("%llu -- %.2f\n", matches[i].num, matches[i].diff * 100);
FREE(matches);
}
FREE(matches);
return 0;
}

Loading…
Cancel
Save