refactor: started refactoring trie api (contains segfaults)
This commit is contained in:
parent
088322c18f
commit
50ebf86589
4 changed files with 109 additions and 115 deletions
|
|
@ -41,23 +41,22 @@ typedef struct entry {
|
|||
char *string;
|
||||
} Entry;
|
||||
|
||||
typedef enum trie_exit_code {
|
||||
Ok = 0,
|
||||
NotFound,
|
||||
AlreadyPresent,
|
||||
FileError
|
||||
} TrieExitCode;
|
||||
|
||||
Entry *entry_new(EntryType type, const char *string);
|
||||
|
||||
/**
|
||||
* Allocate and initialize an empty Trie.
|
||||
* Allocate & initialize a new trie, and populate it with the data from the
|
||||
* given data file.
|
||||
*
|
||||
* @return a pointer to an empty Trie struct
|
||||
* @return 0 if everything was successful, non-zero otherwise
|
||||
*/
|
||||
Trie *trie_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 trie_populate(Trie *trie, const char *file_path);
|
||||
TrieExitCode trie_init(Trie **trie_ptr, const char *file_path);
|
||||
|
||||
/**
|
||||
* De-allocate a trie by freeing the memory occupied by this trie.
|
||||
|
|
@ -70,10 +69,11 @@ void trie_free(Trie *trie);
|
|||
* Search for an entry in the trie.
|
||||
*
|
||||
* @param trie
|
||||
* @param entry_ptr pointer to Entry will be stored here, if found
|
||||
* @param key key representing the entry
|
||||
* @return pointer to entry; NULL if not found
|
||||
* @return 0 if the search was successful, 1 if not found
|
||||
*/
|
||||
Entry *trie_search(Trie *trie, const char *key);
|
||||
TrieExitCode trie_search(Trie *trie, Entry **entry_ptr, const char *key);
|
||||
|
||||
/**
|
||||
* Add a string to this trie.
|
||||
|
|
@ -81,12 +81,9 @@ Entry *trie_search(Trie *trie, const char *key);
|
|||
* @param trie
|
||||
* @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
|
||||
* @return 0 if added, 1 if already in trie, something else if other errors
|
||||
*/
|
||||
bool trie_add(Trie *trie, const char *key, Entry *entry);
|
||||
|
||||
bool trie_add_no_lock(Trie *trie, const char *key, Entry *entry);
|
||||
TrieExitCode trie_add(Trie *trie, const char *key, Entry *entry);
|
||||
|
||||
/**
|
||||
* Add an entry by generating a random string as the key.
|
||||
|
|
@ -97,7 +94,8 @@ bool trie_add_no_lock(Trie *trie, const char *key, Entry *entry);
|
|||
* @return pointer to the generated key. This pointer is safe to use after
|
||||
* unlocking the trie, and should be freed manually.
|
||||
*/
|
||||
char *trie_add_random(Trie *trie, Entry *entry, bool secure);
|
||||
TrieExitCode trie_add_random(Trie *trie, char **key_ptr, Entry *entry,
|
||||
bool secure);
|
||||
|
||||
/**
|
||||
* Remove an entry from this trie given its key.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue