From af8d064328b718a90d66e1d729780563f17539f7 Mon Sep 17 00:00:00 2001 From: Soikk Date: Sun, 24 Jul 2022 22:26:35 +0200 Subject: Updated example --- src/database.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'src/database.c') diff --git a/src/database.c b/src/database.c index f034464..ea3a6e0 100644 --- a/src/database.c +++ b/src/database.c @@ -130,21 +130,21 @@ int addFileTags(database *db, char *file, int ntags, ...){ return 0; } -// Stores in r a list with the indexes of the first n files that have this tag +// Stores in r a list with the indexes of the first n tags that this file has // If n is 0 or lower, it returns all of them. Stores in rl the length of r -int searchTag(database *db, char *tag, uint64_t n, uint64_t **r, uint64_t *rl){ +int searchFile(database *db, char *file, uint64_t n, uint64_t **r, uint64_t *rl){ uint32_t l; - tag = normalizeStrLimit(tag, &l, MAXPATH-1); - uint64_t h = crc64(0, tag, l); - uint64_t ti = htableSearch(db->htags, h); - if(ti == -1){ + file = normalizeStrLimit(file, &l, MAXPATH-1); + uint64_t h = crc64(0, file, l); + uint64_t fi = htableSearch(db->hfiles, h); + if(fi == -1){ return -1; } *rl = 0; for(uint64_t i = 0; i < db->map->size; ++i){ if(n < 1 || *rl < n){ - if(db->map->table[i].tag == ti){ + if(db->map->table[i].file == fi){ ++(*rl); } } @@ -152,29 +152,29 @@ int searchTag(database *db, char *tag, uint64_t n, uint64_t **r, uint64_t *rl){ *r = malloc((*rl)*sizeof(uint64_t)); uint64_t c = 0; for(uint64_t i = 0; i < db->map->size && c < *rl; ++i){ - if(db->map->table[i].tag == ti){ - (*r)[c++] = db->map->table[i].file; + if(db->map->table[i].file == fi){ + (*r)[c++] = db->map->table[i].tag; } } return 0; } -// Stores in r a list with the indexes of the first n tags that this file has +// Stores in r a list with the indexes of the first n files that have this tag // If n is 0 or lower, it returns all of them. Stores in rl the length of r -int searchFile(database *db, char *file, uint64_t n, uint64_t **r, uint64_t *rl){ +int searchTag(database *db, char *tag, uint64_t n, uint64_t **r, uint64_t *rl){ uint32_t l; - file = normalizeStrLimit(file, &l, MAXPATH-1); - uint64_t h = crc64(0, file, l); - uint64_t fi = htableSearch(db->hfiles, h); - if(fi == -1){ + tag = normalizeStrLimit(tag, &l, MAXPATH-1); + uint64_t h = crc64(0, tag, l); + uint64_t ti = htableSearch(db->htags, h); + if(ti == -1){ return -1; } *rl = 0; for(uint64_t i = 0; i < db->map->size; ++i){ if(n < 1 || *rl < n){ - if(db->map->table[i].file == fi){ + if(db->map->table[i].tag == ti){ ++(*rl); } } @@ -182,8 +182,8 @@ int searchFile(database *db, char *file, uint64_t n, uint64_t **r, uint64_t *rl) *r = malloc((*rl)*sizeof(uint64_t)); uint64_t c = 0; for(uint64_t i = 0; i < db->map->size && c < *rl; ++i){ - if(db->map->table[i].file == fi){ - (*r)[c++] = db->map->table[i].tag; + if(db->map->table[i].tag == ti){ + (*r)[c++] = db->map->table[i].file; } } -- cgit v1.2.3