treewide: restucture source tree per project

Signed-off-by: Max Regan <mgregan2@gmail.com>
This commit is contained in:
2017-04-20 18:12:28 -07:00
parent 6ba525b64b
commit e5acc3088c
24 changed files with 43 additions and 45 deletions

58
src/common/tri.h Normal file
View File

@@ -0,0 +1,58 @@
/*
* An implementation of tries.
*/
#ifndef _TRI_H_
#define _TRI_H_
#include <stdbool.h>
#define NUM_ALPHA_CHARS (256)
struct tri_node {
struct tri_node *nodes[NUM_ALPHA_CHARS];
void *value;
};
struct tri {
struct tri_node *head;
};
/**
* Initialize a tri and set its maximum depth.
*/
void tri_init(struct tri *tri);
/**
* Destroys an initialized tri and frees its internal structures.
*/
void tri_free(struct tri *tri);
/**
* Add a string as a key, and a value to the tri.
*/
int tri_add_string(struct tri *tri, const char *string, void * value);
/**
* Returns the value cooresponding to string. If the string is not in the tri, return
* NULL.
*/
void *tri_get_string(struct tri *tri, const char *string);
/**
* Returns the value cooresponding to the longest matching prefix
*/
void *tri_prefix_match(struct tri *tri, const char *string);
/**
* Using 'string' as a prefix, returns the value of the cooresponding string if there
* is only one that matches.
*
* If there are multiple possible matches, return NULL and set 'ambiguous' to true. If
* there are no possible matches, return NULL and set 'ambiguous' to false.
*/
void *tri_get_string_autocomplete(struct tri *tri, const char *string, bool *ambiguous);
#endif