Browse Source

* move simdb_bitmap_print() from library to tool

master
Alex 'AdUser' Z 8 years ago
parent
commit
e0dea4f3c7
  1. 20
      src/bitmap.c
  2. 13
      src/bitmap.h
  3. 37
      src/simdb-query.c

20
src/bitmap.c

@ -98,23 +98,3 @@ simdb_bitmap_unpack(const unsigned char *map, char **buf) {
return buf_size; return buf_size;
} }
void
simdb_bitmap_print(const unsigned char *map) {
char *buf = NULL, *p = NULL;
char line[SIMDB_BITMAP_SIDE * 2 + 1];
simdb_bitmap_unpack(map, &buf);
p = buf;
line[SIMDB_BITMAP_SIDE * 2] = '\0';
for (size_t i = 0; i < SIMDB_BITMAP_SIDE; i++) {
for (size_t j = 0; j < SIMDB_BITMAP_SIDE; j++, p++) {
line[(j * 2) + 0] = (*p == 0x00) ? CHAR_NONE : CHAR_USED;
line[(j * 2) + 1] = (*p == 0x00) ? CHAR_NONE : CHAR_USED;
}
puts(line);
}
FREE(buf);
}

13
src/bitmap.h

@ -13,10 +13,6 @@
/** Bitmap size in bytes (currently - 32) */ /** Bitmap size in bytes (currently - 32) */
#define SIMDB_BITMAP_SIZE (SIMDB_BITMAP_BITS / 8) #define SIMDB_BITMAP_SIZE (SIMDB_BITMAP_BITS / 8)
/** placeholders for various bit states */
#define CHAR_USED '@' /**< bit is 1 */
#define CHAR_NONE '-' /**< bit is 0 */
/** /**
* @brief Compare two bitmaps * @brief Compare two bitmaps
* @param a First bitmap to compare * @param a First bitmap to compare
@ -48,13 +44,4 @@ simdb_bitmap_diffmap(const unsigned char *a,
*/ */
size_t size_t
simdb_bitmap_unpack(const unsigned char *map, char **buf); simdb_bitmap_unpack(const unsigned char *map, char **buf);
/**
* @brief Print bitmap to stdout as ascii-square
* @param map Source bitmap
* @note Height of "square" is equals to BITMAP_SIDE,
* but width is BITMAP_SIDE x 2, for ease of reading
*/
void
simdb_bitmap_print(const unsigned char *map);
#endif #endif

37
src/simdb-query.c

@ -45,6 +45,30 @@ void usage(int exitcode) {
exit(exitcode); exit(exitcode);
} }
/**
* @brief Print bitmap to stdout as ascii-square
* @param map Source bitmap
* @note Height of "square" is equals to BITMAP_SIDE,
* but width is BITMAP_SIDE x 2, for ease of reading
*/
void
bitmap_print(const char *map, size_t side) {
const char *p = NULL;
char line[side * 2 + 1];
assert(map != NULL);
p = map;
for (size_t i = 0; i < side; i++) {
line[side * 2] = '\0';
for (size_t j = 0; j < side; j++, p++) {
line[(j * 2) + 0] = *p ? CHAR_USED : CHAR_FREE;
line[(j * 2) + 1] = *p ? CHAR_USED : CHAR_FREE;
}
puts(line);
}
}
int search_similar(simdb_t *db, int num, float maxdiff) { int search_similar(simdb_t *db, int num, float maxdiff) {
int ret = 0, i = 0; int ret = 0, i = 0;
simdb_search_t search; simdb_search_t search;
@ -126,21 +150,22 @@ int db_usage_slice(simdb_t *db, uint64_t offset, uint16_t limit)
} }
int rec_bitmap(simdb_t *db, int num) { int rec_bitmap(simdb_t *db, int num) {
simdb_urec_t *r; char *bitmap;
size_t side;
int ret; int ret;
assert(db != NULL); assert(db != NULL);
if ((ret = simdb_read(db, num, 1, &r)) < 0) { if ((ret = simdb_record_bitmap(db, num, &bitmap, &side)) < 0) {
fprintf(stderr, "read failed: %s\n", simdb_error(ret)); fprintf(stderr, "can't get record's bitmap: %s\n", simdb_error(ret));
return 1; return 1;
} else if (ret == 0) { } else if (ret == 0) {
fprintf(stderr, "bitmap: %s\n", "sample not found"); fprintf(stderr, "bitmap: %s\n", "sample not found");
return 1; return 1;
} }
simdb_bitmap_print(r->bitmap); bitmap_print(bitmap, side);
free(r); free(bitmap);
return 0; return 0;
} }
@ -173,7 +198,7 @@ int rec_diff(simdb_t *db, int a, int b, unsigned short int showmap) {
if (showmap) { if (showmap) {
simdb_bitmap_diffmap(one->bitmap, two->bitmap, map); simdb_bitmap_diffmap(one->bitmap, two->bitmap, map);
simdb_bitmap_print(map); bitmap_print(map, SIMDB_BITMAP_SIDE);
return 0; return 0;
} }

Loading…
Cancel
Save