Browse Source

* rename type: rec__t -> imdb_rec_t

master
Alex 'AdUser' Z 10 years ago
parent
commit
b203005b52
  1. 2
      src/common.h
  2. 14
      src/database.c
  3. 10
      src/database.h
  4. 10
      src/imdb_1to2.c
  5. 16
      src/util.c
  6. 2
      tests/database.c

2
src/common.h

@ -27,5 +27,5 @@
extern int image_add(uint64_t, char *path); extern int image_add(uint64_t, char *path);
extern int image_del(uint64_t); extern int image_del(uint64_t);
extern int image_exists(uint64_t); extern int image_exists(uint64_t);
extern int image_search(uint64_t, rec_t **data, size_t limit); extern int image_search(uint64_t, imdb_rec_t **data, size_t limit);
*/ */

14
src/database.c

@ -96,7 +96,7 @@ int db_close(imdb_t *db)
return 0; return 0;
} }
int db_rd_rec(imdb_t *db, rec_t *rec) int db_rd_rec(imdb_t *db, imdb_rec_t *rec)
{ {
ssize_t bytes = 0; ssize_t bytes = 0;
@ -110,7 +110,7 @@ int db_rd_rec(imdb_t *db, rec_t *rec)
return bytes / IMDB_REC_LEN; return bytes / IMDB_REC_LEN;
} }
int db_wr_rec(imdb_t *db, rec_t *rec) int db_wr_rec(imdb_t *db, imdb_rec_t *rec)
{ {
ssize_t bytes = 0; ssize_t bytes = 0;
@ -142,9 +142,9 @@ int db_rd_blk(imdb_t *db, block_t *blk)
return blk->records; return blk->records;
} }
int db_rd_list(imdb_t *db, rec_t *list, size_t list_len) int db_rd_list(imdb_t *db, imdb_rec_t *list, size_t list_len)
{ {
rec_t *r = NULL; imdb_rec_t *r = NULL;
ssize_t bytes; ssize_t bytes;
unsigned int i = 0; unsigned int i = 0;
unsigned int processed = 0; unsigned int processed = 0;
@ -163,9 +163,9 @@ int db_rd_list(imdb_t *db, rec_t *list, size_t list_len)
return processed; return processed;
} }
int db_wr_list(imdb_t *db, rec_t *list, size_t list_len) int db_wr_list(imdb_t *db, imdb_rec_t *list, size_t list_len)
{ {
rec_t *r = NULL; imdb_rec_t *r = NULL;
ssize_t bytes; ssize_t bytes;
unsigned int i = 0; unsigned int i = 0;
unsigned int processed = 0; unsigned int processed = 0;
@ -184,7 +184,7 @@ int db_wr_list(imdb_t *db, rec_t *list, size_t list_len)
return processed; return processed;
} }
int db_search(imdb_t *db, rec_t *sample, float tresh, match_t **matches) int db_search(imdb_t *db, imdb_rec_t *sample, float tresh, match_t **matches)
{ {
const int blk_size = 4096; const int blk_size = 4096;
uint64_t found = 0; uint64_t found = 0;

10
src/database.h

@ -60,7 +60,7 @@ sect | [ 0-15 ][ 16-31 ][ 32-48 ]
typedef struct { typedef struct {
uint64_t num; uint64_t num;
unsigned char data[IMDB_REC_LEN]; unsigned char data[IMDB_REC_LEN];
} rec_t; } imdb_rec_t;
typedef struct { typedef struct {
uint64_t num; uint64_t num;
@ -70,14 +70,14 @@ typedef struct {
extern int db_open(imdb_t *db, const char *path); extern int db_open(imdb_t *db, const char *path);
extern int db_close(imdb_t *db); extern int db_close(imdb_t *db);
extern int db_rd_rec(imdb_t *db, rec_t *rec); extern int db_rd_rec(imdb_t *db, imdb_rec_t *rec);
extern int db_wr_rec(imdb_t *db, rec_t *rec); extern int db_wr_rec(imdb_t *db, imdb_rec_t *rec);
extern int db_rd_blk(imdb_t *db, block_t *blk); extern int db_rd_blk(imdb_t *db, block_t *blk);
extern int db_wr_blk(imdb_t *db, block_t *blk); extern int db_wr_blk(imdb_t *db, block_t *blk);
extern int db_rd_list(imdb_t *db, rec_t *list, size_t list_len); extern int db_rd_list(imdb_t *db, imdb_rec_t *list, size_t list_len);
extern int db_wr_list(imdb_t *db, rec_t *list, size_t list_len); extern int db_wr_list(imdb_t *db, imdb_rec_t *list, size_t list_len);
/** /**
@returns: @returns:

10
src/imdb_1to2.c

@ -19,7 +19,7 @@ void usage(const char *message) {
int main(int argc, char **argv) { int main(int argc, char **argv) {
int in, out; int in, out;
long unsigned int rec_total, rec_first, rec_last, records; long unsigned int imdb_rec_total, rec_first, rec_last, records;
unsigned char in_buf[IMDB_REC_LEN * BLK_SIZE]; unsigned char in_buf[IMDB_REC_LEN * BLK_SIZE];
unsigned char out_buf[IMDB_REC_LEN * BLK_SIZE]; unsigned char out_buf[IMDB_REC_LEN * BLK_SIZE];
unsigned char header[IMDB_REC_LEN]; unsigned char header[IMDB_REC_LEN];
@ -46,8 +46,8 @@ int main(int argc, char **argv) {
if ((st.st_size % IMDB_REC_LEN) != 0) if ((st.st_size % IMDB_REC_LEN) != 0)
usage("database size expected to be multiples to 48"); usage("database size expected to be multiples to 48");
rec_total = (st.st_size / IMDB_REC_LEN); imdb_rec_total = (st.st_size / IMDB_REC_LEN);
printf("Processing %lu records\n", rec_total - 1); printf("Processing %lu records\n", imdb_rec_total - 1);
if (lseek(in, IMDB_REC_LEN, SEEK_SET) < 0) if (lseek(in, IMDB_REC_LEN, SEEK_SET) < 0)
usage(strerror(errno)); usage(strerror(errno));
@ -57,9 +57,9 @@ int main(int argc, char **argv) {
if (write(out, header, IMDB_REC_LEN) != IMDB_REC_LEN) if (write(out, header, IMDB_REC_LEN) != IMDB_REC_LEN)
usage(strerror(errno)); usage(strerror(errno));
for (unsigned int block = 0; block <= (rec_total / BLK_SIZE); block++) { for (unsigned int block = 0; block <= (imdb_rec_total / BLK_SIZE); block++) {
rec_first = rec_last = (block * BLK_SIZE) + 1; rec_first = rec_last = (block * BLK_SIZE) + 1;
records = ((rec_first + BLK_SIZE) > rec_total) ? rec_total - rec_first : BLK_SIZE; records = ((rec_first + BLK_SIZE) > imdb_rec_total) ? imdb_rec_total - rec_first : BLK_SIZE;
rec_last = rec_first + records; rec_last = rec_first + records;
printf("* block %u, %4lu records [%lu, %lu]\n", printf("* block %u, %4lu records [%lu, %lu]\n",
block + 1, records, rec_first, rec_last - 1); block + 1, records, rec_first, rec_last - 1);

16
src/util.c

@ -37,7 +37,7 @@ void usage(int exitcode) {
exit(exitcode); exit(exitcode);
} }
int search_similar(imdb_t *db, rec_t *sample, float tresh) int search_similar(imdb_t *db, imdb_rec_t *sample, float tresh)
{ {
int ret = 0, i = 0; int ret = 0, i = 0;
match_t *matches = NULL; match_t *matches = NULL;
@ -95,7 +95,7 @@ int db_usage_map(imdb_t *db, unsigned short int cols)
return 0; return 0;
} }
int rec_bitmap(imdb_t *db, rec_t *sample) int rec_bitmap(imdb_t *db, imdb_rec_t *sample)
{ {
uint16_t row; uint16_t row;
uint8_t i, j; uint8_t i, j;
@ -124,8 +124,8 @@ int rec_bitmap(imdb_t *db, rec_t *sample)
int rec_diff(imdb_t *db, unsigned long a, unsigned long b, unsigned short int showmap) int rec_diff(imdb_t *db, unsigned long a, unsigned long b, unsigned short int showmap)
{ {
rec_t src; imdb_rec_t src;
rec_t dst; imdb_rec_t dst;
float diff = 0.0; float diff = 0.0;
unsigned char map[BITMAP_SIZE]; unsigned char map[BITMAP_SIZE];
uint16_t row; uint16_t row;
@ -133,8 +133,8 @@ int rec_diff(imdb_t *db, unsigned long a, unsigned long b, unsigned short int sh
assert(db != NULL); assert(db != NULL);
memset(&src, 1, sizeof(rec_t)); memset(&src, 1, sizeof(imdb_rec_t));
memset(&dst, 2, sizeof(rec_t)); memset(&dst, 2, sizeof(imdb_rec_t));
src.num = a; src.num = a;
dst.num = b; dst.num = b;
@ -183,13 +183,13 @@ int main(int argc, char **argv)
float tresh = 0.10; float tresh = 0.10;
unsigned short int cols = 64, map = 0; unsigned short int cols = 64, map = 0;
imdb_t db; imdb_t db;
rec_t sample; imdb_rec_t sample;
unsigned long a = 0, b = 0; unsigned long a = 0, b = 0;
char *c = NULL; char *c = NULL;
char opt = '\0'; char opt = '\0';
memset(&db, 0x0, sizeof(imdb_t)); memset(&db, 0x0, sizeof(imdb_t));
memset(&sample, 0x0, sizeof(rec_t)); memset(&sample, 0x0, sizeof(imdb_rec_t));
if (argc < 3) if (argc < 3)
usage(EXIT_FAILURE); usage(EXIT_FAILURE);

2
tests/database.c

@ -4,7 +4,7 @@
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
imdb_t db; imdb_t db;
rec_t rec[2]; imdb_rec_t rec[2];
block_t blk; block_t blk;
char *path = "test.db"; char *path = "test.db";

Loading…
Cancel
Save