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.
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;
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;
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;
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;
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;
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;
}
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;
}
int removeLtable(ltable *lt, char *str){
uint64_t i = searchLtable(lt, str);
- if(i == -1){
+ if(i == UINTMAX_MAX){
return -1;
}
lt->size--;
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;
int removeMtable(mtable *mt, relation r){
uint64_t i = searchMtable(mt, r);
- if(i == -1){
+ if(i == UINTMAX_MAX){
return -1;
}
mt->size--;
return r;
}
-// Searches for h, returns i
uint64_t searchNode(node *n, uint64_t h){
if(n == NULL){
return UINTMAX_MAX;