diff options
| author | Soikk | 2022-08-06 21:46:45 +0200 |
|---|---|---|
| committer | Soikk | 2022-08-06 21:46:45 +0200 |
| commit | f9a7d9cd8a7e603c89d4cc5d98d7f694cc217d85 (patch) | |
| tree | 647b02d6ebabbafed7604da36685b5d17e0c825c /include/storage.h | |
| parent | 0e95d2c61da7b7fbce76b0633313128b7440136e (diff) | |
| download | soikk-DB-f9a7d9cd8a7e603c89d4cc5d98d7f694cc217d85.tar.xz soikk-DB-f9a7d9cd8a7e603c89d4cc5d98d7f694cc217d85.tar.zst | |
Refactored database. Replaced htable with ctable (same thing different name). Introduced AVL tree for hashes.
Diffstat (limited to 'include/storage.h')
| -rw-r--r-- | include/storage.h | 65 |
1 files changed, 48 insertions, 17 deletions
diff --git a/include/storage.h b/include/storage.h index ebf2dc2..8bfc751 100644 --- a/include/storage.h +++ b/include/storage.h @@ -60,11 +60,11 @@ typedef struct lookupTable{ char **table; // They cant be longer than MAXPATH } ltable; -// Stores the hashes of the filepaths/tags (for easier lookup) -typedef struct hashTable{ +// Stores a number (used as the count for files and tags in the mapping table) +typedef struct countTable{ uint64_t size; uint64_t *table; -} htable; +} ctable; typedef struct relation{ uint64_t file; @@ -77,42 +77,73 @@ typedef struct mappingTable{ relation *table; } mtable; +// Stores a hash and an index (hash table implemented with an AVL tree) for easier lookup +typedef struct AVLnode{ + uint64_t h; + uint64_t i; + struct AVLnode *left; + struct AVLnode *right; +} node; -// LTABLE -ltable *newLtable(uint64_t size); +typedef node* tree; -ltable *loadLtable(FILE *fp); -int storeLtable(const ltable *lt, FILE *fp); +// LTABLE + +ltable *newLtable(uint64_t size); int ltableAdd(ltable *lt, char *str); uint64_t ltableSearch(ltable *lt, char *str); -// HTABLE +int storeLtable(const ltable *lt, FILE *fp); + +ltable *loadLtable(FILE *fp); + +// CTABLE -htable *newHtable(uint64_t size); +ctable *newCtable(uint64_t size); -htable *loadHtable(FILE *fp); +int ctableAdd(ctable *ct, uint64_t n); -int storeHtable(const htable *ht, FILE *fp); +int ctableDelete(ctable *ct, uint64_t n); -int htableAdd(htable *ht, uint64_t h); +uint64_t ctableSearch(ctable *ct, uint64_t n); -uint64_t htableSearch(htable *ht, uint64_t h); +int storeCtable(const ctable *ht, FILE *fp); -int htableDelete(htable *ht, uint64_t h); +ctable *loadCtable(FILE *fp); // MTABLE mtable *newMtable(uint64_t size); -mtable *loadMtable(FILE *fp); +int mtableAdd(mtable *mt, relation r); + +uint64_t mtableSearch(mtable *mt, relation r); + +uint64_t mtableSearchFile(mtable *mt, uint64_t file); + +uint64_t mtableSearchTag(mtable *mt, uint64_t tag); int storeMtable(const mtable *mt, FILE *fp); -int mtableAdd(mtable *mt, relation r); +mtable *loadMtable(FILE *fp); -uint64_t mtableSearch(mtable *mt, relation r); +// AVL TREE + +uint64_t height(node *n); + +node *newNode(uint64_t h, uint64_t i); + +node *insertNode(node *r, uint64_t h, uint64_t i); + +node *deleteNode(node *r, uint64_t h); + +uint64_t nodeSearch(node *n, uint64_t h); + +int storeAVLTree(tree root, FILE *fp); + +tree loadAVLTree(FILE *fp); #endif |
