Teacup rim text: Difference between revisions
m
C - simplified code
(C - use GLib) |
m (C - simplified code) |
||
Line 89:
}
return count > 0;
}
int string_compare(gconstpointer p1, gconstpointer p2) {
return strcmp
}
Line 107 ⟶ 103:
return NULL;
}
GPtrArray* dict = g_ptr_array_new_full(1024,
GString* line = g_string_sized_new(64);
while (get_line(in, line))
g_ptr_array_add(dict,
g_ptr_array_sort(dict, string_compare);
g_string_free(line, TRUE);
Line 123 ⟶ 119:
}
bool dictionary_search(const GPtrArray* dictionary, const
return bsearch(&word, dictionary->pdata, dictionary->len, sizeof(
string_compare) != NULL;
}
void find_teacup_words(GPtrArray* dictionary) {
GHashTable* found = g_hash_table_new_full(
▲ GPtrArray* teacup_words = g_ptr_array_new_full(8, destroy_string);
for (size_t i = 0, n = dictionary->len; i < n; ++i) {
size_t len = strlen(word
if (len < 3 || g_hash_table_contains(found, word))
continue;
g_ptr_array_set_size(teacup_words, 0);
for (size_t i = 0; i < len - 1; ++i) {
rotate(temp
if (
|| !dictionary_search(dictionary, temp))
break;
g_ptr_array_add(teacup_words,
}
if (teacup_words->len == len - 1) {
printf("%s", word
g_hash_table_insert(found,
for (size_t i = 0; i < len - 1; ++i) {
printf(" %s", teacup_word
}
printf("\n");
|