aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSoikk2022-08-08 21:56:27 +0200
committerSoikk2022-08-08 21:56:27 +0200
commitae0921866fb49aadea65b8057ab000d42e75f24c (patch)
treeb0bd66fa790667a087dece98c5c40b6cc673e62c
parent65aada1a6d5f01e8d167fb816c467d60a28d2d97 (diff)
downloadsoikk-DB-ae0921866fb49aadea65b8057ab000d42e75f24c.tar.xz
soikk-DB-ae0921866fb49aadea65b8057ab000d42e75f24c.tar.zst
Minor changes.
-rw-r--r--CHANGELOG3
-rw-r--r--DOC9
-rw-r--r--src/database.c17
-rw-r--r--src/storage.c6
4 files changed, 20 insertions, 15 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 945f0d3..2f43bc5 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,6 @@
+1659988523 (Mon Aug 08 2022 21:55:23 GMT+0200 (Central European Summer Time))
+Minor changes.
+
1659987439 (Mon Aug 08 2022 21:37:19 GMT+0200 (Central European Summer Time))
Forgot to update changelog. Also fixed*.
diff --git a/DOC b/DOC
index 72e7535..8aa33d4 100644
--- a/DOC
+++ b/DOC
@@ -151,6 +151,15 @@ STORAGE
https://www.geeksforgeeks.org/avl-tree-set-1-insertion/
https://www.geeksforgeeks.org/avl-tree-set-2-deletion/
+ static inline uint64_t max(uint64_t a, uint64_t b);
+ Returns the maximum of a and b.
+
+ static uint64_t height(node *n);
+ Returns the height of node n.
+
+ static int64_t balance(node *n);
+ Returns the balance of node n.
+
node *insertNode(node *r, uint64_t h, uint64_t i);
Inserts a new node with hash h and index i into node r, self balancing the node structure after having done so.
Returns a pointer to the resulting node in that position.
diff --git a/src/database.c b/src/database.c
index f930539..5b03b4b 100644
--- a/src/database.c
+++ b/src/database.c
@@ -19,7 +19,7 @@ uint64_t addFile(database *db, char *file){
file = normalizeStrLimit(file, &l, MAXPATH-1);
uint64_t h = crc64(0, file, l);
uint64_t i = searchNode(db->hfiles, h);
- if(i == -1){
+ if(i == UINTMAX_MAX){
insertLtable(db->lfiles, file);
insertCtable(db->cfiles, 0);
i = db->lfiles->size-1;
@@ -33,7 +33,7 @@ uint64_t addTag(database *db, char *tag){
tag = normalizeStrLimit(tag, &l, MAXPATH-1);
uint64_t h = crc64(0, tag, l);
uint64_t i = searchNode(db->htags, h);
- if(i == -1){
+ if(i == UINTMAX_MAX){
insertLtable(db->ltags, tag);
insertCtable(db->ctags, 0);
i = db->ltags->size-1;
@@ -92,11 +92,6 @@ int addTagFiles(database *db, char *tag, int nfiles, ...){
return 0;
}
-// When removing the file from the ltable and ctable we change the indexes of the tags in front
-// of it. Thus, we must change their indexes on the avl tree and mapping table. To do this we
-// simply get all tags with an index higher than the tag we removed and substract one from it,
-// since when removing a tag from the tables all we did was shift down all the tags in front of
-// it one position
static void decreaseHigherIndexNode(node *n, uint64_t i){
if(n == NULL){
return;
@@ -128,7 +123,7 @@ int removeFile(database *db, char *file){
uint32_t l;
file = normalizeStrLimit(file, &l, MAXPATH-1);
uint64_t i = searchLtable(db->lfiles, file);
- if(i == -1){
+ if(i == UINTMAX_MAX){
return -1;
}
uint64_t *r, rl;
@@ -151,7 +146,7 @@ int removeTag(database *db, char *tag){
uint32_t l;
tag = normalizeStrLimit(tag, &l, MAXPATH-1);
uint64_t i = searchLtable(db->ltags, tag);
- if(i == -1){
+ if(i == UINTMAX_MAX){
return -1;
}
uint64_t *r, rl;
@@ -175,7 +170,7 @@ int searchFile(database *db, char *file, uint64_t n, uint64_t **r, uint64_t *rl)
file = normalizeStrLimit(file, &l, MAXPATH-1);
uint64_t h = crc64(0, file, l);
uint64_t fi = searchNode(db->hfiles, h);
- if(fi == -1){
+ if(fi == UINTMAX_MAX){
return -1;
}
@@ -202,7 +197,7 @@ int searchTag(database *db, char *tag, uint64_t n, uint64_t **r, uint64_t *rl){
tag = normalizeStrLimit(tag, &l, MAXPATH-1);
uint64_t h = crc64(0, tag, l);
uint64_t ti = searchNode(db->htags, h);
- if(ti == -1){
+ if(ti == UINTMAX_MAX){
return -1;
}
diff --git a/src/storage.c b/src/storage.c
index 73d8131..9afede7 100644
--- a/src/storage.c
+++ b/src/storage.c
@@ -38,7 +38,7 @@ int insertLtable(ltable *lt, char *str){
int removeLtable(ltable *lt, char *str){
uint64_t i = searchLtable(lt, str);
- if(i == -1){
+ if(i == UINTMAX_MAX){
return -1;
}
lt->size--;
@@ -51,7 +51,6 @@ int removeLtable(ltable *lt, char *str){
uint64_t searchLtable(ltable *lt, char *str){
uint32_t l;
str = normalizeStrLimit(str, &l, MAXPATH-1);
-
for(uint64_t i = 0; i < lt->size; ++i){
if(sameStr(str, lt->table[i])){
return i;
@@ -204,7 +203,7 @@ int insertMtable(mtable *mt, relation r){
int removeMtable(mtable *mt, relation r){
uint64_t i = searchMtable(mt, r);
- if(i == -1){
+ if(i == UINTMAX_MAX){
return -1;
}
mt->size--;
@@ -421,7 +420,6 @@ node *removeNode(node *r, uint64_t h){
return r;
}
-// Searches for h, returns i
uint64_t searchNode(node *n, uint64_t h){
if(n == NULL){
return UINTMAX_MAX;