From: Thadeu Lima de Souza Cascardo Date: Fri, 30 Sep 2005 15:29:08 +0000 (+0000) Subject: Fixed bug in items related to the comparison of set items X-Git-Tag: cascardo@tlscascardo--private,libgrammatic--lr1--0.1--base-0~1 X-Git-Url: http://git.cascardo.info/?p=cascardo%2Fgrammar.git;a=commitdiff_plain;h=ea586a0fb4e667aebab81a83facd1c3e35614064 Fixed bug in items related to the comparison of set items The comparison of set items did not work with g_hash_table_find because hash values were all NULL. Putting the keys in a list and, then, iterating through it fixed the problem. git-archimport-id: cascardo@tlscascardo--private/libgrammatic--dev--0.1--patch-17 --- diff --git a/item.c b/item.c index a752dbd..1d7a9e4 100644 --- a/item.c +++ b/item.c @@ -109,16 +109,29 @@ gboolean item_set_add (GHashTable* item_set, item_t* item) return FALSE; } -gboolean item_set_find (gpointer key, gpointer val, gpointer data) +void put_key_on_list (gpointer key, gpointer val, gpointer data) { - return !g_hash_table_lookup_extended (data, key, NULL, NULL); + GList** l; + l = (GList**) data; + *l = g_list_prepend (*l, key); } gboolean item_set_equal (gconstpointer a, gconstpointer b) { + GList* l; + gboolean equal; if (g_hash_table_size (a) != g_hash_table_size (b)) return FALSE; - return (g_hash_table_find (a, item_set_find, b) == NULL); + l = NULL; + g_hash_table_foreach (a, put_key_on_list, (gpointer) &l); + equal = TRUE; + while (l != NULL && equal == TRUE) + { + equal = g_hash_table_lookup_extended (b, l->data, NULL, NULL); + l = g_list_next (l); + } + g_list_free (l); + return equal; } void hash_item (gpointer key, gpointer val, gpointer data) @@ -185,13 +198,6 @@ void item_set_closure_step (GHashTable* item_set, Grammar* grammar, } } -void put_key_on_list (gpointer key, gpointer val, gpointer data) -{ - GList** l; - l = (GList**) data; - *l = g_list_prepend (*l, key); -} - GHashTable* item_set_closure (GHashTable* item_set, Grammar* grammar) { int size;