diff options
| author | Soikk | 2022-07-23 01:46:24 +0200 |
|---|---|---|
| committer | Soikk | 2022-07-23 01:46:24 +0200 |
| commit | 28578b192d0828a9820983b5624b9bcc3577cd18 (patch) | |
| tree | 2f30b1730f30a7eeee80995ee3984c10f5bdc2ff /include/storage.h | |
| parent | 377dc104be127291ede5b32640c23eea0ba6791a (diff) | |
| download | soikk-DB-28578b192d0828a9820983b5624b9bcc3577cd18.tar.xz soikk-DB-28578b192d0828a9820983b5624b9bcc3577cd18.tar.zst | |
Improved the database storage system. Added persistency.
Diffstat (limited to 'include/storage.h')
| -rw-r--r-- | include/storage.h | 105 |
1 files changed, 92 insertions, 13 deletions
diff --git a/include/storage.h b/include/storage.h index a30278f..82ea55a 100644 --- a/include/storage.h +++ b/include/storage.h @@ -3,24 +3,103 @@ #include "db.h" -#define MAXPATH 4094 -#define MAXTAGS 4094 +/* + tags are stored in a big table (or their hashes are) ordered + by alphabetical order + tags can have namespaces which are a special tag that starts + with a ':' + all tags in a namespace are located between two occurrences + of the namespace within the list, + e.g [":people", "sam hyde", "hitler", ":people"] + maybe namespaces use another hashing function to prevent + collisions because of the lack of space because of the ':' -// When intializing the struct, it is recommended -// to also initialize numTags and lenTags -typedef struct{ - char path[MAXPATH]; - char tags[MAXTAGS]; - uint16_t lenTags; - uint16_t numTags; -} row; + files (their paths) are stored in a big table (or their hashes + are) by alphabetical/numerical order + tags and files' indexes on their respective tables correspond + to the index of the actual tag or file on alookup table. + e.g + iT[23] = 816820769819429900 = hash(lT[23]) = hash("cacadevaca") -row *newRow(const char *path); + there is another table that ties the two together by their + indexes + if an file has more than one tag, it is stored as multiple + relations inside the table, e.g ["1:2", "1:3", "1:4"] -void insertTag(row *r, char *tag); + searching for an file that has a tag is as simple as + - finding the tag on its list + - if the tag is on the list, getting its index number + if not, return 'tag not found' + - search for all the relations that have the index as + the second argument + - if no files are found, return 'files not found' + - store the indexes of all the files (the first argument) + - return the list of all the files + - (OPTIONAL) show all the other tags the files shown have +*/ -void removeTag(row *r, char *tag); +#define MAXPATH 4096 + + +// Stores the actual filepaths/tags +typedef struct lookupTable{ + uint64_t size; + char **table; // They cant be longer than MAXPATH +} ltable; + +// Stores the hashes of the filepaths/tags (for easier lookup) +typedef struct hashTable{ + uint64_t size; + uint64_t *table; +} htable; + +typedef struct relation{ + uint64_t file; + uint64_t tag; +} relation; + +// Maps the relations between the filepaths and the tags +typedef struct mappingTable{ + uint64_t size; + relation *table; +} mtable; + + +// LTABLE +ltable *newLtable(uint64_t size); + +ltable *loadLtable(FILE *fp); + +int storeLtable(const ltable *lt, FILE *fp); + +int ltableAdd(ltable *lt, char *str); + +uint64_t ltableSearch(ltable *lt, char *str); + +// HTABLE + +htable *newHtable(uint64_t size); + +htable *loadHtable(FILE *fp); + +int storeHtable(const htable *ht, FILE *fp); + +int htableAdd(htable *ht, uint64_t h); + +uint64_t htableSearch(htable *ht, uint64_t h); + +// MTABLE + +mtable *newMtable(uint64_t size); + +mtable *loadMtable(FILE *fp); + +int storeMtable(const mtable *mt, FILE *fp); + +int mtableAdd(mtable *mt, relation r); + +uint64_t mtableSearch(mtable *mt, relation r); #endif |
