|
|
@ -97,7 +97,7 @@ int search_similar(simdb_t *db, int num, float maxdiff) { |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int db_usage_map(simdb_t *db, unsigned short int cols) { |
|
|
|
int db_usage_map(simdb_t *db, int cols) { |
|
|
|
char *map = NULL; |
|
|
|
char *map = NULL; |
|
|
|
char *m = NULL; |
|
|
|
char *m = NULL; |
|
|
|
char row[256]; |
|
|
|
char row[256]; |
|
|
@ -169,7 +169,7 @@ int rec_bitmap(simdb_t *db, int num) { |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int rec_diff(simdb_t *db, int a, int b, unsigned short int showmap) { |
|
|
|
int rec_diff(simdb_t *db, int a, int b, bool show_map) { |
|
|
|
char *map1 = NULL, *map2 = NULL, *dmap = NULL; |
|
|
|
char *map1 = NULL, *map2 = NULL, *dmap = NULL; |
|
|
|
size_t size = 0, diff = 0; |
|
|
|
size_t size = 0, diff = 0; |
|
|
|
int ret; |
|
|
|
int ret; |
|
|
@ -206,7 +206,7 @@ int rec_diff(simdb_t *db, int a, int b, unsigned short int showmap) { |
|
|
|
*dm = *m1 ^ *m2; |
|
|
|
*dm = *m1 ^ *m2; |
|
|
|
diff += *dm ? 0 : 1; |
|
|
|
diff += *dm ? 0 : 1; |
|
|
|
} |
|
|
|
} |
|
|
|
if (showmap) { |
|
|
|
if (show_map) { |
|
|
|
bitmap_print(dmap, size); |
|
|
|
bitmap_print(dmap, size); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
printf("%.2f%%\n", ((float) diff / size) * 100); |
|
|
|
printf("%.2f%%\n", ((float) diff / size) * 100); |
|
|
@ -222,16 +222,12 @@ int rec_diff(simdb_t *db, int a, int b, unsigned short int showmap) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char **argv) { |
|
|
|
int main(int argc, char **argv) { |
|
|
|
enum { undef, add, del, init, search, bitmap, usage_map, usage_slice, diff } mode = undef; |
|
|
|
|
|
|
|
const char *db_path = NULL; |
|
|
|
|
|
|
|
float maxdiff = 0.10; |
|
|
|
|
|
|
|
unsigned short int cols = 64, map = 0, ret = 0; |
|
|
|
|
|
|
|
char *sample = NULL; |
|
|
|
|
|
|
|
simdb_t *db = NULL; |
|
|
|
simdb_t *db = NULL; |
|
|
|
int a = 0, b = 0; |
|
|
|
enum { undef = 0, add, del, init, search, bitmap, usage_map, usage_slice, diff } mode = undef; |
|
|
|
char *c = NULL; |
|
|
|
char *db_path = NULL, *sample = NULL, *c = NULL, opt = '\0'; |
|
|
|
int err; |
|
|
|
int cols = 64, a = 0, b = 0, ret = 0, db_flags = 0; |
|
|
|
char opt = '\0'; |
|
|
|
bool show_map = false, need_write = false; |
|
|
|
|
|
|
|
float maxdiff = 0.10; |
|
|
|
|
|
|
|
|
|
|
|
if (argc < 3) |
|
|
|
if (argc < 3) |
|
|
|
usage(EXIT_FAILURE); |
|
|
|
usage(EXIT_FAILURE); |
|
|
@ -251,6 +247,7 @@ int main(int argc, char **argv) { |
|
|
|
break; |
|
|
|
break; |
|
|
|
case 'A' : |
|
|
|
case 'A' : |
|
|
|
mode = add; |
|
|
|
mode = add; |
|
|
|
|
|
|
|
need_write = true; |
|
|
|
if ((c = strchr(optarg, ',')) == NULL) |
|
|
|
if ((c = strchr(optarg, ',')) == NULL) |
|
|
|
usage(EXIT_FAILURE); |
|
|
|
usage(EXIT_FAILURE); |
|
|
|
a = atoll(optarg); |
|
|
|
a = atoll(optarg); |
|
|
@ -262,13 +259,14 @@ int main(int argc, char **argv) { |
|
|
|
break; |
|
|
|
break; |
|
|
|
case 'D' : |
|
|
|
case 'D' : |
|
|
|
mode = del; |
|
|
|
mode = del; |
|
|
|
|
|
|
|
need_write = true; |
|
|
|
a = atoll(optarg); |
|
|
|
a = atoll(optarg); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case 'I' : |
|
|
|
case 'I' : |
|
|
|
mode = init; |
|
|
|
mode = init; |
|
|
|
break; |
|
|
|
break; |
|
|
|
case 'F' : |
|
|
|
case 'F' : |
|
|
|
map = 1; |
|
|
|
show_map = true; |
|
|
|
case 'C' : |
|
|
|
case 'C' : |
|
|
|
mode = diff; |
|
|
|
mode = diff; |
|
|
|
if ((c = strchr(optarg, ',')) == NULL) |
|
|
|
if ((c = strchr(optarg, ',')) == NULL) |
|
|
@ -310,8 +308,12 @@ int main(int argc, char **argv) { |
|
|
|
exit(EXIT_FAILURE); |
|
|
|
exit(EXIT_FAILURE); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if ((db = simdb_open(db_path, 0, &err)) == NULL) { |
|
|
|
|
|
|
|
fprintf(stderr, "database open: %d\n", err); |
|
|
|
if (need_write) |
|
|
|
|
|
|
|
db_flags = SIMDB_FLAG_WRITE|SIMDB_FLAG_LOCK; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ((db = simdb_open(db_path, db_flags, &ret)) == NULL) { |
|
|
|
|
|
|
|
fprintf(stderr, "database open: %s\n", simdb_error(ret)); |
|
|
|
exit(EXIT_FAILURE); |
|
|
|
exit(EXIT_FAILURE); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -319,16 +321,16 @@ int main(int argc, char **argv) { |
|
|
|
case add : |
|
|
|
case add : |
|
|
|
if (a == 0 || sample == NULL) |
|
|
|
if (a == 0 || sample == NULL) |
|
|
|
usage(EXIT_FAILURE); |
|
|
|
usage(EXIT_FAILURE); |
|
|
|
if ((err = simdb_record_add(db, a, sample, 0)) < 0) { |
|
|
|
if ((ret = simdb_record_add(db, a, sample, 0)) < 0) { |
|
|
|
fprintf(stderr, "%s\n", simdb_error(err)); |
|
|
|
fprintf(stderr, "%s\n", simdb_error(ret)); |
|
|
|
exit(EXIT_FAILURE); |
|
|
|
exit(EXIT_FAILURE); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
fprintf(stderr, "added as record #%d", err); |
|
|
|
fprintf(stderr, "added as record #%d", ret); |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
case del : |
|
|
|
case del : |
|
|
|
if ((err = simdb_record_del(db, a)) < 0) { |
|
|
|
if ((ret = simdb_record_del(db, a)) < 0) { |
|
|
|
fprintf(stderr, "%s\n", simdb_error(err)); |
|
|
|
fprintf(stderr, "%s\n", simdb_error(ret)); |
|
|
|
exit(EXIT_FAILURE); |
|
|
|
exit(EXIT_FAILURE); |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
@ -360,7 +362,7 @@ int main(int argc, char **argv) { |
|
|
|
fprintf(stderr, "both numbers must be set\n"); |
|
|
|
fprintf(stderr, "both numbers must be set\n"); |
|
|
|
exit(EXIT_FAILURE); |
|
|
|
exit(EXIT_FAILURE); |
|
|
|
} |
|
|
|
} |
|
|
|
ret = rec_diff(db, a, b, map); |
|
|
|
ret = rec_diff(db, a, b, show_map); |
|
|
|
break; |
|
|
|
break; |
|
|
|
default : |
|
|
|
default : |
|
|
|
usage(EXIT_SUCCESS); |
|
|
|
usage(EXIT_SUCCESS); |
|
|
|