Browse Source

* rename type

master
Alex 'AdUser' Z 10 years ago
parent
commit
5598fde41d
  1. 22
      src/database.c
  2. 26
      src/database.h
  3. 12
      src/query.c
  4. 4
      src/sampler.c

22
src/database.c

@ -44,7 +44,7 @@
const char *imdb_hdr_fmt = "IMDB v%02u, CAPS: %s;"; const char *imdb_hdr_fmt = "IMDB v%02u, CAPS: %s;";
int imdb_init(imdb_t *db, const char *path) int imdb_init(imdb_db_t *db, const char *path)
{ {
ssize_t bytes = 0; ssize_t bytes = 0;
unsigned char buf[IMDB_REC_LEN]; unsigned char buf[IMDB_REC_LEN];
@ -68,7 +68,7 @@ int imdb_init(imdb_t *db, const char *path)
return 0; return 0;
} }
int imdb_open(imdb_t *db, const char *path) int imdb_open(imdb_db_t *db, const char *path)
{ {
ssize_t bytes = 0; ssize_t bytes = 0;
struct stat st; struct stat st;
@ -77,7 +77,7 @@ int imdb_open(imdb_t *db, const char *path)
assert(db != NULL); assert(db != NULL);
assert(path != NULL); assert(path != NULL);
memset(db, 0x0, sizeof(imdb_t)); memset(db, 0x0, sizeof(imdb_db_t));
db->fd = -1; db->fd = -1;
errno = 0; errno = 0;
@ -117,7 +117,7 @@ int imdb_open(imdb_t *db, const char *path)
return 0; return 0;
} }
int imdb_close(imdb_t *db) int imdb_close(imdb_db_t *db)
{ {
assert(db != NULL); assert(db != NULL);
@ -131,7 +131,7 @@ int imdb_close(imdb_t *db)
return 0; return 0;
} }
int imdb_read_rec(imdb_t *db, imdb_rec_t *rec) int imdb_read_rec(imdb_db_t *db, imdb_rec_t *rec)
{ {
ssize_t bytes = 0; ssize_t bytes = 0;
@ -151,7 +151,7 @@ int imdb_read_rec(imdb_t *db, imdb_rec_t *rec)
return 1; return 1;
} }
int imdb_write_rec(imdb_t *db, imdb_rec_t *rec) int imdb_write_rec(imdb_db_t *db, imdb_rec_t *rec)
{ {
ssize_t bytes = 0; ssize_t bytes = 0;
@ -168,7 +168,7 @@ int imdb_write_rec(imdb_t *db, imdb_rec_t *rec)
return 1; return 1;
} }
int imdb_read_blk(imdb_t *db, imdb_block_t *blk) int imdb_read_blk(imdb_db_t *db, imdb_block_t *blk)
{ {
ssize_t bytes = 0; ssize_t bytes = 0;
@ -187,7 +187,7 @@ int imdb_read_blk(imdb_t *db, imdb_block_t *blk)
} }
uint64_t uint64_t
imdb_records_count(imdb_t * const db) { imdb_records_count(imdb_db_t * const db) {
struct stat st; struct stat st;
off_t size = 0; off_t size = 0;
@ -210,7 +210,7 @@ ratio_from_rec_data(unsigned char * const data) {
} }
int int
imdb_search(imdb_t * const db, imdb_search(imdb_db_t * const db,
imdb_rec_t * const sample, imdb_rec_t * const sample,
imdb_search_t * const search, imdb_search_t * const search,
imdb_match_t **matches) imdb_match_t **matches)
@ -291,8 +291,8 @@ imdb_search(imdb_t * const db,
} }
uint64_t uint64_t
imdb_usage_map(imdb_t * const db, imdb_usage_map(imdb_db_t * const db,
char ** const map) { char ** const map) {
const int blk_size = 4096; const int blk_size = 4096;
imdb_block_t blk; imdb_block_t blk;
uint64_t records; uint64_t records;

26
src/database.h

@ -10,7 +10,7 @@ typedef struct {
const char *path; const char *path;
const char *errstr; const char *errstr;
unsigned char caps[8]; unsigned char caps[8];
} imdb_t; } imdb_db_t;
/** /**
Database header format - fixed length, 48 bytes Database header format - fixed length, 48 bytes
@ -92,15 +92,15 @@ typedef struct {
* @return 1 on success, 0 if record not used * @return 1 on success, 0 if record not used
* and -1 if record number not exists, * and -1 if record number not exists,
*/ */
extern int imdb_read_rec (imdb_t *db, imdb_rec_t *rec); extern int imdb_read_rec (imdb_db_t *db, imdb_rec_t *rec);
extern int imdb_write_rec(imdb_t *db, imdb_rec_t *rec); extern int imdb_write_rec(imdb_db_t *db, imdb_rec_t *rec);
extern int imdb_read_blk (imdb_t *db, imdb_block_t *blk); extern int imdb_read_blk (imdb_db_t *db, imdb_block_t *blk);
extern int imdb_write_blk(imdb_t *db, imdb_block_t *blk); extern int imdb_write_blk(imdb_db_t *db, imdb_block_t *blk);
extern int imdb_init (imdb_t *db, const char *path); extern int imdb_init (imdb_db_t *db, const char *path);
extern int imdb_open (imdb_t *db, const char *path); extern int imdb_open (imdb_db_t *db, const char *path);
extern int imdb_close(imdb_t *db); extern int imdb_close(imdb_db_t *db);
float float
ratio_from_rec_data(unsigned char * const data); ratio_from_rec_data(unsigned char * const data);
@ -112,22 +112,22 @@ ratio_from_rec_data(unsigned char * const data);
>0 if found some matches >0 if found some matches
*/ */
extern int extern int
imdb_search(imdb_t * const db, imdb_search(imdb_db_t * const db,
imdb_rec_t * const sample, imdb_rec_t * const sample,
imdb_search_t * const search, imdb_search_t * const search,
imdb_match_t **matches); imdb_match_t ** matches);
/** /**
@returns: number of records in database @returns: number of records in database
*/ */
uint64_t uint64_t
imdb_records_count(imdb_t * const db); imdb_records_count(imdb_db_t * const db);
/** /**
@brief fills buffer 'map' according to records existense in database @brief fills buffer 'map' according to records existense in database
@returns records processed (and also buffer size) @returns records processed (and also buffer size)
*/ */
uint64_t uint64_t
imdb_usage_map(imdb_t * const db, imdb_usage_map(imdb_db_t * const db,
char ** const map); char ** const map);
#endif #endif

12
src/query.c

@ -38,7 +38,7 @@ void usage(int exitcode) {
exit(exitcode); exit(exitcode);
} }
int search_similar(imdb_t *db, uint64_t number, float maxdiff) int search_similar(imdb_db_t *db, uint64_t number, float maxdiff)
{ {
int ret = 0, i = 0; int ret = 0, i = 0;
imdb_rec_t sample; imdb_rec_t sample;
@ -68,7 +68,7 @@ int search_similar(imdb_t *db, uint64_t number, float maxdiff)
return 0; return 0;
} }
int db_usage_map(imdb_t *db, unsigned short int cols) int db_usage_map(imdb_db_t *db, unsigned short int cols)
{ {
char *map = NULL; char *map = NULL;
char *m = NULL; char *m = NULL;
@ -97,7 +97,7 @@ int db_usage_map(imdb_t *db, unsigned short int cols)
return 0; return 0;
} }
int rec_bitmap(imdb_t *db, uint64_t number) int rec_bitmap(imdb_db_t *db, uint64_t number)
{ {
imdb_rec_t rec; imdb_rec_t rec;
@ -115,7 +115,7 @@ int rec_bitmap(imdb_t *db, uint64_t number)
return 0; return 0;
} }
int rec_diff(imdb_t *db, uint64_t a, uint64_t b, unsigned short int showmap) int rec_diff(imdb_db_t *db, uint64_t a, uint64_t b, unsigned short int showmap)
{ {
imdb_rec_t rec; imdb_rec_t rec;
float diff = 0.0; float diff = 0.0;
@ -158,12 +158,12 @@ int main(int argc, char **argv)
const char *db_path = NULL; const char *db_path = NULL;
float maxdiff = 0.10; float maxdiff = 0.10;
unsigned short int cols = 64, map = 0; unsigned short int cols = 64, map = 0;
imdb_t db; imdb_db_t db;
uint64_t a = 0, b = 0; uint64_t 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_db_t));
if (argc < 3) if (argc < 3)
usage(EXIT_FAILURE); usage(EXIT_FAILURE);

4
src/sampler.c

@ -10,10 +10,10 @@ void usage() {
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
imdb_t db; imdb_db_t db;
imdb_rec_t rec; imdb_rec_t rec;
memset(&db, 0x0, sizeof(imdb_t)); memset(&db, 0x0, sizeof(imdb_db_t));
memset(&rec, 0x0, sizeof(imdb_rec_t)); memset(&rec, 0x0, sizeof(imdb_rec_t));
if (argc < 4) if (argc < 4)

Loading…
Cancel
Save