feat: pave way for pastebin integration

This commit is contained in:
Jef Roosens 2022-11-21 15:28:02 +01:00
parent 689a878978
commit f1ec643f80
Signed by: Jef Roosens
GPG key ID: B75D4F293C7052DB
5 changed files with 112 additions and 61 deletions

View file

@ -23,6 +23,19 @@ static const size_t charset_len = sizeof(charset) - 1;
*/
typedef struct ttrie TernaryTrie;
typedef enum entry_type {
Redirect,
Paste,
Unknown
} EntryType;
typedef struct entry {
EntryType type;
char *string;
} Entry;
Entry *entry_new(EntryType type, const char *string);
/**
* Allocate and initialize an empty Trie.
*
@ -47,50 +60,47 @@ int ternarytrie_populate(TernaryTrie* trie, const char* file_path);
void ternarytrie_free(TernaryTrie* trie);
/**
* Search whether a string is contained in this trie.
* Search for an entry in the trie.
*
* @param trie
* @param key
* @return pointer to payload string; NULL if not found
* @param key key representing the entry
* @return pointer to entry; NULL if not found
*/
char * ternarytrie_search(TernaryTrie* trie, const char* key);
Entry *ternarytrie_search(TernaryTrie* trie, const char* key);
/**
* Add a string to this trie.
*
* @param trie
* @param key
* @param payload payload to add
* @param key key to represent entry with
* @param entry entry to add
* @return true if the trie was changed by this operation, false if it was already present
*/
bool ternarytrie_add(TernaryTrie* trie, const char* key, const char *payload);
bool ternarytrie_add(TernaryTrie* trie, const char* key, Entry *entry);
/**
* Add a payload by generating a random string as the key.
* Add an entry by generating a random string as the key.
*
* @param trie
* @param payload payload to add
* @param entry entry to add
* @return the generated key
*/
char *ternarytrie_add_random(TernaryTrie *trie, const char *payload);
char *ternarytrie_add_random(TernaryTrie *trie, Entry *entry);
/**
* Remove a string from this trie.
*
* Note: strings added to this trie are considered to be "owned" by the caller.
* Removing the string from the trie should not free the string's memory.
* Remove an entry from this trie given its key.
*
* @param trie
* @param key
* @return true if the string was present and has been removed, false if it was not present
* @param key key representing entry
* @return true if the entry was present and has been removed, false if it was not present
*/
bool ternarytrie_remove(TernaryTrie* trie, const char* key);
bool ternarytrie_remove(TernaryTrie* trie, const char *key);
/**
* Returns the number of strings in this trie.
* Returns the number of entries in this trie.
*
* @param trie
* @return the number of strings in this trie
* @return the number of entries in this trie
*/
size_t ternarytrie_size(TernaryTrie* trie);