diff options
| author | Soikk | 2022-08-13 21:32:42 +0200 |
|---|---|---|
| committer | Soikk | 2022-08-13 21:32:42 +0200 |
| commit | 1faec2ebd0c7151ff67390f7de7873f4b07cabb9 (patch) | |
| tree | 7b54a39506b24df37b5e1403a007a40d43c5bd62 /src | |
| parent | a341db54d82db0cfca948f0cf95b273430ee4675 (diff) | |
| download | soikk-DB-1faec2ebd0c7151ff67390f7de7873f4b07cabb9.tar.xz soikk-DB-1faec2ebd0c7151ff67390f7de7873f4b07cabb9.tar.zst | |
Updated README and fixed error on example images. Removed deleted dependencies. Fixed AVL tree bug.
Diffstat (limited to 'src')
| -rw-r--r-- | src/main.c | 16 | ||||
| -rw-r--r-- | src/storage.c | 14 |
2 files changed, 20 insertions, 10 deletions
@@ -6,26 +6,32 @@ int main(){ inputBuffer *in = newInputBuffer(); - /*database *test = newDatabase("miDB"); + /*database *test = newDatabase("miDB"); addFileTag(test, "vaca.png", "naturalezas"); addFileTags(test, "terry-davis.jpg", 3, "holyC", "programmer", "very cool"); addFileTag(test, "vaca.png", "lovely"); addFileTags(test, "vaca.png", 3, "nature", "animal", "very cool"); addFileTag(test, "terry-davis.jpg", "based"); + + printDatabase(test); + + debugDatabase(test); storeDatabase(test, "db.db"); + + test = loadDatabase("db.db"); - printDatabase(db); + printDatabase(test); - debugDatabase(db); + debugDatabase(test); uint64_t *l, i; - searchFile(db, "terry-davis.jpg", 0, &l, &i); + searchFile(test, "terry-davis.jpg", 0, &l, &i); printf("Tags with file 'terry-davis.jpg':\n"); for(uint64_t j = 0; j < i; ++j){ - printf("\t%s\n", db->ltags->table[l[j]]); + printf("\t%s\n", test->ltags->table[l[j]]); }*/ diff --git a/src/storage.c b/src/storage.c index bc5ab6b..dc1ad88 100644 --- a/src/storage.c +++ b/src/storage.c @@ -504,13 +504,17 @@ int storeAVLTree(tree root, FILE *fp){ return 0; } -static node *arrayToNodes(uint64_t *array, uint64_t i, uint64_t maxNodes){ - if(i >= maxNodes*2){ +static node *arrayToNodes(uint64_t *array, uint64_t pos, uint64_t maxNodes){ + if(pos >= maxNodes*2){ return NULL; } - node *n = newNode(array[i+0], array[i+1]); - n->left = arrayToNodes(array, (2*i + 1)*2, maxNodes); - n->right = arrayToNodes(array, (2*i + 2)*2, maxNodes); + uint64_t h = array[pos+0], i = array[pos+1]; + if(h == UINTMAX_MAX && i == UINTMAX_MAX){ + return NULL; + } + node *n = newNode(h, i); + n->left = arrayToNodes(array, (2*pos + 1)*2, maxNodes); + n->right = arrayToNodes(array, (2*pos + 2)*2, maxNodes); return n; } |
