From: Sebastian B. <sb...@us...> - 2014-01-19 18:55:33
|
Update of /cvsroot/simplemail/simplemail In directory sfp-cvs-1.v30.ch3.sourceforge.com:/tmp/cvs-serv25573 Modified Files: index_external.c Log Message: Reimplemented the callback function using the iterator function. The standard index_unittest.c test now mostly works. What is still missing is deletion. Index: index_external.c =================================================================== RCS file: /cvsroot/simplemail/simplemail/index_external.c,v retrieving revision 1.50 retrieving revision 1.51 diff -u -d -r1.50 -r1.51 --- index_external.c 19 Jan 2014 18:55:10 -0000 1.50 +++ index_external.c 19 Jan 2014 18:55:31 -0000 1.51 @@ -657,55 +657,6 @@ } /** - * Tries to find the given string. - * - * @param idx - * @param text - * @return - */ -static int bnode_find_string(struct index_external *idx, const char *text, int (*callback)(int did, void *userdata), void *userdata) -{ - int i; - int block; - char *str; - bnode *tmp = idx->tmp; - struct bnode_element *be; - int text_len = strlen(text); - int nd = 0; - struct bnode_path path; - - if (!bnode_lookup(idx, text, &path)) - return 0; - - block = path.node[path.max_level].block; - i = path.node[path.max_level].key_index; - - if (!bnode_read_block(idx, tmp, block)) - return 0; - - if (text_len > idx->max_substring_len) - text_len = idx->max_substring_len; - - for (;i<tmp->num_elements;i++) - { - int cmp; - be = bnode_get_ith_element_of_node(idx, tmp, i); - str = bnode_read_string(idx, be); - if (!str) return 0; - cmp = strncmp(text, str, text_len); - free(str); - if (!cmp) - { - callback(be->did, userdata); - nd++; - } - else - break; - } - return nd; -} - -/** * The iterator data. */ struct bnode_string_iter_data @@ -799,6 +750,28 @@ return NULL; } +/** + * Tries to find the given string. + * + * @param idx + * @param text + * @return + */ +static int bnode_find_string(struct index_external *idx, const char *text, int (*callback)(int did, void *userdata), void *userdata) +{ + struct bnode_string_iter_data *iter = NULL; + int nd = 0; + + while ((iter = bnode_find_string_iter(idx, text, iter))) + { + callback(bnode_string_iter_data_get_did(iter), userdata); + nd++; + } + return nd; +} + + + static void index_external_dispose(struct index *index) { struct document_node *d; |