refactor: remove entry code from trie
This commit is contained in:
parent
4b772d003b
commit
0c742f45b0
7 changed files with 23 additions and 16 deletions
|
|
@ -5,7 +5,6 @@
|
|||
#include <string.h>
|
||||
|
||||
#include "trie.h"
|
||||
#include "trie_entry.c"
|
||||
#include "trie_node.c"
|
||||
|
||||
typedef struct ttrie {
|
||||
|
|
|
|||
|
|
@ -1,42 +0,0 @@
|
|||
#include "trie.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
EntryType entry_type_from_char(char c) {
|
||||
switch (c) {
|
||||
case '0':
|
||||
return Redirect;
|
||||
case '1':
|
||||
return Paste;
|
||||
default:
|
||||
return Unknown;
|
||||
}
|
||||
}
|
||||
|
||||
char entry_type_to_char(EntryType et) {
|
||||
switch (et) {
|
||||
case Redirect:
|
||||
return '0';
|
||||
case Paste:
|
||||
return '1';
|
||||
default:
|
||||
return '\0';
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t entry_new(Entry **entry_ptr, EntryType type, const char *string) {
|
||||
size_t str_len = strlen(string);
|
||||
uint64_t entry_size = sizeof(EntryType) + str_len + 1;
|
||||
Entry *entry = malloc(entry_size);
|
||||
entry->type = type;
|
||||
|
||||
if (string != NULL) {
|
||||
memcpy(entry->string, string, str_len + 1);
|
||||
} else {
|
||||
entry->string[0] = '\0';
|
||||
}
|
||||
|
||||
*entry_ptr = entry;
|
||||
return entry_size;
|
||||
}
|
||||
|
||||
void entry_free(Entry *entry) { free(entry); }
|
||||
Loading…
Add table
Add a link
Reference in a new issue