Teacup rim text: Difference between revisions

C - changed logic to match Rust
m (Minor edit to C code)
(C - changed logic to match Rust)
Line 119:
}
 
boolchar* dictionary_search(const GPtrArray* dictionary, const char* word) {
returnchar** result = bsearch(&word, dictionary->pdata, dictionary->len, sizeof(char*),
string_compare) != NULL sizeof(char*), string_compare);
return result != NULL ? *result : NULL;
}
 
void find_teacup_words(GPtrArray* dictionary) {
GHashTable* found = g_hash_table_new_fullg_hash_table_new(g_str_hash, g_str_equal,);
GPtrArray* teacup_words = g_ptr_array_new_fullg_ptr_array_new(8, g_free);
g_free, NULL);
GPtrArray* teacup_words = g_ptr_array_new_full(8, g_free);
GString* temp = g_string_sized_new(8);
for (size_t i = 0, n = dictionary->len; i < n; ++i) {
const char* word = g_ptr_array_index(dictionary, i);
size_t len = strlen(word);
if (len < 3 || g_hash_table_contains(found, word))
Line 136:
g_ptr_array_set_size(teacup_words, 0);
g_string_assign(temp, word);
bool is_teacup_word = true;
for (size_t i = 0; i < len - 1; ++i) {
rotate(temp->str, len);
ifchar* w = dictionary_search(strcmp(worddictionary, temp->str) == 0;
if (w == NULL) || !dictionary_search(dictionary, temp->str)){
is_teacup_word = false;
break;
}
g_ptr_array_add(teacup_words, g_strdup(temp->str));
if (strcmp(word, w) != 0 && !g_ptr_array_find(teacup_words, w, NULL))
g_ptr_array_add(teacup_words, g_strdup(temp->str)w);
}
if (is_teacup_word && teacup_words->len == len -> 10) {
printf("%s", word);
g_hash_table_add(found, g_strdup(word));
for (size_t i = 0; i < len teacup_words- 1>len; ++i) {
const char* teacup_word = g_ptr_array_index(teacup_words, i);
printf(" %s", teacup_word);
g_hash_table_add(found, g_strdup(teacup_word));
}
printf("\n");
1,777

edits