Browse Source

* util.c : update rec_diff()

master
Alex 'AdUser' Z 10 years ago
parent
commit
7608eaf233
  1. 43
      src/util.c

43
src/util.c

@ -100,7 +100,6 @@ int db_usage_map(imdb_t *db, unsigned short int cols)
int rec_bitmap(imdb_t *db, uint64_t number) int rec_bitmap(imdb_t *db, uint64_t number)
{ {
imdb_rec_t rec; imdb_rec_t rec;
unsigned char *map = NULL;
assert(db != NULL); assert(db != NULL);
memset(&rec, 0x0, sizeof(imdb_rec_t)); memset(&rec, 0x0, sizeof(imdb_rec_t));
@ -114,52 +113,44 @@ int rec_bitmap(imdb_t *db, uint64_t number)
return 0; return 0;
} }
bitmap_unpack(&rec.data[REC_OFF_BM], &map); bitmap_print(&rec.data[REC_OFF_BM]);
bitmap_print(map);
return 0; return 0;
} }
int rec_diff(imdb_t *db, uint64_t a, uint64_t b, unsigned short int showmap) int rec_diff(imdb_t *db, uint64_t a, uint64_t b, unsigned short int showmap)
{ {
imdb_rec_t src; imdb_rec_t rec;
imdb_rec_t dst;
float diff = 0.0; float diff = 0.0;
unsigned char one[BITMAP_SIZE];
unsigned char two[BITMAP_SIZE];
unsigned char map[BITMAP_SIZE]; unsigned char map[BITMAP_SIZE];
assert(db != NULL); assert(db != NULL);
memset(&rec, 0x0, sizeof(imdb_rec_t));
memset(&src, 1, sizeof(imdb_rec_t)); rec.num = a;
memset(&dst, 2, sizeof(imdb_rec_t)); if (imdb_read_rec(db, &rec) < 1) {
src.num = a;
dst.num = b;
if (imdb_read_rec(db, &src) < 1)
return -1;
if (!src.data[0]) {
puts("First sample not exists"); puts("First sample not exists");
return 0; return 0;
} }
memcpy(one, &rec.data[REC_OFF_BM], BITMAP_SIZE);
if (imdb_read_rec(db, &dst) < 1) rec.num = b;
return -1; if (imdb_read_rec(db, &rec) < 1) {
puts("Second sample not exists");
if (!src.data[0]) {
puts("First sample not exists");
return 0; return 0;
} }
memcpy(two, &rec.data[REC_OFF_BM], BITMAP_SIZE);
if (showmap == 0) { if (showmap) {
diff = (float) bitmap_compare(&src.data[REC_OFF_BM], &dst.data[REC_OFF_BM]); bitmap_diffmap(map, one, two);
diff /= BITMAP_BITS; bitmap_print(map);
printf("%.2f%%\n", diff * 100);
return 0; return 0;
} }
bitmap_diffmap(&map[0], &src.data[REC_OFF_BM], &dst.data[REC_OFF_BM]); diff = (float) bitmap_compare(one, two);
bitmap_print(map); printf("%.2f%%\n", (diff / BITMAP_BITS) * 100);
return 0; return 0;
} }

Loading…
Cancel
Save