chore: added some comments

trie-skips
Jef Roosens 2022-11-21 14:46:53 +01:00
parent 494946d24a
commit 689a878978
Signed by: Jef Roosens
GPG Key ID: B75D4F293C7052DB
2 changed files with 23 additions and 14 deletions

View File

@ -29,7 +29,8 @@ int main() {
std::string file_path = "lander.data"; std::string file_path = "lander.data";
std::cout << "Populating trie from file '" << file_path << "'..." << std::endl; std::cout << "Populating trie from file '" << file_path << "'..."
<< std::endl;
int count = ternarytrie_populate(trie, file_path.c_str()); int count = ternarytrie_populate(trie, file_path.c_str());
@ -75,8 +76,7 @@ int main() {
}); });
CROW_ROUTE(app, "/<string>") CROW_ROUTE(app, "/<string>")
.methods(crow::HTTPMethod::Post)( .methods(crow::HTTPMethod::Post)(
[api_key, base_url, trie](const crow::request &req, [api_key, base_url, trie](const crow::request &req, std::string s) {
std::string s) {
AUTH(); AUTH();
std::string key = req.body; std::string key = req.body;

View File

@ -30,6 +30,13 @@ typedef struct ttrie TernaryTrie;
*/ */
TernaryTrie* ternarytrie_init(); TernaryTrie* ternarytrie_init();
/**
* Populate trie with entries stored in the given file.
*
* @param trie
* @param file_path path to file containing entries
* @return amount of entries added; -1 if an error occured
*/
int ternarytrie_populate(TernaryTrie* trie, const char* file_path); int ternarytrie_populate(TernaryTrie* trie, const char* file_path);
/** /**
@ -43,24 +50,26 @@ void ternarytrie_free(TernaryTrie* trie);
* Search whether a string is contained in this trie. * Search whether a string is contained in this trie.
* *
* @param trie * @param trie
* @param string * @param key
* @return true if the string is contained within this trie, false otherwise * @return pointer to payload string; NULL if not found
*/ */
char * ternarytrie_search(TernaryTrie* trie, const char* string); char * ternarytrie_search(TernaryTrie* trie, const char* key);
/** /**
* Add a string to this trie. * Add a string to this trie.
* *
* @param trie * @param trie
* @param string * @param key
* @param payload payload to add
* @return true if the trie was changed by this operation, false if it was already present * @return true if the trie was changed by this operation, false if it was already present
*/ */
bool ternarytrie_add(TernaryTrie* trie, const char* string, const char *payload); bool ternarytrie_add(TernaryTrie* trie, const char* key, const char *payload);
/** /**
* Add a payload by generating a random string as the key. * Add a payload by generating a random string as the key.
* *
* @param trie * @param trie
* @param payload payload to add
* @return the generated key * @return the generated key
*/ */
char *ternarytrie_add_random(TernaryTrie *trie, const char *payload); char *ternarytrie_add_random(TernaryTrie *trie, const char *payload);
@ -72,10 +81,10 @@ char *ternarytrie_add_random(TernaryTrie *trie, const char *payload);
* Removing the string from the trie should not free the string's memory. * Removing the string from the trie should not free the string's memory.
* *
* @param trie * @param trie
* @param string * @param key
* @return true if the string was present and has been removed, false if it was not present * @return true if the string was present and has been removed, false if it was not present
*/ */
bool ternarytrie_remove(TernaryTrie* trie, const char* string); bool ternarytrie_remove(TernaryTrie* trie, const char* key);
/** /**
* Returns the number of strings in this trie. * Returns the number of strings in this trie.