The string dictionary container.
More...
Go to the source code of this file.
|
typedef struct TrieData_ | TrieData |
| TrieData is the data type for the container private information. More...
|
|
The string dictionary container.
Definition in file trie.h.
TrieData is the data type for the container private information.
Definition at line 10 of file trie.h.
int32_t TrieInit |
( |
Trie ** |
ppObj | ) |
|
The constructor for Trie.
- Parameters
-
ppObj | The double pointer to the to be constructed trie |
- Return values
-
SUCC | |
ERR_NOMEM | Insufficient memory for trie construction |
void TrieDeinit |
( |
Trie ** |
ppObj | ) |
|
The destructor for Trie.
- Parameters
-
ppObj | The double pointer to the to be destructed trie |
int32_t TrieInsert |
( |
Trie * |
self, |
|
|
char * |
str |
|
) |
| |
Insert a string into the trie.
- Parameters
-
self | The pointer to Trie structure |
str | The designated string |
- Return values
-
SUCC | |
ERR_NOINIT | Uninitialized container |
ERR_NOMEM | Insufficient memory for trie extension |
int32_t TrieBulkInsert |
( |
Trie * |
self, |
|
|
char ** |
aStr, |
|
|
int |
iNum |
|
) |
| |
Insert an array of strings into the trie.
- Parameters
-
self | The pointer to Trie structure |
aStr | Array of to be inserted strings |
iNum | The array size |
- Return values
-
SUCC | |
ERR_NOINIT | Uninitialized container |
ERR_NOMEM | Insufficient memory for trie extension |
int32_t TrieHasExact |
( |
Trie * |
self, |
|
|
char * |
str |
|
) |
| |
Check if the trie contains the designated string.
- Parameters
-
self | The pointer to Trie structure |
str | The designated string |
- Return values
-
SUCC | |
NOKEY | |
ERR_NOINIT | Uninitialized container |
int32_t TrieHasPrefixAs |
( |
Trie * |
self, |
|
|
char * |
str |
|
) |
| |
Check if the trie contains the strings matching the designated prefix.
- Parameters
-
self | The pointer to Trie structure |
str | The designated prefix |
- Return values
-
SUCC | |
NOKEY | |
ERR_NOINIT | Uninitialized container |
ERR_NOMEM | Insufficient memory to prepare trie traversal |
int32_t TrieGetPrefixAs |
( |
Trie * |
self, |
|
|
char * |
str, |
|
|
char *** |
paStr, |
|
|
int * |
piNum |
|
) |
| |
Retrieve the strings from the trie matching the designated prefix.
To retrieve the strings, you need to pass:
- The pointer to the string array to store the returned strings.
- The pointer to the integer for the returned array size.
And this function will allocate the memory to store the returned strings. But if no string can be resolved, the string array will be returned as NULL and the array size will be returned as 0.
- Parameters
-
self | The pointer to Trie structure |
str | The designated prefix |
paStr | The pointer to the returned array of strings |
piNum | The pointer to the returned array size |
- Return values
-
SUCC | |
NOKEY | |
ERR_NOINIT | Uninitialized container |
ERR_GET | Invalid parameter to store returned data |
ERR_NOMEM | Insufficient memory to store the resolved strings |
- Note
- Please remember to free the following resource:
- Each returned string
- The array to store returned strings
int32_t TrieDelete |
( |
Trie * |
self, |
|
|
char * |
str |
|
) |
| |
Delete a string from the trie.
- Parameters
-
self | The pointer to Trie structure |
str | The designated string |
- Return values
-
SUCC | |
ERR_NOINIT | Uninitialized container |
ERR_NODATA | Non-existent string |
int32_t TrieSize |
( |
Trie * |
self | ) |
|
Return the number of strings stored in the trie.
- Parameters
-
self | The pointer to Trie structure |
- Returns
- The number of strings
- Return values
-
ERR_NOINIT | Uninitialized container |