]> git.xolatile.top Git - soikk-DB.git/commitdiff
Minor changes.
authorSoikk <76824648+Soikk@users.noreply.github.com>
Mon, 8 Aug 2022 19:56:27 +0000 (21:56 +0200)
committerSoikk <76824648+Soikk@users.noreply.github.com>
Mon, 8 Aug 2022 19:56:27 +0000 (21:56 +0200)
CHANGELOG
DOC
src/database.c
src/storage.c

index 945f0d3af9e2d948bddb5c81d925fcff46263d99..2f43bc52dcc21c984886c22d0eab1d5c4506f5ad 100644 (file)
--- 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 72e7535599c7eaa43cd8a693d3cc4f33e9ee09e1..8aa33d4bc8c3e7ce325de9e39cd93355d0c05081 100644 (file)
--- 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.
index f930539744672b0815dc04fcd232cd7e35d8bbc3..5b03b4bc0aaad2d30b8bf83b2c612590b83ba82e 100644 (file)
@@ -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;
        }
        
index 73d813101489af7342eb97982663cd7615b1d470..9afede75ac9b983de0b6bc6a52d32c9243dd6711 100644 (file)
@@ -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;