Browse Source

* rename some fields in simdb_search_t & simdb_match_t

master
Alex 'AdUser' Z 8 years ago
parent
commit
3572281ad5
  1. 20
      src/database.c
  2. 12
      src/simdb-tool.c
  3. 16
      src/simdb.h

20
src/database.c

@ -366,9 +366,9 @@ simdb_search(simdb_t *db, simdb_search_t *search, simdb_urec_t *sample) {
assert(db != NULL);
assert(search != NULL);
if (search->maxdiff_ratio < 0.0 && search->maxdiff_ratio > 1.0)
if (search->d_ratio < 0.0 && search->d_ratio > 1.0)
return SIMDB_ERR_USAGE;
if (search->maxdiff_bitmap < 0.0 && search->maxdiff_bitmap > 1.0)
if (search->d_bitmap < 0.0 && search->d_bitmap > 1.0)
return SIMDB_ERR_USAGE;
memset(&match, 0x0, sizeof(simdb_match_t));
@ -376,7 +376,7 @@ simdb_search(simdb_t *db, simdb_search_t *search, simdb_urec_t *sample) {
if (search->limit == 0)
search->limit = INT_MAX;
if (search->maxdiff_ratio > 0.0)
if (search->d_ratio > 0.0)
ratio_s = simdb_record_ratio(sample);
if ((matches = calloc(capacity, sizeof(simdb_match_t))) == NULL)
@ -395,22 +395,22 @@ simdb_search(simdb_t *db, simdb_search_t *search, simdb_urec_t *sample) {
if (!rec->used)
continue; /* record missing */
match.diff_ratio = 0.0;
match.diff_bitmap = 0.0;
match.d_ratio = 0.0;
match.d_bitmap = 0.0;
/* - compare ratio - cheap */
/* TODO: check caps */
if (ratio_s > 0.0 && (ratio_t = simdb_record_ratio(rec)) > 0.0) {
match.diff_ratio = ratio_s - ratio_t;
match.diff_ratio *= (ratio_s > ratio_t) ? 1.0 : -1.0;
if (match.diff_ratio > search->maxdiff_ratio)
match.d_ratio = ratio_s - ratio_t;
match.d_ratio *= (ratio_s > ratio_t) ? 1.0 : -1.0;
if (match.d_ratio > search->d_ratio)
continue;
} else {
/* either source or target ratio not set, can't compare, skip test */
}
/* - compare bitmap - more expensive */
match.diff_bitmap = simdb_bitmap_compare(rec->bitmap, sample->bitmap) / SIMDB_BITMAP_BITS;
if (match.diff_bitmap > search->maxdiff_bitmap)
match.d_bitmap = simdb_bitmap_compare(rec->bitmap, sample->bitmap) / SIMDB_BITMAP_BITS;
if (match.d_bitmap > search->d_bitmap)
continue;
/* whoa! a match found */
/* allocate more memory for results array if needed */

12
src/simdb-tool.c

@ -78,8 +78,8 @@ print_search_results(simdb_search_t *search) {
for (int i = 0; i < search->found; i++) {
printf("%d -- %.1f (bitmap), %.1f (ratio)\n",
search->matches[i].num,
search->matches[i].diff_bitmap * 100,
search->matches[i].diff_ratio * 100);
search->matches[i].d_bitmap * 100,
search->matches[i].d_ratio * 100);
}
}
@ -89,8 +89,8 @@ int search_similar_file(simdb_t *db, float maxdiff, char *path) {
memset(&search, 0x0, sizeof(simdb_search_t));
search.maxdiff_ratio = 0.2; /* 20% */
search.maxdiff_bitmap = maxdiff;
search.d_ratio = 0.2; /* 20% */
search.d_bitmap = maxdiff;
if ((ret = simdb_search_file(db, &search, path)) < 0) {
fprintf(stderr, "%s\n", simdb_error(ret));
@ -111,8 +111,8 @@ int search_similar_byid(simdb_t *db, float maxdiff, int num) {
memset(&search, 0x0, sizeof(simdb_search_t));
search.maxdiff_ratio = 0.2; /* 20% */
search.maxdiff_bitmap = maxdiff;
search.d_ratio = 0.2; /* 20% */
search.d_bitmap = maxdiff;
if ((ret = simdb_search_byid(db, &search, num)) < 0) {
fprintf(stderr, "%s\n", simdb_error(ret));

16
src/simdb.h

@ -56,20 +56,20 @@ typedef struct _simdb_t simdb_t;
* search matches
*/
typedef struct {
int num; /**< record id */
float diff_ratio; /**< difference of ratio */
float diff_bitmap; /**< difference of bitmap */
int num; /**< record id */
float d_ratio; /**< difference of ratio */
float d_bitmap; /**< difference of bitmap */
} simdb_match_t;
/**
* search parameters
* maxdiff_* fields should have value from 0.0 to 1.0 (0% - 100%)
* d_* fields should have value from 0.0 to 1.0 (0% - 100%)
*/
typedef struct {
float maxdiff_bitmap; /**< max difference of luma bitmaps */
float maxdiff_ratio; /**< max difference of ratios, default - 7% */
int limit; /**< max results */
int found; /**< count of found results */
float d_bitmap; /**< max difference of luma bitmaps, default - 7% */
float d_ratio; /**< max difference of ratios, default - 7% */
int limit; /**< max results */
int found; /**< count of found results */
simdb_match_t *matches;
} simdb_search_t;

Loading…
Cancel
Save