feat: use more std::string
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
parent
26318de22e
commit
494946d24a
5 changed files with 38 additions and 24 deletions
|
|
@ -39,22 +39,22 @@ void ternarytrie_free(TernaryTrie *trie) {
|
|||
|
||||
bool ternarytrie_add_internal(TernaryTrie *trie, const char *string, const char *payload);
|
||||
|
||||
void ternarytrie_populate(TernaryTrie *trie, const char *file_path) {
|
||||
int ternarytrie_populate(TernaryTrie *trie, const char *file_path) {
|
||||
trie->file_path = my_strdup(file_path);
|
||||
|
||||
FILE* fp = fopen(file_path, "r");
|
||||
|
||||
// TODO properly handle this
|
||||
if (fp == NULL) {
|
||||
return;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// We read in lines of at most 8192 characters (sounds like enough)
|
||||
char buffer[8192];
|
||||
int i, j;
|
||||
int entries = 0;
|
||||
|
||||
while (fgets(buffer, 8192, fp)) {
|
||||
printf("%s", buffer);
|
||||
// Find index of space character
|
||||
i = 0;
|
||||
|
||||
|
|
@ -75,9 +75,12 @@ void ternarytrie_populate(TernaryTrie *trie, const char *file_path) {
|
|||
buffer[j] = '\0';
|
||||
|
||||
ternarytrie_add_internal(trie, buffer, buffer + i + 1);
|
||||
entries++;
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
|
||||
return entries;
|
||||
}
|
||||
|
||||
typedef struct searchresult {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue