Created
April 20, 2015 06:09
-
-
Save IsaacCisneros/feacd10172d0ba4adb53 to your computer and use it in GitHub Desktop.
GLib Collections Test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <glib.h> | |
void __print(char *data, char *user_data){ | |
printf("DATA: [%s] ADRESS: [%d]\n", data, &(*data)); | |
} | |
gboolean __print_hash_table(gpointer key, gpointer data, gpointer user_data){ | |
printf("HASH ITEM: %d\n", GPOINTER_TO_INT(key)); | |
g_list_foreach((GList *)data, (GFunc)__print, NULL); | |
} | |
gboolean __free_hash_table(gpointer key, gpointer data, gpointer user_data){ | |
g_list_free((GList *) data); | |
} | |
int main(void) | |
{ | |
GList *list1 = NULL; | |
list1 = g_list_append(list1, "A1"); | |
list1 = g_list_append(list1, "A2"); | |
list1 = g_list_append(list1, "A3"); | |
list1 = g_list_append(list1, "A4"); | |
list1 = g_list_append(list1, "A5"); | |
list1 = g_list_append(list1, "A6"); | |
//g_list_foreach(list1, (GFunc)__print, NULL); | |
GList *list2 = NULL; | |
list2 = g_list_append(list2, "B1"); | |
list2 = g_list_append(list2, "B2"); | |
list2 = g_list_append(list2, "B3"); | |
list2 = g_list_append(list2, "B4"); | |
list2 = g_list_append(list2, "B5"); | |
list2 = g_list_append(list2, "B6"); | |
list2 = g_list_append(list2, "B7"); | |
list2 = g_list_append(list2, "B8"); | |
//g_list_foreach(list2, (GFunc)__print, NULL); | |
GList *list3 = NULL; | |
list3 = g_list_append(list3, "C1"); | |
list3 = g_list_append(list3, "C2"); | |
list3 = g_list_append(list3, "C3"); | |
list3 = g_list_append(list3, "C4"); | |
//g_list_foreach(list3, (GFunc)__print, NULL); | |
GHashTable *hash_table1 = g_hash_table_new(g_direct_hash, g_direct_equal); | |
g_hash_table_insert(hash_table1, GINT_TO_POINTER(1), list1); | |
g_hash_table_insert(hash_table1, GINT_TO_POINTER(2), list2); | |
g_hash_table_insert(hash_table1, GINT_TO_POINTER(3), list3); | |
g_hash_table_foreach(hash_table1, __print_hash_table, NULL); | |
g_hash_table_foreach_remove(hash_table1, __free_hash_table, NULL); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment