Browse Source

* rename macroses

master
Alex 'AdUser' Z 10 years ago
parent
commit
fa45ef0e15
  1. 44
      src/database.c
  2. 6
      src/database.h
  3. 2
      src/util.c
  4. 2
      tests/database.c

44
src/database.c

@ -47,7 +47,7 @@ int db_open(db_t *db, const char *path)
int init = 0; int init = 0;
ssize_t bytes = 0; ssize_t bytes = 0;
struct stat st; struct stat st;
char buf[REC_LEN] = "\0"; char buf[IMDB_REC_LEN] = "\0";
assert(db != NULL); assert(db != NULL);
assert(path != NULL); assert(path != NULL);
@ -69,12 +69,12 @@ int db_open(db_t *db, const char *path)
db->path = path; db->path = path;
if (init) { if (init) {
memset(buf, 0x0, REC_LEN); memset(buf, 0x0, IMDB_REC_LEN);
snprintf((char *) buf, REC_LEN, "DB of image fingerprints (vers %d)", DB_VERSION); snprintf((char *) buf, IMDB_REC_LEN, "DB of image fingerprints (vers %d)", IMDB_VERSION);
DB_SEEK(db, 0); DB_SEEK(db, 0);
DB_WRITE(db, buf, REC_LEN); DB_WRITE(db, buf, IMDB_REC_LEN);
return bytes / REC_LEN; return bytes / IMDB_REC_LEN;
} }
return 0; return 0;
@ -102,10 +102,10 @@ int db_rd_rec(db_t *db, rec_t *rec)
assert(rec != NULL); assert(rec != NULL);
assert(rec->num > 0); assert(rec->num > 0);
DB_SEEK(db, rec->num * REC_LEN); DB_SEEK(db, rec->num * IMDB_REC_LEN);
DB_READ(db, rec->data, REC_LEN); DB_READ(db, rec->data, IMDB_REC_LEN);
return bytes / REC_LEN; return bytes / IMDB_REC_LEN;
} }
int db_wr_rec(db_t *db, rec_t *rec) int db_wr_rec(db_t *db, rec_t *rec)
@ -116,10 +116,10 @@ int db_wr_rec(db_t *db, rec_t *rec)
assert(rec != NULL); assert(rec != NULL);
assert(rec->num > 0); assert(rec->num > 0);
DB_SEEK(db, rec->num * REC_LEN); DB_SEEK(db, rec->num * IMDB_REC_LEN);
DB_WRITE(db, rec->data, REC_LEN); DB_WRITE(db, rec->data, IMDB_REC_LEN);
return bytes / REC_LEN; return bytes / IMDB_REC_LEN;
} }
int db_rd_blk(db_t *db, block_t *blk) int db_rd_blk(db_t *db, block_t *blk)
@ -132,10 +132,10 @@ int db_rd_blk(db_t *db, block_t *blk)
assert(blk->records > 0); assert(blk->records > 0);
FREE(blk->data); FREE(blk->data);
CALLOC(blk->data, blk->records, REC_LEN); CALLOC(blk->data, blk->records, IMDB_REC_LEN);
DB_SEEK(db, blk->start * REC_LEN); DB_SEEK(db, blk->start * IMDB_REC_LEN);
DB_READ(db, blk->data, blk->records * REC_LEN); DB_READ(db, blk->data, blk->records * IMDB_REC_LEN);
blk->records = bytes / REC_LEN; blk->records = bytes / IMDB_REC_LEN;
return blk->records; return blk->records;
} }
@ -153,9 +153,9 @@ int db_rd_list(db_t *db, rec_t *list, size_t list_len)
r = list; r = list;
for (i = 0; i < list_len; i++, r++) { for (i = 0; i < list_len; i++, r++) {
DB_SEEK(db, r->num * REC_LEN); DB_SEEK(db, r->num * IMDB_REC_LEN);
DB_READ(db, r->data, REC_LEN); DB_READ(db, r->data, IMDB_REC_LEN);
if (bytes == REC_LEN) { processed++; } if (bytes == IMDB_REC_LEN) { processed++; }
} }
return processed; return processed;
@ -174,9 +174,9 @@ int db_wr_list(db_t *db, rec_t *list, size_t list_len)
r = list; r = list;
for (i = 0; i < list_len; i++, r++) { for (i = 0; i < list_len; i++, r++) {
DB_SEEK(db, r->num * REC_LEN); DB_SEEK(db, r->num * IMDB_REC_LEN);
DB_WRITE(db, r->data, REC_LEN); DB_WRITE(db, r->data, IMDB_REC_LEN);
if (bytes == REC_LEN) { processed++; } if (bytes == IMDB_REC_LEN) { processed++; }
} }
return processed; return processed;
@ -212,7 +212,7 @@ int db_search(db_t *db, rec_t *sample, float tresh, match_t **matches)
*matches = NULL; *matches = NULL;
while (db_rd_blk(db, &blk) > 0) { while (db_rd_blk(db, &blk) > 0) {
p = blk.data; p = blk.data;
for (i = 0; i < blk.records; i++, p += REC_LEN) { for (i = 0; i < blk.records; i++, p += IMDB_REC_LEN) {
t = p + OFF_USED; t = p + OFF_USED;
if (*t == 0x0) continue; if (*t == 0x0) continue;

6
src/database.h

@ -1,8 +1,8 @@
#ifndef HAS_DATABASE_H #ifndef HAS_DATABASE_H
#define HAS_DATABASE_H 1 #define HAS_DATABASE_H 1
#define REC_LEN 48 #define IMDB_REC_LEN 48
#define DB_VERSION 1 #define IMDB_VERSION 1
#define OPEN_FLAGS O_CREAT | O_RDWR #define OPEN_FLAGS O_CREAT | O_RDWR
typedef struct { typedef struct {
@ -36,7 +36,7 @@ typedef struct {
typedef struct { typedef struct {
uint64_t num; uint64_t num;
unsigned char data[REC_LEN]; unsigned char data[IMDB_REC_LEN];
} rec_t; } rec_t;
typedef struct { typedef struct {

2
src/util.c

@ -77,7 +77,7 @@ int db_usage_map(db_t *db, unsigned short int cols)
while (db_rd_blk(db, &blk) > 0) { while (db_rd_blk(db, &blk) > 0) {
p = blk.data; p = blk.data;
for (i = 0; i < blk.records; i++, p += REC_LEN) { for (i = 0; i < blk.records; i++, p += IMDB_REC_LEN) {
t = p + OFF_USED; t = p + OFF_USED;
buf[j] = (*t == 0xFF) ? '1' : '0'; buf[j] = (*t == 0xFF) ? '1' : '0';
if (j++ < cols) if (j++ < cols)

2
tests/database.c

@ -14,7 +14,7 @@ int main(int argc, char **argv)
rec[0].num = 1; rec[0].num = 1;
assert(db_rd_rec(&db, rec) == 0); assert(db_rd_rec(&db, rec) == 0);
memset(rec[0].data, 0xAA, REC_LEN); memset(rec[0].data, 0xAA, IMDB_REC_LEN);
assert(db_wr_rec(&db, rec) == 1); assert(db_wr_rec(&db, rec) == 1);
assert(db_rd_rec(&db, rec) == 1); assert(db_rd_rec(&db, rec) == 1);

Loading…
Cancel
Save