int main(int ac, char* av[]) { cpu::tube::context context(CPUTUBE_CONTEXT_ARGS(ac, av)); int size(ac == 1? 0: atoi(av[1])); int const max = 100000; std::vector<string_type> strings(make_strings(2 * (size? size: max * 20))); if (size) { run_tests(context, size, strings); } else { for (int i(10); i <= max; i *= 10) { for (int j(1); j < 10; j *= 2) { run_tests(context, i * j, strings); } } } }
strings* complete(trie root, char* prefix) { uint32_t i, len; len = strlen(prefix); trie n = root; for(i = 0; n != NULL && i < len; i++) { n = get_child(n, prefix[i]); } if(n == NULL) { return NULL; } else { GSList* suffixes = reversed_suffixes(n); uint32_t len, prefix_len; len = g_slist_length(suffixes); prefix_len = strlen(prefix); strings* res = make_strings(len); string* str; int i,j; char c; // Loop through each suffix. We can't check if i >= 0, since i is unsigned. for(i = len; i--;) { str = g_slist_nth_data(suffixes, 0); // We don't want to include the last item in the prefix // (since it's going to be in the generated suffixes) for(j = 0; j < (int) prefix_len-1; j++) { append_char(string_at(res, i), prefix[j]); } while((c = remove_last_char(str)) != '\0') { append_char(string_at(res, i), c); } suffixes = g_slist_remove(suffixes, str); free(str); } return res; } }