feat: switch to C-based compilation, start of simple event loop
This commit is contained in:
parent
01eb5ece55
commit
11cd537759
7 changed files with 1238 additions and 94 deletions
|
|
@ -2,46 +2,7 @@
|
|||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "trie.h"
|
||||
|
||||
/**
|
||||
* Represents a node of the binary tree contained within each non-leaf
|
||||
* TrieNode.
|
||||
*/
|
||||
typedef struct tinode {
|
||||
struct tinode *left;
|
||||
struct tinode *right;
|
||||
struct tnode *next;
|
||||
char key;
|
||||
} TrieInnerNode;
|
||||
|
||||
/**
|
||||
* Represents a node inside a Trie. A node can be in one of three states:
|
||||
* - Internal node: a node that's part of a path to a leaf node. This node will
|
||||
* always have a size greater than one, and an initialized root.
|
||||
* - Leaf: a node solely used to represent a string ending there. Its size is 0,
|
||||
* its ptr is unitialized and represents is true.
|
||||
* - Full leaf: a leaf node that contains a string. This occurs when a string is
|
||||
* added whose path is not fully in the tree yet, causing its remaining suffix
|
||||
* to be stored as a single node. Its size will be zero, represents its true,
|
||||
* and its string pointer is initialized.
|
||||
*/
|
||||
typedef struct tnode {
|
||||
Entry *entry;
|
||||
|
||||
TrieInnerNode *tree;
|
||||
uint8_t tree_size;
|
||||
|
||||
// Skips are at most TRIE_MAX_SKIP_SIZE characters, and are stored in the
|
||||
// nodes
|
||||
char string[TRIE_MAX_SKIP_SIZE];
|
||||
uint8_t string_len;
|
||||
|
||||
bool represents;
|
||||
} TrieNode;
|
||||
|
||||
// Required for recursively freeing tree structure
|
||||
void tnode_free(TrieNode *node);
|
||||
#include "trie_node.h"
|
||||
|
||||
/**
|
||||
* Allocate and initialize a new TrieInnerNode representing a given
|
||||
|
|
|
|||
53
trie/src/trie_node.h
Normal file
53
trie/src/trie_node.h
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
#include <stdint.h>
|
||||
|
||||
#include "trie.h"
|
||||
|
||||
/**
|
||||
* Represents a node of the binary tree contained within each non-leaf
|
||||
* TrieNode.
|
||||
*/
|
||||
typedef struct tinode {
|
||||
struct tinode *left;
|
||||
struct tinode *right;
|
||||
struct tnode *next;
|
||||
char key;
|
||||
} TrieInnerNode;
|
||||
|
||||
/**
|
||||
* Represents a node inside a Trie. A node can be in one of three states:
|
||||
* - Internal node: a node that's part of a path to a leaf node. This node will
|
||||
* always have a size greater than one, and an initialized root.
|
||||
* - Leaf: a node solely used to represent a string ending there. Its size is 0,
|
||||
* its ptr is unitialized and represents is true.
|
||||
* - Full leaf: a leaf node that contains a string. This occurs when a string is
|
||||
* added whose path is not fully in the tree yet, causing its remaining suffix
|
||||
* to be stored as a single node. Its size will be zero, represents its true,
|
||||
* and its string pointer is initialized.
|
||||
*/
|
||||
typedef struct tnode {
|
||||
Entry *entry;
|
||||
|
||||
TrieInnerNode *tree;
|
||||
uint8_t tree_size;
|
||||
|
||||
// Skips are at most TRIE_MAX_SKIP_SIZE characters, and are stored in the
|
||||
// nodes
|
||||
char string[TRIE_MAX_SKIP_SIZE];
|
||||
uint8_t string_len;
|
||||
|
||||
bool represents;
|
||||
} TrieNode;
|
||||
|
||||
TrieInnerNode *tinode_init(char c);
|
||||
|
||||
TrieNode *tnode_init();
|
||||
|
||||
void tinode_free_cascade(TrieInnerNode *node);
|
||||
|
||||
void tnode_free(TrieNode *node);
|
||||
|
||||
TrieNode **tnode_search(TrieNode *node, const char c, bool create);
|
||||
|
||||
void tinode_remove(TrieInnerNode *node, const char c);
|
||||
|
||||
void tnode_remove(TrieNode *node, const char c);
|
||||
Loading…
Add table
Add a link
Reference in a new issue