diff options
author | bpc2003 <wpesfriendnva@gmail.com> | 2025-04-24 17:08:08 -0400 |
---|---|---|
committer | bpc2003 <wpesfriendnva@gmail.com> | 2025-04-24 17:08:08 -0400 |
commit | 2b7a3a815fb5d0b5155deec5f613730e898e4100 (patch) | |
tree | 00db87ef554335e1c9871330703d86d0247a4ee8 | |
parent | 5b0d930e9e2605add559a70591573ffaa2fd8404 (diff) |
Update Documentation
-rw-r--r-- | Makefile | 4 | ||||
-rw-r--r-- | README.md | 25 | ||||
-rw-r--r-- | src/include/engine/delkeys.c (renamed from src/lib/delkeys.c) | 21 | ||||
-rw-r--r-- | src/include/engine/engine.h (renamed from src/lib/mdb.h) | 4 | ||||
-rw-r--r-- | src/include/engine/file.c (renamed from src/lib/file.c) | 8 | ||||
-rw-r--r-- | src/include/engine/getkeys.c (renamed from src/lib/getkeys.c) | 2 | ||||
-rw-r--r-- | src/include/engine/setkeys.c (renamed from src/lib/setkeys.c) | 2 | ||||
-rw-r--r-- | src/include/engine/utils.c (renamed from src/lib/utils.c) | 0 | ||||
-rw-r--r-- | src/include/engine/utils.h (renamed from src/lib/utils.h) | 2 | ||||
-rw-r--r-- | src/include/mdb.h | 6 | ||||
-rw-r--r-- | src/main.c | 2 | ||||
-rw-r--r-- | src/test.c | 2 |
12 files changed, 39 insertions, 39 deletions
@@ -8,7 +8,7 @@ all: mdb mdb: lib $(CC) src/main.c src/cmd.c $(D_FLAGS) -O2 $(C_FLAGS) -o $(BUILD)/mdb.out lib: $(BUILD) - $(CC) src/lib/*.c $(L_FLAGS) + $(CC) src/include/engine/*.c $(L_FLAGS) $(CC) -shared -o $(BUILD)/libmdb.so *.o rm *.o @@ -20,7 +20,7 @@ test: dev_lib dev: dev_lib $(CC) src/main.c src/cmd.c $(D_FLAGS) -g $(C_FLAGS) -o $(BUILD)/devmdb.out dev_lib: $(BUILD) - $(CC) src/lib/*.c $(L_FLAGS) -g + $(CC) src/include/engine/*.c $(L_FLAGS) -g $(CC) -shared -o $(BUILD)/libmdb.so *.o rm *.o @@ -43,20 +43,17 @@ if the file doesn't exist it will return an empty tablist array\ if readdb fails in any other way it will return NULL. - writedb: takes a filename and tablist array\ writedb writes the given tablist array to a file. -- getkeys: takes a tablist array and index\ -getkeys finds every single key-value pair in a given tablist\ -and returns an integer array with the indexes of each key-value pair. -- getkey: takes a tablist array, index, and key\ -getkey finds a key-value pair from a given tablist\ -if it can't find the key-value pair it will return an empty -tabidx. -- setkey: takes a pointer to a tablist array, an index, and a key-value pair\ -setkey sets a given key-value pair in a given object, if a given key already exists\ -it will overwrite the value set in that key.\ -If setkey is successful it will return 0. -- delkey: takes a tablist array, an index, and a key\ -delkey deletes the given key-value pair from the given object\ -if successful it will return 0. +- getkeys: takes a tablist array, id, list of keys,\ +and the length of the list of keys.\ +If id is -1, it will get every provided key from every document.\ +If keys is NULL, it will get every key-value pair from a document. +- setkeys: takes a tablist array, id, list of key-value pairs,\ +and the length of the list of pairs.\ +If id is -1, it will set the provided pairs in every document. +- delkeys: takes a tablist array, id, list of keys,\ +and the length of the list of keys.\ +If id is -1, it will delete every provided key from every document.\ +If keys is NULL it will delete every key from a document. ## Removal In order to remove mdb run:\ diff --git a/src/lib/delkeys.c b/src/include/engine/delkeys.c index a828e8d..ad9c228 100644 --- a/src/lib/delkeys.c +++ b/src/include/engine/delkeys.c @@ -2,14 +2,13 @@ #include <stdlib.h> #include <string.h> -#include "mdb.h" +#include "engine.h" #include "utils.h" static int delkey_helper(void *thr_data); static int delkey(tablist_t *, int, char *); static struct params *pass(mtx_t *mtx, tablist_t *list, char **keys, int len, int id); - struct params { mtx_t *mtx; tablist_t *copy; @@ -27,14 +26,14 @@ int delkeys(tablist_t *list, int id, char **keys, int len) if (mtx_init(&mtx, mtx_plain) != thrd_success) return -2; int rc = 0; - tablist_t *delkey_copy = calloc(list[0].len, sizeof(tablist_t)); - copytab(delkey_copy, list); + tablist_t *copy = calloc(list[0].len, sizeof(tablist_t)); + copytab(copy, list); if (id == -1) { thrd_t *thrds = calloc(list[0].len, sizeof(thrd_t)); - for (int i = 0; i < delkey_copy[0].len; ++i) - thrd_create(&thrds[i], delkey_helper, pass(&mtx, delkey_copy, keys, len, i)); - for (int i = 0; i < delkey_copy[0].len; ++i) { + for (int i = 0; i < copy[0].len; ++i) + thrd_create(&thrds[i], delkey_helper, pass(&mtx, copy, keys, len, i)); + for (int i = 0; i < copy[0].len; ++i) { if (rc) thrd_join(thrds[i], NULL); else @@ -42,15 +41,15 @@ int delkeys(tablist_t *list, int id, char **keys, int len) } free(thrds); } else - rc = delkey_helper(pass(&mtx, delkey_copy, keys, len, id)); + rc = delkey_helper(pass(&mtx, copy, keys, len, id)); if (!rc) { dellist(list); - memmove(list, delkey_copy, delkey_copy[0].len * sizeof(tablist_t)); + memmove(list, copy, copy[0].len * sizeof(tablist_t)); } else - dellist(delkey_copy); + dellist(copy); mtx_destroy(&mtx); - free(delkey_copy); + free(copy); return rc; } diff --git a/src/lib/mdb.h b/src/include/engine/engine.h index cb0502d..d233bdd 100644 --- a/src/lib/mdb.h +++ b/src/include/engine/engine.h @@ -1,5 +1,5 @@ -#ifndef MDB_H -#define MDB_H +#ifndef ENGINE_H +#define ENGINE_H #define TABLEN 1024 diff --git a/src/lib/file.c b/src/include/engine/file.c index 8b0c715..4da8b2d 100644 --- a/src/lib/file.c +++ b/src/include/engine/file.c @@ -2,13 +2,11 @@ #include <stdlib.h> #include <string.h> -#include "mdb.h" +#include "engine.h" static char *getpair(int *c, FILE *fp); -// readdb - reads the given file into a key table list -// if fp returns NULL it will return the empty list -// if readdb fails it will return NULL +// TODO: reimplement this to read file in FI format tablist_t *readdb(char *filename) { int len = 2; @@ -51,7 +49,7 @@ fail: return NULL; } -// writedb - writes a keytablist to a given file +// TODO: rewrite this function to write data in FI format void writedb(char *filename, tablist_t *list) { FILE *fp = fopen(filename, "wb"); diff --git a/src/lib/getkeys.c b/src/include/engine/getkeys.c index ab1cb2f..ae2eb73 100644 --- a/src/lib/getkeys.c +++ b/src/include/engine/getkeys.c @@ -3,7 +3,7 @@ #include <ctype.h> #include <threads.h> -#include "mdb.h" +#include "engine.h" #include "utils.h" static tabidx_t getkey(tablist_t *list, int id, char *key); diff --git a/src/lib/setkeys.c b/src/include/engine/setkeys.c index f52ab48..34ef3d2 100644 --- a/src/lib/setkeys.c +++ b/src/include/engine/setkeys.c @@ -3,7 +3,7 @@ #include <stdlib.h> #include <threads.h> -#include "mdb.h" +#include "engine.h" #include "utils.h" static int setkey_helper(void *thr_data); diff --git a/src/lib/utils.c b/src/include/engine/utils.c index 909c123..909c123 100644 --- a/src/lib/utils.c +++ b/src/include/engine/utils.c diff --git a/src/lib/utils.h b/src/include/engine/utils.h index 99a8efa..54bfc17 100644 --- a/src/lib/utils.h +++ b/src/include/engine/utils.h @@ -1,7 +1,7 @@ #ifndef UTILS_H #define UTILS_H -#include "mdb.h" +#include "engine.h" // dellist: deletes the provided table void dellist(tablist_t *list); diff --git a/src/include/mdb.h b/src/include/mdb.h new file mode 100644 index 0000000..cba4aa8 --- /dev/null +++ b/src/include/mdb.h @@ -0,0 +1,6 @@ +#ifndef MDB_H +#define MDB_H + +#include "engine/engine.h" + +#endif @@ -3,7 +3,7 @@ #include <string.h> #include <ctype.h> -#include "lib/mdb.h" +#include "include/mdb.h" #include "cmd.h" int getid(char *selector); @@ -1,7 +1,7 @@ #include <stdio.h> #include <stdlib.h> -#include "lib/mdb.h" +#include "include/mdb.h" void test_setkeys(void) { |