[phrases] Adding trie_get_data/trie_set_data + at_index methods

This commit is contained in:
Al
2015-07-20 16:39:58 -04:00
parent b9771921fc
commit 7f96726e82
2 changed files with 15 additions and 4 deletions

View File

@@ -714,8 +714,7 @@ inline bool trie_set_data_node(trie_t *self, uint32_t index, trie_data_node_t da
return true; return true;
} }
inline bool trie_get_data(trie_t *self, char *key, uint32_t *data) { inline bool trie_get_data_at_index(trie_t *self, uint32_t index, uint32_t *data) {
uint32_t node_id = trie_get(self, key);
if (node_id == NULL_NODE_ID) return false; if (node_id == NULL_NODE_ID) return false;
trie_node_t node = trie_get_node(self, node_id); trie_node_t node = trie_get_node(self, node_id);
@@ -725,8 +724,12 @@ inline bool trie_get_data(trie_t *self, char *key, uint32_t *data) {
return true; return true;
} }
inline bool trie_set_data(trie_t *self, char *key, uint32_t data) { inline bool trie_get_data(trie_t *self, char *key, uint32_t *data) {
uint32_t node_id = trie_get(self, key); uint32_t node_id = trie_get(self, key);
return trie_get_data_at_index(self, node_id, data);
}
inline bool trie_set_data_at_index(trie_t *self, uint32_t index, uint32_t data) {
if (node_id == NULL_NODE_ID) { if (node_id == NULL_NODE_ID) {
return trie_add(self, key, data); return trie_add(self, key, data);
} }
@@ -735,6 +738,12 @@ inline bool trie_set_data(trie_t *self, char *key, uint32_t data) {
trie_data_node_t data_node = trie_get_data_node(self, node); trie_data_node_t data_node = trie_get_data_node(self, node);
data_node.data = data; data_node.data = data;
return trie_set_data_node(self, node_id, data_node); return trie_set_data_node(self, node_id, data_node);
}
inline bool trie_set_data(trie_t *self, char *key, uint32_t data) {
uint32_t node_id = trie_get(self, key);
return trie_set_data_at_index(self, node_id, data);
} }
trie_prefix_result_t trie_get_prefix_from_index(trie_t *self, char *key, size_t len, uint32_t start_index, size_t tail_pos) { trie_prefix_result_t trie_get_prefix_from_index(trie_t *self, char *key, size_t len, uint32_t start_index, size_t tail_pos) {

View File

@@ -88,7 +88,9 @@ trie_node_t trie_get_free_list(trie_t *self);
trie_data_node_t trie_get_data_node(trie_t *self, trie_node_t node); trie_data_node_t trie_get_data_node(trie_t *self, trie_node_t node);
bool trie_set_data_node(trie_t *self, uint32_t index, trie_data_node_t data_node); bool trie_set_data_node(trie_t *self, uint32_t index, trie_data_node_t data_node);
bool trie_get_data_at_index(trie_t *self, uint32_t index, uint32_t *data);
bool trie_get_data(trie_t *self, char *key, uint32_t *data); bool trie_get_data(trie_t *self, char *key, uint32_t *data);
bool trie_set_data_at_index(trie_t *self, uint32_t index, uint32_t data);
bool trie_set_data(trie_t *self, char *key, uint32_t data); bool trie_set_data(trie_t *self, char *key, uint32_t data);
bool trie_tail_match(trie_t *self, char *str, uint32_t tail_index); bool trie_tail_match(trie_t *self, char *str, uint32_t tail_index);