Add a pattern struct to encompass a pattern NFA and its size.

The size is necessary in free operations - unlike vectors and linked
lists, sparse sets in libds are not dynamically resizable.
This commit is contained in:
Danila Fedorin 2017-01-21 21:18:09 -08:00
parent fbba562eb7
commit 19ca43d8e4
1 changed files with 18 additions and 2 deletions

View File

@ -149,23 +149,39 @@ struct pattern_chain_s {
struct pattern_node_s* tail;
};
/**
* Represents a single compiled pattern.
*/
struct pattern_s {
/**
* The first NFA state of the pattern.
*/
struct pattern_node_s* head;
/**
* The number of NFA nodes in this pattern.
*/
int size;
};
typedef enum pattern_node_type_e pattern_node_type;
typedef struct pattern_node_s pattern_node;
typedef struct pattern_chain_s pattern_chain;
typedef struct pattern_s pattern;
/**
* Compiles a string representation of a pattern into a pattern NFA,
* and stores the first node of the new NFA in root.
* @param root the node to store the resulting pattern into.
* @param expression the pattern represented as a string.
* @param id the id of the pattern.
* @return LIBLEX_SUCCESS if all goes well, otherwise some other liblex_result.
*/
liblex_result pattern_compile(pattern_node** root, char* expression);
liblex_result pattern_compile(pattern* ptrn, char* expression, int id);
/**
* Frees a pattern NFA allocated by pattern_compile.
* @param root the root node to start freeing from.
* @return LIBLEX_SUCCESS if all goes well, otherwise some other liblex_result.
*/
liblex_result pattern_free(pattern_node* root);
liblex_result pattern_free(pattern* ptrn);
#endif