refactor: remove entry code from trie

generic-data-trie
Jef Roosens 2022-12-08 07:52:21 +01:00
parent 4b772d003b
commit 0c742f45b0
Signed by: Jef Roosens
GPG Key ID: B75D4F293C7052DB
7 changed files with 23 additions and 16 deletions

View File

@ -4,7 +4,7 @@ project(lander C CXX)
set(CMAKE_C_STANDARD 17) set(CMAKE_C_STANDARD 17)
set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD 17)
include_directories(trie/include) include_directories(include trie/include)
add_subdirectory(crow) add_subdirectory(crow)
add_subdirectory(trie) add_subdirectory(trie)
@ -15,6 +15,6 @@ else()
add_compile_options(-O3 -flto) add_compile_options(-O3 -flto)
endif() endif()
add_executable(lander src/main.cpp) add_executable(lander src/main.cpp src/entry.c)
target_link_libraries(lander PUBLIC Crow::Crow trie) target_link_libraries(lander PUBLIC Crow::Crow trie)
endif() endif()

View File

@ -1,7 +1,7 @@
# =====CONFIG===== # =====CONFIG=====
BUILD_DIR := ./build BUILD_DIR := ./build
SRC_DIRS := ./src ./trie/src SRC_DIRS := ./src ./trie/src
INCLUDE_DIRS := ./trie/include INCLUDE_DIRS := ./trie/include ./include
TEST_DIR := test TEST_DIR := test
CORES != nproc CORES != nproc

17
include/entry.h 100644
View File

@ -0,0 +1,17 @@
#ifndef LANDER_ENTRY
#define LANDER_ENTRY
#include <stdint.h>
typedef enum entry_type { Redirect, Paste, Unknown } EntryType;
typedef struct entry {
EntryType type;
char string[];
} Entry;
uint64_t entry_new(Entry **entry_ptr, EntryType type, const char *string);
void entry_free(Entry *entry);
#endif

View File

@ -1,5 +1,6 @@
#include "trie.h" #include "entry.h"
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
EntryType entry_type_from_char(char c) { EntryType entry_type_from_char(char c) {
switch (c) { switch (c) {

View File

@ -4,6 +4,7 @@
#include "crow.h" #include "crow.h"
extern "C" { extern "C" {
#include "entry.h"
#include "trie.h" #include "trie.h"
} }

View File

@ -38,13 +38,6 @@ static const size_t charset_len = sizeof(charset) - 1;
*/ */
typedef struct ttrie Trie; typedef struct ttrie Trie;
typedef enum entry_type { Redirect, Paste, Unknown } EntryType;
typedef struct entry {
EntryType type;
char string[];
} Entry;
typedef enum trie_exit_code { typedef enum trie_exit_code {
Ok = 0, Ok = 0,
NotFound, NotFound,
@ -52,10 +45,6 @@ typedef enum trie_exit_code {
FileError FileError
} TrieExitCode; } TrieExitCode;
uint64_t entry_new(Entry **entry_ptr, EntryType type, const char *string);
void entry_free(Entry *entry);
/** /**
* Allocate & initialize a new trie, and populate it with the data from the * Allocate & initialize a new trie, and populate it with the data from the
* given data file. * given data file.

View File

@ -5,7 +5,6 @@
#include <string.h> #include <string.h>
#include "trie.h" #include "trie.h"
#include "trie_entry.c"
#include "trie_node.c" #include "trie_node.c"
typedef struct ttrie { typedef struct ttrie {