From 27171e068d2dfd951fc76e1b164029f5b2a27860 Mon Sep 17 00:00:00 2001 From: Al Date: Fri, 22 May 2015 09:08:07 -0400 Subject: [PATCH] [phrases] constant for NULL prefix results --- src/trie.c | 10 +++++----- src/trie.h | 4 +++- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/trie.c b/src/trie.c index 4506accd..e07ba64c 100644 --- a/src/trie.c +++ b/src/trie.c @@ -697,7 +697,7 @@ inline trie_data_node_t trie_get_data_node(trie_t *self, trie_node_t node) { trie_prefix_result_t trie_get_prefix_from_index(trie_t *self, char *key, size_t len, uint32_t i, size_t tail_pos) { if (key == NULL) { - return (trie_prefix_result_t){NULL_NODE_ID, 0}; + return NULL_PREFIX_RESULT; } unsigned char *ptr = (unsigned char *)key; @@ -705,7 +705,7 @@ trie_prefix_result_t trie_get_prefix_from_index(trie_t *self, char *key, size_t uint32_t node_id = i; trie_node_t node = trie_get_node(self, i); if (node.base == NULL_NODE_ID) { - return (trie_prefix_result_t){NULL_NODE_ID, 0}; + return NULL_PREFIX_RESULT; } uint32_t next_id = NULL_NODE_ID; @@ -719,7 +719,7 @@ trie_prefix_result_t trie_get_prefix_from_index(trie_t *self, char *key, size_t node = trie_get_node(self, next_id); if (node.check != node_id) { - return (trie_prefix_result_t){NULL_NODE_ID, 0}; + return NULL_PREFIX_RESULT; } if (node.base < 0) break; @@ -737,13 +737,13 @@ trie_prefix_result_t trie_get_prefix_from_index(trie_t *self, char *key, size_t if (data_node.tail != 0 && trie_compare_tail(self, query_tail, query_len, data_node.tail + tail_pos)) { return (trie_prefix_result_t){next_id, query_len}; } else { - return (trie_prefix_result_t){NULL_NODE_ID, 0}; + return NULL_PREFIX_RESULT; } } - return (trie_prefix_result_t){next_id, 0}; + return NULL_PREFIX_RESULT; } diff --git a/src/trie.h b/src/trie.h index 15cc5e29..982350ef 100644 --- a/src/trie.h +++ b/src/trie.h @@ -110,9 +110,11 @@ typedef struct trie_prefix_result { size_t tail_pos; } trie_prefix_result_t; +const trie_prefix_result_t NULL_PREFIX_RESULT = {NULL_NODE_ID, 0}; + trie_prefix_result_t trie_get_prefix(trie_t *self, char *key); trie_prefix_result_t trie_get_prefix_len(trie_t *self, char *key, size_t len); -trie_prefix_result_t trie_get_prefix_from_index(trie_t *self, char *key, size_t len, uint32_t i); +trie_prefix_result_t trie_get_prefix_from_index(trie_t *self, char *key, size_t len, uint32_t i, size_t tail_pos); void trie_print(trie_t *self);