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; return -1;
} }
if (!sample->data[0]) { if (search->limit == 0)
db->errstr = "Source sample not exists"; search->limit = -1; /* unsigned -> max */
return -1;
}
if (search->tresh_ratio > 0.0) if (search->maxdiff_ratio > 0.0)
ratio_s = ratio_from_rec_data(sample->data); ratio_s = ratio_from_rec_data(sample->data);
*matches = NULL; *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) { if (ratio_s > 0.0 && (ratio_t = ratio_from_rec_data(p)) > 0.0) {
diff = ratio_s - ratio_t; diff = ratio_s - ratio_t;
diff *= (ratio_s > ratio_t) ? 1.0 : -1.0; diff *= (ratio_s > ratio_t) ? 1.0 : -1.0;
if (diff > search->tresh_ratio) if (diff > search->maxdiff_ratio)
continue; continue;
} else { } 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 */ /* - compare bitmap - more expensive */
diff = (float) bitmap_compare(p + REC_OFF_BM, sample->data + REC_OFF_BM); diff = (float) bitmap_compare(p + REC_OFF_BM, sample->data + REC_OFF_BM);
diff /= BITMAP_BITS; diff /= BITMAP_BITS;
if (diff > search->tresh_bitmap) if (diff > search->maxdiff_bitmap)
continue; continue;
/* allocate more memory, if needed */ /* allocate more memory, if needed */
@ -323,11 +321,11 @@ imdb_search(imdb_t * const db,
(*matches)[found].num = blk.start + i; (*matches)[found].num = blk.start + i;
(*matches)[found].diff = diff; (*matches)[found].diff = diff;
found++; found++;
if (search->limit && found >= search->limit) if (found >= search->limit)
break; break;
} }
FREE(blk.data); FREE(blk.data);
if (search->limit && found >= search->limit) if (found >= search->limit)
break; break;
blk.start += blk_size; blk.start += blk_size;
} }

4
src/database.h

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

19
src/util.c

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

Loading…
Cancel
Save