|
|
|
@ -11,6 +11,10 @@
|
|
|
|
|
#include "config.h"
|
|
|
|
|
#include "task.h"
|
|
|
|
|
|
|
|
|
|
enum dfs_list {
|
|
|
|
|
VERTICES, VARIABLES
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static struct trie *trie_base = NULL;
|
|
|
|
|
|
|
|
|
|
static int indexof(char c) {
|
|
|
|
@ -143,24 +147,39 @@ bool trie_load(const char fn[]) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool trie_dfs(char prefix[], int prefixlen, struct grow *list, struct trie *vertex) {
|
|
|
|
|
static bool trie_dfs(char prefix[], uint64_t prefixlen, struct grow *list, struct trie *vertex, enum dfs_list style) {
|
|
|
|
|
if (vertex == NULL) {// Very special case;
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
bool retval = true;
|
|
|
|
|
if (style == VARIABLES) {
|
|
|
|
|
if (prefixlen > cfg_var_name_max_len) {
|
|
|
|
|
syslog(cfg_log_facility | LOG_NOTICE, "trie: dfs: too long variable name in trie");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (vertex -> def) {
|
|
|
|
|
prefix[prefixlen] = '\0';
|
|
|
|
|
// Add to list
|
|
|
|
|
struct trie_list *l = malloc(sizeof(struct trie_list));
|
|
|
|
|
if (l == NULL) {
|
|
|
|
|
syslog(cfg_log_facility|LOG_WARNING, "trie: dfs: cannot create list element: %m");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
l -> val = vertex -> val;
|
|
|
|
|
l -> name = malloc((prefixlen + 1) * sizeof(char));
|
|
|
|
|
strcpy(l->name, prefix);
|
|
|
|
|
grow_push(l, list);
|
|
|
|
|
retval &=grow_push(l, list);
|
|
|
|
|
}
|
|
|
|
|
} else if (style == VERTICES) {
|
|
|
|
|
// Add pointers to all vertices
|
|
|
|
|
retval &= grow_push(vertex, list);
|
|
|
|
|
}
|
|
|
|
|
for (int i = 0; i<37; i++) {
|
|
|
|
|
if (vertex -> children[i] != NULL) {
|
|
|
|
|
if (style == VARIABLES) {
|
|
|
|
|
prefix[prefixlen] = charof(i);
|
|
|
|
|
retval &= trie_dfs(prefix, prefixlen + 1, list, vertex -> children[i]);
|
|
|
|
|
}
|
|
|
|
|
retval &= trie_dfs(prefix, prefixlen + 1, list, vertex -> children[i], style);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return retval;
|
|
|
|
@ -178,7 +197,7 @@ bool trie_save(const char fn[]) {
|
|
|
|
|
struct grow *list = grow_init(true);
|
|
|
|
|
char prefix[cfg_var_name_max_len +1];
|
|
|
|
|
prefix[cfg_var_name_max_len +1] = '\0';
|
|
|
|
|
trie_dfs(prefix, 0, list, trie_base);
|
|
|
|
|
trie_dfs(prefix, 0, list, trie_base, VARIABLES);
|
|
|
|
|
|
|
|
|
|
for (uint64_t i = 0; i < list -> elems; i++) {
|
|
|
|
|
struct trie_list l = *(struct trie_list *)(list -> arr[i]);
|
|
|
|
@ -192,7 +211,7 @@ struct grow *trie_list(void) {
|
|
|
|
|
struct grow *list = grow_init(true);
|
|
|
|
|
char prefix[cfg_var_name_max_len +1];
|
|
|
|
|
prefix[cfg_var_name_max_len +1] = '\0';
|
|
|
|
|
trie_dfs(prefix, 0, list, trie_base);
|
|
|
|
|
trie_dfs(prefix, 0, list, trie_base, VARIABLES);
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -245,3 +264,10 @@ bool trie_unassoc(char var[], uint64_t task) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void trie_drop (void) {
|
|
|
|
|
struct grow *list = grow_init(true);
|
|
|
|
|
trie_dfs("", 0, list, trie_base, VERTICES);
|
|
|
|
|
grow_drop(list);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|