aboutsummaryrefslogtreecommitdiff
path: root/src/database.c
diff options
context:
space:
mode:
authorSoikk2022-07-24 22:26:35 +0200
committerSoikk2022-07-24 22:26:35 +0200
commitaf8d064328b718a90d66e1d729780563f17539f7 (patch)
tree8e492d0701a7f630c50011e15e9860610596eea7 /src/database.c
parentff5da06da823ac3a0bc7e89b35ed573255139b2d (diff)
downloadsoikk-DB-af8d064328b718a90d66e1d729780563f17539f7.tar.xz
soikk-DB-af8d064328b718a90d66e1d729780563f17539f7.tar.zst
Updated example
Diffstat (limited to 'src/database.c')
-rw-r--r--src/database.c36
1 files changed, 18 insertions, 18 deletions
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;
}
}